3 Replies Latest reply on Aug 19, 2009 5:28 PM by Shan Paul

    seam valueChangeListener

    Shan Paul Newbie
      Hi

      Could you please tell me what i am doing wrong here.  Whenever i change the drop down the textbox is not changed with new value. because of this whenever i change the drop down it updates the table from the textbox.

      xhtml page...

      '<ice:selectOneListbox id="accounts"
                                              value="#{accountManagerService.selectedAccount}" size="1"
                                              valueChangeListener="#{accountManagerService.accountChanged}"
                                              partialSubmit="true" required="true">
                                              <s:selectItems value="#{findAllActiveAccounts}" var="account"
                                                   label="#{account.description}" />
                                              <s:convertEntity />
                                         </ice:selectOneListbox>'

      '<ice:inputText styleClass="freeFormInput" id="description"
                                    value="${accountManagerService.selectedAccount.description}" required="true" />'

      AccountManager.java

      @Scope(ScopeType.CONVERSATION)
      @Name("accountManagerService")
      @AutoCreate
      @Restrict("#{identity.loggedIn}")
      public class AccountManager implements java.io.Serializable {

           @In
           private EntityManager entityManager;

           private Account selectedAccount;

      public void accountChanged(ValueChangeEvent evt) {
                if (!evt.getPhaseId().equals(PhaseId.INVOKE_APPLICATION)) {
                     evt.setPhaseId(PhaseId.INVOKE_APPLICATION);
                     evt.queue();
                     return;
                }
                if (evt.getNewValue() != null) {
                     entityManager.flush();
                     FacesContext.getCurrentInstance().getResponseComplete();
                     selectedAccount = (Account) evt.getNewValue();
                }
                FacesContext.getCurrentInstance().responseComplete();
           }

      When the page loades from the s:link it sets the description after everychange there is no change in description.


      1. How do i refesh the description from the selectedAccount.
      2. I think because of not changing the description seam think the object is dirty.

      Thanks in advance
        • 1. Re: seam valueChangeListener
          Shan Paul Newbie
          I did this also  but same effects..

          public void accountChanged(ValueChangeEvent evt) {
            if (!evt.getPhaseId().equals(PhaseId.INVOKE_APPLICATION)) {
             evt.setPhaseId(PhaseId.INVOKE_APPLICATION);
             evt.queue();
             return;
            }
            if (evt.getNewValue() != null) {
             selectedAccount = (Account) evt.getNewValue();
            }
            FacesContext.getCurrentInstance().responseComplete();
          }


          I noticed that selectedAccount object is right when the event is fired.  But after that the old object seems set to be dirty and updating the db table.  How can i stop the update?  Because i have my own save, soft delete method in that object.

          Thanks
          • 2. Re: seam valueChangeListener
            judy guglielmin Novice

            Can it be assumed that you are using manual flush with hibernate?  I would probably suggest pushing the new value to invoke the next jsf lifecycle (if I understand what you are wanting to do correctly).  Since it is a little unclear to me, I can only assume there is some detail on the same page that reflects the change in selectedAccount?  Also, keep in mind that the conversation may be lazy loading this info (if you have collections in your entity that might be lazily loaded)?  You could also use an action vs an actionListener and a page parameter to load the new account.  For more detailed examples, you could try the ICEfaces forum

            • 3. Re: seam valueChangeListener
              Shan Paul Newbie

              Thanks i will try that forum. How can i push the new value to invoke next jsf lifecycle.


              i can see the selectedAccount in the listener is correct but later it got updated with old description on the selectedAccount.