8 Replies Latest reply on May 3, 2010 2:51 PM by Nick Belaevski

    MenuItem x actionParam as Object?

    Flavio Henrique Newbie

      Hi there!

      I need some help here: I have a dataTable and I register a contextMenu for its onRowClick event, using componentControl.

      I want to pass as parameter to my menuItem the whole object, but seems componentControl only pass literal values.

       

      My code to explain better:

      <r:dataTable var="item">

      [...]

          <r:componentControl event="onRowClick" for="menu" operation="show">

              <f:param value="#{item.id}" name="id" />

              <f:param value="#{item}" name="item" />

          </r:componentControl>

      </r:dataTable>

      [...]

      <r:contextMenu attached="false" id="menu" disableDefaultMenu="true" submitMode="ajax">

          <r:menuItem ajaxSingle="true" ignoreDupResponses="true" action="#{Bean.actionMethod}">

              <b>Editar</b>

              <a4j:actionparam name="id" noEscape="true" assignTo="#{Bean.object.id}" value="{id}" />

              <a4j:actionparam name="item" noEscape="true" assignTo="#{Bean.object}" value="{item}" />

          </r:menuItem>

      </r:contextMenu>

      [...]

       

      Only the first parameter (item.id) work on actionparam. The second (item) is passed as String 'Object object' not as the whole object handled by dataTable.

       

      Can I pass objects as parameters? Or any other way to solve this?

       

      Thank you!

       

      Flávio Henrique

        • 1. Re: MenuItem x actionParam as Object?
          Nick Belaevski Master

          Hi Flavio,

           

          Object can be passed as object to construct menu items using {...} expressions, however objects cannot be submitted as request parameters, only string data can be used.

          • 2. Re: MenuItem x actionParam as Object?
            Flavio Henrique Newbie

            Ok Nick.

            Too bad.    

            Thank you for the quick reply.

            • 3. Re: MenuItem x actionParam as Object?
              Flavio Henrique Newbie

              Hi Nick.

              And do you know if can I use the request parameters on rendered tag?

              Let me explain:

               

              The code below do not work:

               <r:menuItem ajaxSingle="true" ignoreDupResponses="true" rendered="{id} == 0" action="#{Bean.actionMethod}">
                       Editar
                      <a4j:actionparam name="id" noEscape="true" assignTo="#{Bean.object.id}" value="{id}" />
                      <a4j:actionparam name="item" noEscape="true" assignTo="#{Bean.object}" value="{item}" />
              </r:menuItem>
              

               

               

              But I can use the parameter {id} in javascript events like this:

               <r:menuItem ajaxSingle="true" ignoreDupResponses="true" onmouseover="alert({id});" action="#{Bean.actionMethod}">
                      Editar
                      <a4j:actionparam name="id" noEscape="true" assignTo="#{Bean.object.id}" value="{id}" />
                      <a4j:actionparam name="item" noEscape="true" assignTo="#{Bean.object}" value="{item}" />
              </r:menuItem>
              

               

              So, I'm doind something wrong or is not possible?

               

              Thank you!

               

              Flávio Henrique

              • 4. Re: MenuItem x actionParam as Object?
                Flavio Henrique Newbie

                Hmmm.

                I tried so many forms but seems when the parameter is involved in rendered tag the test always returns false.

                I need to show the r:menuItem only for some rows, not all of them.

                 

                Maybe I'm testing in wrong way?

                 

                Please, take a look in this code:

                 

                <r:dataTable var="item" onRowClick="#{r:component('contextMenu')}.show(event, {'status':'#{item.status}'});" />

                 

                <r:contextMenu attached="false" id="contextMenu" disableDefaultMenu="true" submitMode="ajax">

                  <r:menuItem rendered="{status} == 2" />

                </r:contextMenu>

                 

                The problem, obviously, is the test {status} == 2. But what?

                 

                Another solution is how to solve this:

                 

                <r:componentControl event="onRowClick" for="contextMenu" operation="show">

                  <a4j:support ignoreDupResponses="true" event="onRowClick">

                    <f:setPropertyActionListener value="#{item}" target="#{Bean.object}" />

                  </a4j:support>

                <f:param value="#{item.status}" name="status" />

                </r:componentControl>

                 

                Why the setPropertyActionListener do not work to set my Bean's object. I tried all events in a4j:support. I need to define the Bean attribute to test it in the r:menuitem rendered tag.

                 

                Any tip is more than appreciated!

                 

                Thank you in advance.

                 

                Flávio Henrique    

                • 5. Re: MenuItem x actionParam as Object?
                  Harut Sargsyan Apprentice


                  The code below do not work:

                   <r:menuItem ajaxSingle="true" ignoreDupResponses="true" rendered="{id} == 0" action="#{Bean.actionMethod}">
                           Editar
                          <a4j:actionparam name="id" noEscape="true" assignTo="#{Bean.object.id}" value="{id}" />
                          <a4j:actionparam name="item" noEscape="true" assignTo="#{Bean.object}" value="{item}" />
                  </r:menuItem>
                  

                   

                  1. EL expression in "rendered" attribute is incorrect. It should be rendered="#{id == 0}"

                  2. incorrect value of actionparam -- you should add "#" -- value="#{id}"

                   


                  And do you know if can I use the request parameters on rendered tag?


                  You need a4j:actionparam to send reqest params to server. If you need rendered attribute to contain any expression with the value of any actionparam, then write there the "value" of actionparam and not it's name...

                  • 6. Re: MenuItem x actionParam as Object?
                    Flavio Henrique Newbie

                    Hi Harut. Thank you for the tip.

                    1. EL expression in "rendered" attribute is incorrect. It should be rendered="#{id == 0}"

                    I tried #{id ==0} before, but didn't work.

                    2. incorrect value of actionparam -- you should add "#" -- value="#{id}"

                    According  to RF demo page (http://livedemo.exadel.com/richfaces-demo/richfaces/contextMenu.jsf?c=contextMenu&tab=usage) I must use {id} not #{id} in value attribute. Besides that {id} works fine there.

                     

                    The problem is only in rendered attribute. Seems to be impossible to use the actionparam as it uses '{}' to identify and this breaks the '{} from EL expression.

                     

                    Someone has a code that works to share with me? Or should I open a JIRA ticket for this?

                     

                    Thank you!

                     

                    Flávio Henrique    

                    • 7. Re: MenuItem x actionParam as Object?
                      Flavio Henrique Newbie

                      Hmmm...

                      In fact, the actionparam is NOT related with my problem.

                       

                      I want to use the f:param value, from r:componentControl, in rendered attribute:

                      <r:componentControl
                          event="onRowClick"
                          for="menu"
                          operation="show">
                          <f:param
                              value="#{item.id}"
                              name="id" />
                      </r:componentControl>
                       
                      [...]
                      <r:contextMenu
                       attached="false"
                       id="menu"
                       disableDefaultMenu="true"
                       submitMode="ajax"> 
                      <r:menuItem
                          ajaxSingle="true"
                          rendered="{id} == 1"
                          reRender="formulario"
                          ignoreDupResponses="true"
                          action="#{MyBean.method}">
                          <b>{id}</b>    
                      </r:menuIte
                      </r:contextMenu>
                      

                       

                      Sorry if I created confusion.

                       

                      Flávio Henrique

                       

                      Message was edited by: Flavio Henrique

                      • 8. Re: MenuItem x actionParam as Object?
                        Nick Belaevski Master

                        Hi Flavio,

                         

                        No, it's not possible to use {...} expressions in "rendered" attribute expression. You can workaround this using CSS, e.g. styleClass="{var.hidden ? 'display-none' : ''}", however you should be checking on the server if the component is rendered as security measure.