1 Reply Latest reply on Sep 19, 2007 4:51 AM by schneider thomas

    Custom component with HtmlActionParameter

    schneider thomas Newbie

      Hi,

      I add a facelet taglib I used to render dataTable with custom functions and components. But I need to replace it with a standard JSF taglib (to add a simple PDF generation using the same source files).
      So I created my own compoments extending Rich Faces components, but I found a problem converting my a4j:jsFunction and it's a4j:actionparam.

      Here is what I add in my facelet taglib :


      <!-- The table content -->
      <rich:dataTable value="#{tableData.elements}" ... >
       ...
       <ui:insert />
       ...
      </rich:dataTable>
      
      <!-- Javascript method for selection. -->
      <a4j:jsFunction
       name="TPZTableSelection_#{tableData.tableId}"
       action="#{tableData.selectById}"
       reRender="TPZ#{tableData.tableId}" >
      
       <a4j:actionparam name="id" assignTo="#{tableData.selectedObjectId}" />
       <a4j:actionparam name="addToSelectionKey" assignTo="#{tableData.addToSelectionKey}" />
       <a4j:actionparam name="rangeSelectionKey" assignTo="#{tableData.rangeSelectionKey}" />
      </a4j:jsFunction>
      


      When the jsFunction was called from javascript, everything worked fine and my action parameters where setted before the selectById method was called.

      Here his what I use in my JSF version :

      String vbData = m_vbDataTable.getExpressionString();
      String vbSelection = vbData.replace( "}", ".selectById}" );
      String vbSelectionId = vbData.replace( "}", ".selectedObjectId}" );
      String vbSelectionAdd = vbData.replace( "}", ".addToSelectionKey}" );
      String vbSelectionRange = vbData.replace( "}", ".rangeSelectionKey}" );
      
      // Add the jsFunction used to select table elements.
      HtmlAjaxFunction jsSelectionFunction = new HtmlAjaxFunction();
      jsSelectionFunction.setId( context.getViewRoot().createUniqueId() );
      jsSelectionFunction.setName( "TPZTableSelection_" + getDataTable().getTableId() );
      jsSelectionFunction.setAction( FacesContext.getCurrentInstance().getApplication().createMethodBinding( vbSelection, null ) );
      jsSelectionFunction.setReRender( getId() );
      getParent().getChildren().add( jsSelectionFunction );
      jsSelectionFunction.setParent( getParent() );
      
      // Selected element identifier parameter.
      HtmlActionParameter ap1 = new HtmlActionParameter();
      ap1.setId( context.getViewRoot().createUniqueId() );
      ap1.setName( "id" );
      ap1.setAssignToBinding( FacesContext.getCurrentInstance().getApplication().createValueBinding( vbSelectionId ) );
      jsSelectionFunction.getChildren().add( ap1 );
      ap1.setParent( jsSelectionFunction );
      
      // Add to selection with CTRL parameter.
      HtmlActionParameter ap2 = new HtmlActionParameter();
      ap2.setId( context.getViewRoot().createUniqueId() );
      ap2.setName( "addToSelectionKey" );
      ap2.setAssignToBinding( FacesContext.getCurrentInstance().getApplication().createValueBinding( vbSelectionAdd ) );
      jsSelectionFunction.getChildren().add( ap2 );
      ap2.setParent( jsSelectionFunction );
      
      // Add range to selection with MAJ parameter.
      HtmlActionParameter ap3 = new HtmlActionParameter();
      ap3.setId( context.getViewRoot().createUniqueId() );
      ap3.setName( "rangeSelectionKey" );
      ap3.setAssignToBinding( FacesContext.getCurrentInstance().getApplication().createValueBinding( vbSelectionRange ) );
      jsSelectionFunction.getChildren().add( ap3 );
      ap3.setParent( jsSelectionFunction );
      


      Using this code, the javascript generated for the jsFunction is the same that the one generated with the facelet version. The jsFunction call is executed the same way and with the same parameters.
      When calling this jsFunction, the "selectById" method is called without problem, but my parameters are not set.

      For exemple, if I call :
      TPZTableSelection_3( '5', 'true', 'false');
      

      when executing the selectById method, selectedObjectId, addToSelectionKey and rangeSelectionKey are still null.

      I surelly miss something, but I don't know what :/