6 Replies Latest reply on Oct 12, 2007 1:10 PM by mheidt

    Issue with ValueChangeListener and calling SLSB in Seam

    rizviatt

      I am very new to Jboss seam based app development. Still working on prototyopes.
      I have a JSF page with combo box which i am populating with list of users(For which i have entity called user).I am displaying realname in the combobox and values are the username.In the same page i have textbox fields for displaying fields of user like realaname , password etc.
      Now what i would like to do is when i select a particular user from the combobox i want to populate the fields of realname and password for the corresponding selected user.

      WHat I did was
      I wrote a SLSB with a method "toggleUser(ValueChangeEvent event)" in which i do Database query to get the details for the selected user.

      My jsp code looks like this
      "
      <h:selectOneMenu
      valueChangeListener="#{useraction.toggleUser}"
      onchange="this.form.submit();" immediate="true" value="# {user.username}">
      <f:selectItems value="#{useraction.userList}"/>
      </h:selectOneMenu>

      "
      where useraction is SLSB. and user is entity bean.

      The page when initially loaded works fine. It gets loaded with users.But problem happens when i select a user.
      I get the folowing exception

      java.lang.reflect.UndeclaredThrowableException
      at $Proxy136.toggleUser(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:138)
      at javax.faces.component.UIInput.broadcast(UIInput.java:200)
      at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
      at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:132)
      at org.apache.myfaces.lifecycle.LifecycleImpl.applyRequestValues(LifecycleImpl.java:177)
      at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:87)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:94)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: java.io.NotSerializableException: javax.faces.event.PhaseId
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1245)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1069)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
      at java.rmi.MarshalledObject.(MarshalledObject.java:92)
      at org.jboss.aop.joinpoint.MethodInvocation.writeExternal(MethodInvocation.java:271)
      at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1304)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1282)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
      at java.rmi.MarshalledObject.(MarshalledObject.java:92)
      at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:35)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:88)
      ... 31 more

      Is it because ValueChangeEvent is not serialized ???.
      Any help would be appreciated.

        • 1. Re: Issue with ValueChangeListener and calling SLSB in Seam
          rizviatt

          I got the Exception out of the way by making SLSB Local, initially it was remote(there was no need of it.)
          But now, when i select a user from the combo box the corresponding users details does not get loaded in the page. The fields retain its original values.

          My JSP Code looks like this


          Register New User


          <f:view>
          <h:form>


          <h:outputText value="Users:" />
          <h:selectOneMenu
          valueChangeListener="#{useraction.toggleUser}"
          onchange="this.form.submit();" immediate="true" value="#{user.username}">
          <f:selectItems value="#{useraction.userList}"/>
          </h:selectOneMenu>


          Real Name
          <h:inputText value="#{user.name}"/>


          Password
          <h:inputSecret value="#{user.password}"/>


          <h:messages/>
          <h:commandButton type="submit" value="Update" action=""/>
          </h:form>
          </f:view>



          My SLSB looks like this
          @Stateless
          @Scope(EVENT)
          @Name("useraction")
          @Intercept(InterceptionType.ALWAYS)
          @Interceptor(SeamInterceptor.class)
          public class UserActionBean implements UserAction {
          @PersistenceContext
          private EntityManager em;
          @In
          private FacesContext facesContext;
          @In @Out
          private User user;
          String username;

          public List findAllUsers() {
          List values = new ArrayList();
          Query query = em.createQuery("from User");
          for (Object o : query.getResultList()) {
          values.add((User) o);
          }
          return values;
          }

          public List getUserList() {
          List users = new ArrayList();
          List temp = findAllUsers();
          Iterator userIter = temp.iterator();
          while (userIter.hasNext()) {
          User me = (User) userIter.next();
          users.add(new SelectItem(me.getUsername(),me.getName()));
          }
          return users;
          }
          public String findUser() {
          user = em.find(User.class,user.getUsername());
          return "userupdate";
          }

          public String updateUser() {
          em.merge(user);
          return "success";
          }


          public void toggleUser(ValueChangeEvent event) {
          String username = (String)event.getNewValue();
          System.out.println("username is after"+username);
          user = em.find(User.class,username);
          System.out.println("AFter user name is "+user.getUsername());
          FacesContext.getCurrentInstance().renderResponse();
          }

          public String getUsername() {
          System.out.println("Returning username"+username);
          return username;


          }

          public void setUsername(String username) {
          this.username = username;
          }

          }


          My Entity bean
          @Entity
          @Name("user")
          @Scope(SESSION)
          @Table(name="users")
          public class User implements Serializable
          {
          private static final long serialVersionUID = 1881413500711441951L;

          private String username;
          private String password;
          private String name;
          ......
          ......................
          }

          You can see that i did System.out in toggleUser to see if i am getting the right values
          public void toggleUser(ValueChangeEvent event) {
          String username = (String)event.getNewValue();
          System.out.println("username is after"+username);
          user = em.find(User.class,username);
          System.out.println("AFter user name is "+user.getUsername());
          FacesContext.getCurrentInstance().renderResponse();
          }

          and i am getting the right values.
          But the jsp [page still retains the old values.
          Any ideas, help!!!

          • 2. Re: Issue with ValueChangeListener and calling SLSB in Seam
            hoetschmann

            Try to make your User object SESSION-Scoped.
            I had a similar problem, I think...
            See:
            http://www.jboss.com/index.html?module=bb&op=viewtopic&t=71237

            @In @Out(scope = ScopeType.SESSION)
            private User user;
            Regards
            hoetschmann

            • 3. Re: Issue with ValueChangeListener and calling SLSB in Seam
              rizviatt

              Thanks for the advise

              I tried your advise. I added the following in my UserActionBean
              @In @Out(scope = ScopeType.SESSION)
              private User user;

              But it Did Not work

              My JSP Code

              <h:selectOneMenu
              valueChangeListener="#{useraction.toggleUser}"
              onchange="this.form.submit();" immediate="true" value="#{user.username}">
              <f:selectItems value="#{useraction.userList}"/>
              </h:selectOneMenu>

              Do you thing there is something else which is problem.

              • 4. Re: Issue with ValueChangeListener and calling SLSB in Seam
                lisaanm

                I'm also facing the same problem.
                The valueChangeListener is not working. Please let me know if you come across any solution.

                Thanks.

                • 5. Re: Issue with ValueChangeListener and calling SLSB in Seam

                  Did here. In fact, my implementation of valueChangeListener never even gets invoked.

                   <h:selectOneMenu value="#{workPackage.account}" rendered="#{!hasRemittance}" style="font-size:80%"
                   valueChangeListener="#{packages.selectAccount}" onchange="submit()">
                   <f:selectItems value="#{packages.accountMap}" />
                   </h:selectOneMenu>
                  

                   public void selectAccount(ValueChangeEvent event) {
                   log.info("[#0]: event #1", user.getUsername(), event.getNewValue());
                   AccountEntity ae = (AccountEntity)event.getNewValue();
                   workPackage.setAccount(ae);
                   }
                  


                  The selectAccount method is never hit, no matter what. Any ideas?

                  • 6. Re: Issue with ValueChangeListener and calling SLSB in Seam
                    mheidt

                    I know, this thread is old...but for the record...
                    @c_eric_ray
                    Did you declare the valueChangeListener method in your session bean interface?

                    When i forgot it, no error was displayed (and I didn't forget h:messages)