9 Replies Latest reply on Jul 5, 2010 11:52 AM by jurijlender

    Problem with h:commandButton and rendered attribute

    giunad

      Hi


      I have a very simple page with a form:


      <h:form id="test">          
        <h:commandButton id="btn1" action="#{advManager.insert}" rendered="#{empty param.mode or param.mode == 'ins'}" image="images/ins.jpg"/>
        <h:commandButton id="btn2" action="#{advManager.update}" rendered="#{param.mode == 'edit'}" image="images/mod.jpg"/>
      </h:form>
      


      the associated pageflow is:



      <navigation from-action="#{advManager.insert}">
        <rule if-outcome="inserted">
          <redirect view-id="/upload.xhtml"/>
        </rule>
      </navigation>
      <navigation from-action="#{advManager.update}">
        <rule if-outcome="updated">
          <redirect view-id="/confirm.xhtml"/>
        </rule>
      </navigation>
      



      First time I reach this page (/edit.jsf or /edit.jsf?mode=ins), only the first button (btn1) is showed and everything goes ok: insert method is activated and upload page is showed.


      When I reach this page a second time for update (/edit.jsf?mode=edit), only the second button (btn2) is showed but if I clik it the page is reloaded and nothing else happens.


      It seams that param in rendered attribute causes some problem. In fact if I write explicitly


      rendered="true"



      everything works. (I always see 2 buttons of course)
      This let me think advManager component, methods and pageflow are right.


      I'm also supposing something very similar happens the first time on insert. but seams can however evaluate


      empty param.mode



      and goes on in activating insert method.


      I'd like to know your opinion.
      thanks


      env:

      richfaces 3.2.2.SR1

      jboss-seam-2.1.1.GA

      jboss-4.2.3.GA



        • 1. Re: Problem with h:commandButton and rendered attribute
          lvdberg

          Hi,


          this is not really a Seam question, but ok I can imagine your struggle. The rendered attribute does exactly what you state. If the value is false NOTHING is rendered so you can NEVER reference its ID for reRendering, because there is nothing in the DOM available. This is exactly where the nice seam.tag s:div comes in. It renders its content based on the rendered attribute, but stays present itself. So you can reference it in a reRender. You can alos use an Ajax panel wich works basically the same.


          Leo

          • 2. Re: Problem with h:commandButton and rendered attribute
            giunad

            hi,


            maybe I was poor in my writing, sorry english is not my language.


            what exactly happens is:


            - I reach edit page (edit.jsf?mode=edit)

            - the update button is showed

            - I click on it

            - the update method is NOT fired

            - the page is reloaded.


            why?


            I understand how rendered attribute works, but this work happens before I click the button.
            If I can see update button, rendering is over, isn't it?


            So what is stopping seam/jsf to fire update method?


            thanks

            • 3. Re: Problem with h:commandButton and rendered attribute
              lvdberg

              Hi,


              Send the code of the bean, because it should work normal. Surely there is the always present tinny little detail we're missing now.


              Leo

              • 4. Re: Problem with h:commandButton and rendered attribute
                giunad

                here is:


                @Stateful
                @Scope(ScopeType.SESSION)
                @Name("advManager")
                public class AdvManagerBean implements AdvManager, Serializable {
                
                     private static final long serialVersionUID = -8882059433848876582L;
                
                     @DataModel(scope=ScopeType.PAGE)
                     private List<Adv> advList;
                
                     @DataModelSelection
                     @Out(required = false, scope = ScopeType.CONVERSATION)
                     private Adv adv = new Adv();
                     private Spot spot1 = new Spot();
                
                     @In(required = true)
                     private Account currentAccount;
                
                     @PersistenceContext(type = PersistenceContextType.EXTENDED)
                     private EntityManager em;
                
                     // - - - ACTIONS - - -
                     
                     public String insert() {
                
                          // do  insert          
                
                          return "inserted";
                     }
                
                
                     public String update() {
                          
                          // do update
                
                          return "update";
                     }
                
                     // - - - SETTER & GETTER - - -
                
                }
                



                • 5. Re: Problem with h:commandButton and rendered attribute
                  mikkus70

                  The navigation rule for the update() action expects an outcome of updated, whereas the method returns update. This means the rule is not fired.

                  • 6. Re: Problem with h:commandButton and rendered attribute
                    lvdberg

                    Hi,


                    I can't see a reason why you should have the bean at the session context. because its a Stateful SB it already ha a Conversation scope.


                    To get that working you should somewhere have a conversation started. I can imagine you click on the list a conversation starts, you do some things and you submit the form. Don't understand why you complicate stuff with the Param by adding it (somehow) to the url. Just use buttons to insert and edit


                    Leo

                    • 7. Re: Problem with h:commandButton and rendered attribute
                      giunad

                      It's 'updated' in my code. 'update' was just a cut and past error.
                      thansk

                      • 8. Re: Problem with h:commandButton and rendered attribute
                        giunad

                        Leo van den Berg wrote on Jan 13, 2010 15:12:


                        Don't understand why you complicate stuff with the Param by adding it (somehow) to the url. Just use buttons to insert and edit

                        Leo


                        so I'm using the same page for insert and for update. I need just 2 different buttons.

                        • 9. Re: Problem with h:commandButton and rendered attribute
                          jurijlender

                          could anyone find an answer to that problem? i am having the same problem too. i estimate that it is because the ajax-buttons are mapped with the action before some proerties are set in the bean. at least this is what i found out concerning the action using for the rendered attribute.