0 Replies Latest reply on Jan 27, 2012 12:16 PM by robertwalker

    a4j:param not invoking my javscript pointed to by value attribute

    robertwalker

      i am open to a different way to do this, but what i have seems like it should work from the documentation for RichFaces4 and JSF2

      the user flow goes like this

       

      1) there is a 'Check Out' document link implemented with h:outputLink

      2) user clicks it and gets prompted with a dialog to enter check out comments implemented with rich:popupPanel

      3) user enters comments and clicks 'Continue' Button on the rich:popupPanel implemented with h:link (tried h:commandLink and a4j:commandLink also)

      4) a new window pops up with the contents set to the h:link outcome attribute

       

      In my broken case, everything works except when i pass a parameter from h:link with a4j:param, whose value attribute does not resolve the javascript it points to correctly.

       

       

      <h:outputLink id="promptForCommentsLink" 
                    onclick="#{rich:component('commentsDlg')}.show();return false;" 
                    value="#"> Check Out </h:outputLink> 
      

       

       

       

      <rich:popupPanel id="commentsDlg" modal="true"> 
          <h:inputTextarea id="commentsId"/> 
          <h:link id="continueLink" 
                    outcome="editorPage" <!-- editor for making changes to document --> 
                    target="_blank" <!-- open in it;s own indow -->
                    value="Continue Check Out"                
                    onclick="#{rich:component('commentsDlg')}.hide();"> 
      
              <!-- these params get assignd to backing bean properties --> 
              <a4j:param name="dataId" 
                         value="#{ithRow.id}" assignTo="#{myController.dataId}"/> 
              <a4j:param name="checkedOut" 
                         value="true" assignTo="#{myController.checkedOut}"/> 
       
              <!-- this one is broken. assigns chars 'document.getElementById('..  
                   to #{myController.checkOutComment} --> 
              <a4j:param name="checkOutComment" 
                         assignTo="#{myController.checkOutComment}" 
                         noEscape="true" 
      value="document.getElementById('myForm:dataTable:0:commentsId').value" 
                         /> 
          </h:link> 
      </rich:popupPanel>
      
      

       

      I was thinking maybe

      document.getElementById('myForm:dataTable:0:commentsId').value 

      didn't point to what i typed into the textarea, but by putting another button on the dlg and pointing it's onclick to same element id, it did indeed alert me with what it typed.

       

      When i stop on the server side view scoped myController.setCheckOutComment(String s) method,

      it gets passed the string "document.getElementById('myForm:dataTable:0:commentsId').value"

       

       

      according to RF4 documentation

       

      The a4j:param tag can be used with non-Ajax components in addition to Ajax components. This includes components which are working through the GET request, such as the h:link

       

      and

       

      Variables from JavaScript functions can be used for the value attribute. In such an implementation, the noEscape attribute should be set to true. Using noEscape="true", the value attribute can contain any JavaScript expression or JavaScript function invocation, and the result will be sent to the server as the value attribute.

       

      since i seem to be playing by the jsf2/rf4 rules, i would think this would be okay.

       

       

      one thing to note, if i use a4j:commandLink instead of h:link, it does indeed send

      the result of javascript evaluated, however, that breaks the opening in its own window and a few other issues.

       

      any thoughts on what might be happening, or even a better way to do this?