3 Replies Latest reply on Aug 11, 2010 8:16 AM by ilya_shaikovsky

    rich:contextMenu and layout behavior

    cassionandi

      Hello there.

       

      I have this code.

       

      <a4j:form id="test_form">
              <table>
              <tr>
              <td>
                  <a4j:repeat value="#{test.keywords}">
                  <a4j:commandLink id="link"> L I N K </a4j:commandLink>
                          <rich:contextMenu event="oncontextmenu" attachTo="link" submitMode="ajax">
                              <rich:menuItem value="Edit" id="test_edit"></rich:menuItem>
                          </rich:contextMenu>
                  </a4j:repeat>
             
              </td>
              </tr>
              </table>
      </a4j:form>
      </body>

       

      The objective is to show a list of keywords and let the user edit it by using a context menu. Well, test.keywords returns a collection of Strings. When you execute this code, the result is like:

       

      keyword1

      keyword2

      keyword3

      keyword4

       

      If I remove the rich:contextMenu / menuItem tag, the result is

       

      keyword1 keyword2 keyword3 keyword4

       

      The context menu creates a div, but I can't understand how it changes the way that the keywords a showed.

       

      I'm using 3.3.1.GA

        • 1. Re: rich:contextMenu and layout behavior
          ilya_shaikovsky

          context menu actually not inserted into <a> childs but encoded after the link and attached usign script. So as div - block element - next link placed below.

           

          B.t.w. general advice (which will actualy solve your problem in the same time). Do not iterate menus - just use single shared once. Except solving your problem - it will also be resulted in better performance. check http://livedemo.exadel.com/richfaces-demo/richfaces/componentControl.jsf second sample.

          • 2. Re: rich:contextMenu and layout behavior
            cassionandi

            Okay Ilya, so my code has changed but I don't understand HOW it works completely.

             

                     <a4j:repeat value="#{test.keyword}" var="keyword">
                            <a4j:commandLink id="link"> L I N K</a4j:commandLink>
                        </a4j:repeat>
                       
                        <rich:componentControl event="oncontextmenu" for="id_context_menu" operation="show">
                              <f:param value="#{keyword}" name="keyword_param"/>
                        </rich:componentControl>
                       
                        <rich:contextMenu id="id_context_menu" submitMode="ajax">
                               <rich:menuItem value="Edit" id="test_edit"></rich:menuItem>
                        </rich:contextMenu>

             

            How the componentControl is bounded to the commandLink without the attachTo attribute? If the componentControl is inside the commandLink, the event="oncontextmenu" dons't work, but the onclick yes.

             

            Another question. The f:param can see the var="keyword"?

            • 3. Re: rich:contextMenu and layout behavior
              ilya_shaikovsky

              1) if not works in link - wrap the link to div and attach CC to it.

              2) to use var - place CC in iteration.

               

               

              so should be

              <a4j:repeat value="#{test.keyword}" var="keyword">
                  <a4j:outputPanel layout="block">     
                       <a4j:commandLink id="link"> L I N K</a4j:commandLink> 
                       <rich:componentControl event="oncontextmenu" for="id_context_menu" operation="show">
                                <f:param value="#{keyword}" name="keyword_param"/>
                          </rich:componentControl>
                   </a4j:outputPanel>
              </a4j:repeat>
              
              <rich:contextMenu id="id_context_menu" submitMode="ajax">
                                 <rich:menuItem value="Edit" id="test_edit"></rich:menuItem>
              </rich:contextMenu>