Search

March 9, 2015

JSF EL Implicit Object Reference

Just collecting the implicit objects defined by the JSF 2.2 specification (section 5.6.2.1, table 5-11) which are available in the EL:

application
externalContext.getContext()
applicationScope
externalContext.getApplicationMap()
cookie
externalContext.getRequestCookieMap()
facesContext
the FacesContext for this request
component
the top of the stack of UIComponent instances, as pushed via calls to UIComponent.pushComponentToEL(). See Section 3.1.14 “Lifecycle Management Methods”
flowScope
facesContext.getApplication().getFlowHandler().getCurrentFlowScope()
cc
the current composite component relative to the declaring page in which the expression appears.
flash
externalContext.getFlash()
header
externalContext.getRequestHeaderMap()
headerValues
externalContext.getRequestHeaderValuesMap()
initParam
externalContext.getInitParameterMap()
param
externalContext.getRequestParameterMap()
paramValues
externalContext.getRequestParameterValuesMap()
request
externalContext.getRequest()
requestScope
externalContext.getRequestMap()
resource
facesContext.getApplication().getResourceHandler()
session
externalContext.getSession()
sessionScope
externalContext.getSessionMap()
view
facesContext.getViewRoot()
viewScope
facesContext.getViewRoot().getViewMap()
resource
facesContext.getApplication().getResourceHandler()

February 13, 2015

jQuery UI Initialization Issues

Every once in a while when using jQuery UI I notice that my widget is not being initialized smoothly. For example, when using the menu widget I might see the list items behind the menu briefly. Then the page jumps around and it is a generally unpleasant experience for the user. Who likes it when your jQuery widgets are jumpy and cause the page to feel like one of those old 'punch the monkey' banner ads?

This usually means I have done something like this:

require(['jquery', 'jquery-ui/menu'], function($, menu) { $("#navmenu").menu(); });

Instead of wrapping the initialization in a function as I should:

require(['jquery', 'jquery-ui/menu'], function($, menu) { $(function() { $("#navmenu").menu(); }); });

January 17, 2015

JSF: Add Conversation ID to a link or button

To add the conversation ID parameter cid to a h:link or h:button:

<h:button value="Go" outcome="go"> <f:param name="cid" value="#{javax.enterprise.context.conversation.id}" /> </h:button>

January 15, 2015

Retain sessions in WildFly 8

Add the persistent-sessions element to your WildFly configuration to keep sessions persistent across redeployments and restarts:

<servlet-container name="default"> <jsp-config/> <persistent-sessions /> <websockets/> </servlet-container>

See https://docs.jboss.org/author/display/WFLY8/Undertow+%28web%29+subsystem+configuration for more information.

January 7, 2015

WildFly 8.2.0 and Java 8 on CentOS 6.6

This post documents how to install and configure WildFly 8.2.0 on CentOS 6.6. We make some changes to move some of the configuration under /etc and also place log files under /var/log and temp files under /tmp just like a well-behaved POSIX application should.

We’ll start by installing Java; download your desired version as an RPM from Oracle and install:

[root@wxyz ~]# rpm -ivh jdk-8u25-linux-x64.rpm

This installs the JDK in /usr/java/jdk1.8.0_25. There is no need to make this the default java used by the system, we'll just configure WildFly to use it.

Next we create a wildfly user on the server to build and run WildFly as:

[root@wxyz ~]# useradd --system \
--comment "WildFly Application Server" \
--create-home --home /opt/wildfly \
--user-group wildfly

I assume you already have the WildFly tarball downloaded and ready to go:

[wildfly@wxyz ~]$ tar zxvf wildfly-8.2.0.Final.tar.gz

Now that we have WildFly on the system, we need to configure CentOS to treat it like a service. WildFly comes with some scripts in the bin/init.d directory that will help with this. I am using the standalone server, but it is not difficult to modify the instructions for the domain server. First up is the /etc/wildfly/wildfly.conf file.

[root@wxyz ~]# cd /etc
[root@wxyz etc]# mkdir wildfly
[root@wxyz etc]# cd wildfly/
[root@wxyz wildfly]# cp /opt/wildfly/wildfly-8.2.0.Final/bin/init.d/wildfly.conf ./
[root@wxyz wildfly]# # We'll just create an empty properties file for now
[root@wxyz wildfly]# touch wildfly.properties

Next edit the file. We need to define a few environment variables, I am only including the ones I've changed:

# General configuration for the init.d scripts,
# not necessarily for JBoss AS itself.
# default location: /etc/default/wildfly

## Location of JDK
JAVA_HOME=/usr/java/jdk1.8.0_25

## Location of WildFly
JBOSS_HOME=/opt/wildfly/wildfly-8.2.0.Final

## The username who should own the process.
JBOSS_USER=wildfly

## Configuration for standalone mode
JBOSS_CONFIG=standalone-full.xml

## Location to keep the console log
JBOSS_CONSOLE_LOG="/var/log/wildfly/console.log"

# Need to modify the init script to account for JBOSS_OPTS
# Allows us to pass system properties to WildFly
JBOSS_OPTS="--properties=/etc/wildfly/wildfly.properties"

Next up we will deposit the init script in /etc/init.d and set the server to start on boot:

