Balázs Németh
Balázs Németh

Reputation: 6637

JSF 2: Accessing the object a component's value was bound to

I have simple scenario, this example comes from PrimeFaces, but I guess it applies for every tag I would use in a similar way:

<p:autoComplete value="#{address.country}" id="#{layoutId}_country" 
    completeMethod="#{addressBean.completeCountry}" var="country"
    itemLabel="#{country.name}" itemValue="#{country}"
    converter="#{countryConverter}">
</p:autoComplete>

In a method of a bean (eg. addressBean.completeCounty) I have access to an AutoComplete object. What I'd like to get is the reference of its value (#{address.country}), not the value itself.

Where is that bound to?

Upvotes: 0

Views: 1101

Answers (1)

BalusC
BalusC

Reputation: 1108722

What I'd like to get is the reference of its value (#{address.country}), not the value itself.

This question is a bit vague (it's likely the language barrier), but if I understand you correctly, you'd like to get #{address.country} as expression string for some reason. You can get it by UIComponent#getValueExpression() and then ValueExpression#getExpressionString().

public List<Country> completeCountry(String query) {
    UIComponent component = UIComponent.getCurrentComponent(FacesContext.getCurrentInstance());
    String valueEL = component.getValueExpression("value").getExpressionString();
    // ...
}

Upvotes: 2

Related Questions