6 Replies Latest reply on Sep 9, 2009 5:36 AM by nbelaevski

    Programmatically set onclick() at HtmlMenuItem

    asiandub

      Hello,

      what I like to do is to set a rather complex EL expression as onClick() at an HtmlMenuItem.

      It works fine with simple expressions, but is not working with a more complex term:

      
      HtmlMenuItem mi1 ...
      HtmlMenuItem mi2 ...
      
      mi1.setOnclick("alert('hello')"); // .. working
      mi1.setOnclick("#{rich:component('myPanel')}.show();return false"); // .. not working
      
      


      I think that it's the EL expression which causes the troubles, but as the method takes an String argument and is not ... eh ... over-documented, I dont have a clue.

      Can anyone help me out?

      Many thanks,
      Jan

        • 1. Re: Programmatically set onclick() at HtmlMenuItem
          elf

           

          mi1.setOncomplete("javascript:Richfaces.showModalPanel('myPanel').show()");

          works for me


          • 2. Re: Programmatically set onclick() at HtmlMenuItem
            elf

            sorry, just

            mi1.setOncomplete("javascript:Richfaces.showModalPanel('myPanel', {left:'auto', top:'auto'})");
            



            • 3. Re: Programmatically set onclick() at HtmlMenuItem
              asiandub

              thanks a million, mate :-)

              btw: calling functions from richface's javascript API seems like a huge try and error to me. i didn't manage to find any documentation...

              is there a place where i can learn about calls like this?

              #{rich:component('myPanel')}...
              javascript:Richfaces.showModalPanel('myPanel')...
              


              cheers,
              jan

              • 4. Re: Programmatically set onclick() at HtmlMenuItem
                nbelaevski

                Jan,

                It's really very easy. The first step is to check documentation for JS API that the particular component provides (example for rich:modalPanel):

                The second step is just calling the necessary function using rich:component function, format is the following:

                #{rich:component('componentId_or_clientId')}.methodName(methodArg1, methodArg2, ...)

                Treat the whole #{rich:component()} part as a shortcut to the expression that evaluates to the instance of JavaScript object representing this component on the client.

                BTW, rich:componentControl provides just another way for usage of components' JS API.

                This:
                Richfaces.showModalPanel('myPanel')
                is the function that was developed initially to provide control for modal panel; then, with the migration to JSF 1.2 and JSP 2.1, rich:* functions were added and we got just another way of controlling this.

                • 5. Re: Programmatically set onclick() at HtmlMenuItem
                  asiandub

                  Hello Nick,

                  thanks for your kind and fast respond :-)

                  I was aware of the Javascript-API on the component itself, but I did not manage to find any documentation / API description like the one you used:

                  #{rich:component('componentId_or_clientId')}.methodName(methodArg1, methodArg2, ...)
                  


                  It seems like you copied the above code sample somewhere from - and i'm wondering, if this is some sort of public documentation... Maybe there are other commands, like rich:xyz()? I have no clue..

                  Also - and the initial reason behind my question:
                  Richfaces.showModalPanel()
                  


                  I'm sure there must be some way to get information about Richfaces.xyz... I just don't know where to look for it.

                  If someone could just point me in the right direction?

                  Many thanks,
                  Jan

                  • 6. Re: Programmatically set onclick() at HtmlMenuItem
                    nbelaevski

                    Jan,

                    The example on the screenshot is taken from dev guide. http://docs.jboss.org/richfaces/latest_3_3_X/en/tlddoc/ - check function summary section.

                    This:

                    Richfaces.showModalPanel()
                    should be present in documentation for rich:modalPanel component.