[root@wxyz wildfly]# cd /etc/ini t.d/
[root@wxyz init.d]# cp /opt/wildfly/wildfly-8.2.0.Final/bin/init.d/wildfly-init-redhat.sh ./wildfly
[root@wxyz init.d]# chkconfig --add wildfly
[root@wxyz init.d]# chkconfig --level 345 wildfly on
[root@wxyz init.d]# chkconfig --list wildfly
wildfly        0:off   1:off   2:off   3:on    4:on    5:on    6:off

You will need to edit the wildfly script in two places; first, to change the default location of the wildfly.conf file from /etc/default/wildfly.conf, starting at line 19:

# Load JBoss AS init.d configuration.
if [ -z "$JBOSS_CONF" ]; then
        JBOSS_CONF="/etc/wildfly/wildfly.conf"
fi

As-is the scripts do not allow passing any additional options to the WildFly process, so we need to edit the /etc/init.d/wildfly script to add the $JBOSS_OPTS variable whenever WildFly is starting. Here is the edited snippet for the standalone configuration (I’ve added some line breaks for readability) starting from line 104:

if [ ! -z "$JBOSS_USER" ]; then
  if [ "$JBOSS_MODE" = "standalone" ]; then
    if [ -r /etc/rc.d/init.d/functions ]; then
      daemon --user $JBOSS_USER LAUNCH_JBOSS_IN_BACKGROUND=1 \
      JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG \
      $JBOSS_OPTS 2>&1 > $JBOSS_CONSOLE_LOG &
    else
      su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 \
        JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG \
        $JBOSS_OPTS" 2>&1 > $JBOSS_CONSOLE_LOG &
    fi
  else

Next up we create the log directories and redirect the JBoss log directory to /var/log/wildfly and the tmp directory to /tmp/wildfly

[root@wxyz ~]# mkdir /var/log/wildfly
[root@wxyz ~]# chown wildfly:wildfly /var/log/wildfly/

To get WildFly to use these directories, we set the system properties for them in /etc/wildfly/wildfly.properties:

# System properties for wildfly
jboss.server.log.dir=/var/log/wildfly
jboss.server.temp.dir=/tmp/wildfly

At this point you can start the server using the command service wildfly start. You won’t be able to do much however, unless you like browsing via wget since the server is bound to the localhost interface only (and we are working on a headless server, i.e. no GUI web browser). So we’ll need to bind WildFly to all interfaces and open up the CentOS firewall to allow browsing to WildFly and the management console. Keep in mind that this may not be exactly what you want in a production environment or in environment where unknown users might access your server (like shared hosting).

First we’ll edit the /etc/wildfly/wildfly.properties file:

# System properties for wildfly
jboss.bind.address=0.0.0.0
jboss.bind.address.management=0.0.0.0
jboss.server.log.dir=/var/log/wildfly
jboss.server.temp.dir=/tmp/wildfly

Depending on how your local network is setup you may need further configuration for WildFly to be completely happy binding to all interfaces. If your DNS recognizes the name of the CentOS server you are working on, congratulations, you are all set. On the other hand, if DNS is not configured for the server, you will need to add an entry to the /etc/hosts file pointing the name of the server to the external IP.

Next we need to open the firewall for ports 8080 (regular WildFly) and 9990 (the management console). Be careful when adjusting the firewall. The commands below use hard-coded line numbers that may not be appropriate for whatever system you are using. If you think you have screwed up your firewall use service iptables restart to reset it. Of course, this won’t work after you issue service iptables save so be extra sure before you save the rules. You will also need to replace 10.0.0.0 with your subnet below.

[root@wxyz ~]# # 8080 for WildFly applications
[root@wxyz ~]# iptables --insert INPUT 5 \
         --match state \
         --state NEW \
         --protocol tcp \
         --destination-port 8080 \
         --source 10.0.0.0/24 \
         --jump ACCEPT
[root@wxyz ~]# # 9990 for WildFly management
[root@wxyz ~]# iptables --insert INPUT 6 \
         --match state \
         --state NEW \
         --protocol tcp \
         --destination-port 9990 \
         --source 10.0.0.0/24 \
         --jump ACCEPT
[root@wxyz ~]# # Verify the state of the firewall
[root@wxyz ~]# iptables -L --line-numbers
[root@wxyz ~]# # Go and test it out before doing the following
[root@wxyz ~]# service iptables save

At this point you should be ready to go. Start up WildFly and try accessing it from your desktop.

January 6, 2015

Network issues with CentOS 6.x under Hyper-V

I had a number of CentOS instances running under Hyper-V using the standard virtual network interface via integration services. Post CentOS 6.3 integration services are included in the install and that has been my experience. However at some point after updating to 6.6, something causes the integration services to no longer work with the virtual network interface.

To fix, remove the Network Adapter from the Hyper-V configuration and replace it with a Legacy Network Adapter.

Now you need to boot the virtual machine and access it from the Hyper-V console in order to log in. Backup the file /etc/udev/rules/70.persisent-net.rules and remove it from the /etc/udev/rules directory. This file tells CentOS to look for the old network interface and assign it to eth0.

Second, backup the /etc/sysconfig/network-scripts/ifcfg-eth0 file. Edit the file and remove any reference to UUID or HWADDR.