Primefaces autocomplete completeMethod with extra parameter

Viewed 34

I have autoComplete inside dataTable which is using completeMethod. Is it possible to pass row object to the completeMethod bean implementation or somehow let the bean know on which row object I am currently working? Thank you.

Pseudo code:

<p:dataTable var="selection" value="#{bean.selections}">
    <p:column headerText="Selection">
        <p:autoComplete id="dd" dropdown="true" value="#{bean.country}"
                        completeMethod="#{bean.completeText(selection)}"> 
            <p:ajax event="itemSelect"/>
        </p:autoComplete>
    </p:column>
</p:dataTable>
2 Answers

Rubber duck effect, sorry for answering my own question so fast. I have moved my completeMethod to selection object, which in my case holds all the additional parameters I need. Hope someone finds it useful.

<p:dataTable var="selection" value="#{bean.selections}">
    <p:column headerText="Selection">
        <p:autoComplete id="dd" dropdown="true" value="#{bean.country}"
                        completeMethod="#{selection.completeText}">
            <p:ajax event="itemSelect"/>
        </p:autoComplete>
    </p:column>
</p:dataTable>

You can pass attributes in command / ajax components to your action / listener method like:

<p:autoComplete>
    <f:attribute name="foo" value="#{bean.foo}"/>`
</p:autoComplete>

In your bean method you can access attributes like:

FacesContext = FacesContext.getCurrentInstance();
final UIComponent component = UIComponent.getCurrentComponent(context);

Object foo = component.getAttributes().get("foo");

Depending on your requirement you can either pass the row var instance directly or maybe just the "id / rowkey" and look it up manually.

Related