1

Is there any way to access a parameter for a <a4j:jsFunction> in the oncomplete="" attribute of it, without using the action="" attribute and assingTo="" of <a4j:param>?

<a4j:jsFunction name="refreshTableFilter" render="table,scroller" execute="@form" oncomplete="setCursor(componentId);">
    <a4j:param name="componentId" />
</a4j:jsFunction>

I'm looking for a way to access the <a4j:param>directly. I don't need the parameter in a BackingBean and I don't need the action="" attribute.

UPDATE

My current code is:

    <rich:extendedDataTable id="table"
        rowKeyVar="index" selectionMode="single"
        selection="#{cc.attrs.controller.selection}"
        displayColumnsOrder="#{cc.attrs.configController.currentColumnConfig}"
        rowClasses="light-table-row,dark-table-row"
        value="#{cc.attrs.controller.entities}" var="entity"
        rows="#{cc.attrs.rows}">

        <a4j:ajax event="rowclick" onbegin="tableRowClick(#{index})"/> 

        <rich:column id="cShipName" styleClass="segment"
            filterValue="#{cc.attrs.controller.vesselNameFilter}"
            filterExpression="#{fn:containsIgnoreCase(entity.vesselName, fn:trim(cc.attrs.controller.vesselNameFilter))}"
            width="140px">
            <f:facet name="header" id="headerShipName">
                <div style="margin-top: 5px;">
                    <h:inputText id="shipnameFilter" style="width:99.9%" value="#{cc.attrs.controller.vesselNameFilter}" />
                </div>
            </f:facet>
            <h:outputText value="#{entity.vesselName}" />               
        </rich:column>

  ...

    </rich:extendedDataTable>

And the javascript that calls the a4j:jsFunction:

      $(document).bind('keypress', function(e) {
         if(e.keyCode==13){
            var elementId = document.activeElement.id;
            if (elementId.indexOf('shipnameFilter') != -1) {
                refreshTableFilter();
                return false;
            }                
            return true;
         }
      });

a4j:jsFunction:

<a4j:jsFunction name="refreshTableFilter" render="table@body, scroller" execute="@form" />

The jsFunction works correctly if I remove the @body in the render=""attribute, but with it the table show nothing after rendering (if I press F5, the correct data will be show in the table).

mbulau
  • 359
  • 1
  • 7
  • 19

1 Answers1

2

Based on the code snipped, you are trying to re-render a table on filter change and then set focus back to filter input. I guess the filter inputs are placed in table header (and they lose focus once table is re-rendered).

One way (more efficient) to make it work is not to re-render the inputs, you can use meta components to render only table's header/body/footer:

<a4j:jsFunction name="refreshTableFilter" render="table@body table@footer scroller" execute="@form"/>

Regarding your initial question. It does not seem to be possible to get parameter in oncomplete handler without assigning it to something on server side. For example:

   <a:jsFunction name="refreshTableFilter" render="table,scroller" execute="@form"
                 oncomplete="setCursor(event.data);"
                 data="#{refreshTableFilterParam}">
      <a:param name="paramName" assignTo="#{refreshTableFilterParam}"/>
    </a:jsFunction>
iBoolGuy
  • 51
  • 11
Andrey
  • 6,526
  • 3
  • 39
  • 58
  • Your answer regarding the meta components sounds very good to me, but unfortunately it doesn't work proper. I changed `render="table,scroller"` to `render="table@body,scroller"`and the input field is still focused (after render), but the table body is always empty after render. e.g. the table has two row's. When I type something into the filter field and one row shuld be displayed after render, but no row will be displayed. If I clear the filter value, after render no row will be displayed. Is there anything I have to do to use meta components? – mbulau Mar 13 '13 at 08:44
  • @marco235 The metas are supported by rich:extendedDataTable, are you using this component? Can you provide more code (including the table). – Andrey Mar 14 '13 at 00:06
  • I use the extendedDataTable. I updated the question with my current code. – mbulau Mar 14 '13 at 14:15
  • @marco235 I tried the code from your example and it work OK for me. I tried on RichFaces 4.2.0.Final (on latest version 4.3.0.Final you would need to specify filterType="custom"). Is the jsFunction in the same form as the table? You may want to ask a new question about why render="table@body" does not work for you as expected. – Andrey Mar 14 '13 at 22:12
  • Thanks for your help. I currently use RichFaces 4.2.2.Final and I changed it to 4.3.0.Final with no success. I will look for an answer why @body don't work. If I found it, I will post the solution here. – mbulau Mar 15 '13 at 07:09
  • And yes, the jsFunction is in the same form. I tried it in an other form but also no success. – mbulau Mar 15 '13 at 07:12