3 Replies Latest reply on Sep 7, 2010 4:04 AM by nille m

    How to show modal panel or call bean method in commandButton

    nille m Newbie

      Hi everybody,

       

      I have a question regarding the combination of using JS in a a4j:commandButton and executing an action. There is the following scenario: If the commandButton is clicked either a modalPanel should be displayed or a bean method should be called. For now I have the following elements in use.

       

      {code:xml}

      <a4j:jsFunction name="executeSaveAction"  eventsQueue="ajaxQueue" action="#{myBean.save()}"

           reRender="buttonArea"/>


      <rich:messages id="messages" errorClass="messageError" infoClass="messageInfo" warnClass="messageWarn"/>


      <a4j:commandButton styleClass="save-button" id="save" value="save" ajaxSingle="true"
           type="submit" eventsQueue="ajaxQueue" oncomplete="Javascript: window.location.hash='#top';"

       

           onclick="#{(myBean.location or myBean.employees) ?  'Richfaces.showModalPanel(\'modalPanelSaveOrCancel\');'  :'executeSaveAction;'}"/>

       

      <ui:insert name="modalPanelSaveOrCancel">


          <ui:include src="modalPanelSaveOrCancel.xhtml"/>

       

      </ui:insert>

      {code}

       

      The problem with this solution is that two ajay requests are generated, one for the commandButton and another one for the a4j:Function. The bean method creates a info message which should be displayed after the method ends. This works, but only as long as the second ajax request ends. Than the message disappears. In the 'onclick' attribute of the commandButton only JS is allowed, right? Therefore I used the a4j:function to call the bean method from within the 'onclick' attribute.

       

      My question is: how can I get rid of the second ajax request?

       

      Thanks in advance,

       

      Cheers,
      nille