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).
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>
来源:https://stackoverflow.com/questions/15359815/how-to-access-a-parameter-in-a4jjsfunctions-oncomplete-attribute