8 Replies Latest reply on Oct 5, 2007 5:30 AM by margielm

    rendered problem for commandButton

    vincecallagan

      Hi,

      I have a problem with the rendered of a commandButton, here is the code :

      <h:commandButton value="#{msgs.update}" action="update" rendered="#{!empty contact.name}"/>


      this code is execute with a jpdl but does not work. The button is displayed but nothing when I press it. On the other hand, if I remove the rendered attribute, it is still displayed and it works fine.

      Does anyone has a idea ?

      Thanks

        • 1. Re: rendered problem for commandButton

          I cannot reproduce this. Being in a pageflow would not have any effect on whether or the rendered attribute works. There must be some other factor.

          • 2. Re: rendered problem for commandButton
            vincecallagan

            here is the complete code :

            <h:commandButton value="#{msgs.update}" action="update" rendered="#{!empty contact.name}"/>
            <h:commandButton value="#{msgs.createnewcontact}" action="addContact" rendered="#{empty contact.name}"/>
            


            The second button works perfectly but pressing the first one does'nt produce anything :-(

            I checked the code with firebugs and the page doesn't contain errors :-(

            • 3. Re: rendered problem for commandButton

              I tried adding a rendered attribute to a button on the new user pageflow in the dvdstore. It worked exactly as expected. Can you post a larger example or maybe put it in the context of one of the existing examples?

              Also, can you confirm your JSF version and Seam version?

              • 4. Re: rendered problem for commandButton
                vincecallagan

                I am using 1.1 GA with Jboss AS 4.05

                The way I solved it for the moment is :

                rendered="#{contact.name!=''}"


                • 5. Re: rendered problem for commandButton
                  margielm

                  Hi,
                  I am facing the same problem, and I have no idea how I can resolve it.

                  Quick view on something like my application:

                  I have xhtml:

                  
                  <h:form>
                   <h:commandButton action="#{myControler.addNewItem}" value="add" rendered="#{param.mode == 'create'}" />
                   <h:commandButton action="#{myControler.updateItem}" value="update" rendered="#{param.mode == 'update'}" />
                  
                  </h:form>
                  

                  and controler:
                  @Stateful
                  @Name("myControler")
                  public class MyControlerBean implements MyControler {
                   public void addNewItem(){
                   logger.debug("entering adnewitem");
                   //rest of the method body
                   }
                   public void updateItem(){
                   logger.debug("entering updateitem");
                   //rest of the method body
                   }
                  }
                  


                  And when mode parameter value is create or update on generated site everything seems to be ok, one button is displayed another is not- so exactly what I wanted to get.
                  BUT!!! When I click button no action is invoke. I don't see any log on jboss console.
                  What is wondering - when I write true/false explicate to rendered attribute everything is ok. Prefered action is invoked.

                  I am using jboss seam 1.2.1GA, Jboss AS 4.2.1 and JSF 1.2

                  Please help :)


                  • 6. Re: rendered problem for commandButton
                    pmuir

                    Where does param.mode come from?

                    • 7. Re: rendered problem for commandButton
                      pmuir

                      Samuel just pointed me at the answer - the param is coming from the previous request. So when you submit the form (and it evalutates the rendered expression to check whether the button push is valid) the param isn't available (it's the next request).

                      I would suggest pushing (e.g. in pages.xml, a @Factory) your param.mode variable into page scope when the page is loaded, then it will be there when you submit the page.

                      Alternatively you can use a h:commandLink with a nested f:param to propagate the parameter.

                      • 8. Re: rendered problem for commandButton
                        margielm

                         

                        "pete.muir@jboss.org" wrote:
                        I would suggest pushing (e.g. <out /> in pages.xml, a @Factory) your param.mode variable into page scope when the page is loaded, then it will be there when you submit the page.


                        Hi.
                        thanks for your answer, but can you give my some exaple of pushing variable into page scope in pages.xml. Because I don't realy know what do you mean.