9 Replies Latest reply on Oct 30, 2008 9:06 PM by lance stine

    Issue with SelectOneMenu and a4j

    Alan Cassar Newbie

      Hi all,
      I have an issue with a4j and SelectOneMenu item. Let me describe what I am trying to do. I have a page which guides the user to choose some options, one at a time, which is basically the following code:

      <s:div id="ajaxChef">
                        <s:div rendered="#{askChef.step==1}">
                             <h:outputLabel>Are you looking for a:</h:outputLabel>
                              <h:selectOneRadio id="restRadio" value="#{askChef.restaurantType}">
                                      <s:selectItems id="restTypeSelectItems" value="#{eimtypeList.resultList}" var="type" label="#{type.typeName}"/>
                                      <s:convertEntity />
                                      <a:support event="onchange" reRender="ajaxChef, searchResults" actionListener="#{askChef.find}"/>
                       <s:div rendered="#{askChef.step==2}">
                             <h:outputLabel>Select Cuisine:</h:outputLabel>
                              <h:selectOneMenu id="cuisine" value="#{askChef.cuisine}">
                                  <s:selectItems id="cuisineSelectItems" value="#{eimcuisineList.resultList}" var="cuisine" label="#{cuisine.cuisineName}" noSelectionLabel="ANY"/>
                                  <s:convertEntity />
                                  <a:support event="onchange" reRender="ajaxChef, searchResults" actionListener="#{askChef.find}"/>
                       <s:div rendered="#{askChef.step==3}">
                             <h:outputLabel>Select Location:</h:outputLabel>
                              <h:selectOneMenu id="town" value="#{askChef.town}">
                                  <s:selectItems id="townSelectItems" value="#{eimtownList.resultList}" var="town" label="#{town.townName}" noSelectionLabel="ANY"/>
                                  <s:convertEntity />
                                  <a:support event="onchange" reRender="ajaxChef, searchResults" actionListener="#{askChef.find}"/>
                       <s:div rendered="#{askChef.step==4}">
                             <h:outputLabel>Select Cost Bracket:</h:outputLabel>
                              <h:selectOneMenu id="costBracket" value="#{askChef.costBracket}">
                                  <s:selectItems id="costBracketSelectItems" value="#{eimcostbracketList.resultList}" var="costBracket" label="#{costBracket.costValueStart} - #{costBracket.costValueEnd}" noSelectionLabel="ANY"/>
                                  <s:convertEntity />
                                  <a:support event="onchange" reRender="ajaxChef, searchResults" actionListener="#{askChef.find}" />
                      <a:commandButton value="back" disabled="#{1>=askChef.step}">
                          <a:support event="onclick" actionListener="#{askChef.decStep}" reRender="ajaxChef, searchResults" />
                      <a:commandButton value="next" disabled="#{askChef.step>=4}"> 
                              <a:support event="onclick" actionListener="#{askChef.incStep}" reRender="ajaxChef, searchResults" />

      the command buttons at the bottom will increment or decrement the askChef.step value so one div tag is displayed at a time. This works perfectly well.

      However, when for example the user is in step 2, and he selects his favourite cuisine, if the user first presses next, followed by the back button, the value chosen before the two keys were pressed still remains set in the  bean, but the selectonemenu shows the noSelectionLabel!!

      In other words, what I am trying to say is that if a user navigates to step 2 and chooses something from the selectonemenu which sets a value on a bean, if the user navigates back to that same step, the current value in the bean will not be reflected in the selectonemenu.

      when I googled around, I found this post: Link Here
      which shows that the selectonemenu selected item should reflect the current value of the bean's property.

      thanks in advance for you help.

        • 1. Re: Issue with SelectOneMenu and a4j
          James Kelly Newbie

          When you say the back button, do you mean the a:commandButton value="back" or the Back button in the browser?

          A more Ajax4JSF-y way to support wizard functionality would be to use the aj4:include element and define the view transitions in as navigation rules. The RichFaces documentation has an example in the aj4:include section.

          • 2. Re: Issue with SelectOneMenu and a4j
            Alan Cassar Newbie

            by back i meant the

            a:commandButton value="back"

            • 3. Re: Issue with SelectOneMenu and a4j
              Damian Harvey Apprentice

              Do you have a form tag in part of the code that you haven't shown? Also what is the scope of your askChef Bean?



              • 4. Re: Issue with SelectOneMenu and a4j
                Alan Cassar Newbie

                Yes it does have a form and a view as well. the askChef bean is a session bean

                              <all of the above here>

                The askchef bean is declared as:

                public class AskChefAction implements AskChef 

                • 5. Re: Issue with SelectOneMenu and a4j
                  Alan Cassar Newbie

                  Hi all,
                  I gave another shot at this and made it resemble the example there is in the a4j documentation, in other words, using the a4j:include

                  Although I have to say that the transition is much smoother this way, I am still finding issues. The main page now has the following code which acts exactly as the one used before. What I mean by this is that if I choose a certain value in a selectOneMenu, when I navigate back to that step, the value still resides in the bean but is not reflected in the selectOneMenu.

                          <h:panelGrid width="100%" columns="1">
                              <!--a:keepAlive beanName="askChef" /-->
                              <rich:panel styleClass="wizard">
                                  <f:facet name="header">
                                  <h:outputText value="Ask Chef" />
                                      <a:include viewId="/AskChef/step1.xhtml" />

                  Note however that I have to comment the following line

                              <!--a:keepAlive beanName="askChef" /-->

                  When I remove the comments from that line, I end up with the following exception

                  Caused by javax.ejb.NoSuchEJBException with message: "Could not find stateful bean: 3j011-ffn9oe-fdaabwjj-1-fdab4ig9-2s"

                  Thanks for all your help

                  • 6. Re: Issue with SelectOneMenu and a4j
                    Alan Cassar Newbie

                    Another thing, if I put a simple outputText, the value in the bean is reflected perfectly in the outputText, but not in the selectOneMenu combo box. So I am assuming that the bean is working correctly.

                    Is there a way perhaps to set a default value on the selectonemenu?

                    Any ideas about this?


                    • 7. Re: Issue with SelectOneMenu and a4j
                      lance stine Newbie

                      Did you ever find an answer to this? My current unsolvable problem is this. It would be great to have an answer on this blog.

                      • 8. Re: Issue with SelectOneMenu and a4j
                        Alan Cassar Newbie

                        no I never managed to solve this issue ...

                        • 9. Re: Issue with SelectOneMenu and a4j
                          lance stine Newbie

                          Even though this is probably too off the wall to help anyone, this is how I solved my problem.

                          I had two drop downs with a4j rendering a rich data table based on the two selections. The selection would be wiped out randomly but the rich data table would still hold its results.

                          I found that ordinary anchor tags in my navigation menu would cause the associated session beans to fire their function annotated with @Remove. So, I guessed that new conversations were starting when these navigation links were clicked. I don't think that this should happen but it did.

                          I removed all of the anchor tags and replaced them with seam links. Somehow this solved the problem.