title: JSF ActionListener in CommandButton
body: <p>I made simple  sample wit two page in JSF2. On first page I have command button with actionListener released trough interface class. Goal is when I click button on first page, second page will be displayed with changed value on it. 
  But when first time start web server(JBOSS) I have got error page, until I starts second page. In that situation second page will be displayed with default value. After that first page work fine.And everithing work fine, even if I close second page. What happening , what is done? 
  Here are error messages: </p>
  
  <pre><code>ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ActionListenerWithInterface].[Faces Servlet]] (http--0.0.0.0-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.NullPointerException
  at com.tutoriali.test.UserActionListener.processAction(UserActionListener.java:14) [classes:]
  at com.sun.faces.facelets.tag.jsf.core.ActionListenerHandler$LazyActionListener.processAction(ActionListenerHandler.java:129) [jsf-impl-2.1.7-jbossorg-2.jar:]
  at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
  at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
  at javax.faces.component.UICommand.broadcast(UICommand.java:300) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
  at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
  at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
  at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.1.7-jbossorg-2.jar:]
  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
  at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
  at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
  at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_37]
  </code></pre>
  
  <p>Here are xhtml pages:
  FirstPage:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"&gt; 
  
  &lt;h:head&gt;&lt;title&gt;JSF primer&lt;/title&gt;&lt;/h:head&gt; 
  &lt;h:body&gt; 
      &lt;h1&gt;Primer ActionListenera realizovan preko interface-a&lt;/h1&gt;
      &lt;h:form&gt;
          &lt;h2&gt;ActionListener&lt;/h2&gt;
          &lt;hr /&gt;
          &lt;h:commandButton id="SubmitButton" value="Submit" action="#{userData.showResult()}" &gt;
              &lt;f:actionListener type="com.tutoriali.test.UserActionListener"/&gt;
          &lt;/h:commandButton&gt;
      &lt;/h:form&gt;
  &lt;/h:body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is Second page:</p>
  
  <pre><code>    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"&gt; 
  
  &lt;h:head&gt;&lt;title&gt;JSF primer&lt;/title&gt;&lt;/h:head&gt; 
  &lt;h:body&gt; 
      &lt;h1&gt;Primer kako se ostvaruje Action Listener preko interface-a&lt;/h1&gt;
      &lt;h2&gt;Rezultat&lt;/h2&gt;
      &lt;hr /&gt;
  
          #{userData.data}
  
  &lt;/h:body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is Interface class:</p>
  
  <pre><code>    package com.tutoriali.test;
  
  import javax.faces.context.FacesContext;
  import javax.faces.event.AbortProcessingException;
  import javax.faces.event.ActionEvent;
  import javax.faces.event.ActionListener;
  
  public class UserActionListener implements ActionListener {
  
      @Override
      public void processAction(ActionEvent arg0) throws AbortProcessingException {
  
          UserData userData = (UserData)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("userData");
          userData.setData("Hello World!");
          System.out.println("******* We are in interface!*************");
  
      }
  
  }
  </code></pre>
  
  <p>And Here is beackend Bean UserData.java:</p>
  
  <pre><code>package com.tutoriali.test;
  
  import java.io.Serializable;
  
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  
  @ManagedBean(name="userData", eager=true)
  @SessionScoped
  
  public class UserData implements Serializable {
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
  
      private String data="Difoltna vrednost";
  
      public String showResult(){
          return "result";
      }
  
      public String getData() {
          return data;
      }
  
      public void setData(String data) {
          this.data = data;
      }
  
  }
  </code></pre>