开发者

How to access component value programmatically

Lets assume I want to access the value of a sibling component in an ActionListener.

The following fragment is not working as expected, resulting in a ClassCastException: java.util.HashSet cannot be cast to java.lang.String

public void processAction(final ActionEvent event) {

    FacesContext ctx = FacesContext.getCurrentInstance();
    UIComponent sibling = event.getComponent().findComponent("inputText");

    String value = 开发者_C百科(String) sibling.getValue();
    ...
}

If I change the essential part to the following fragment everything works fine:

String value = ctx.getApplication().evaluateExpressionGet(ctx, inputText.getValueExpression("value").getExpressionString(), String.class);

Is there a nicer solution? Why is the value of the inputText of type HashSet?

Thx in advance

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