0

我有一个简单的场景,这个例子来自 PrimeFaces,但我想它适用于我将以类似方式使用的每个标签:

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

在 bean 的方法中(例如 addressBean.completeCounty),我可以访问 AutoComplete 对象。我想得到的是它的值(#{address.country})的引用,而不是值本身。

那是什么地方?

4

1 回答 1

2

我想得到的是它的值(#{address.country})的引用,而不是值本身。

#{address.country}这个问题有点含糊(可能是语言障碍),但如果我理解正确,你会出于某种原因想要作为表达式字符串。你可以得到它UIComponent#getValueExpression()然后ValueExpression#getExpressionString()

public List<Country> completeCountry(String query) {
    UIComponent component = UIComponent.getCurrentComponent(FacesContext.getCurrentInstance());
    String valueEL = component.getValueExpression("value").getExpressionString();
    // ...
}
于 2012-12-14T14:24:42.060 回答