开发者

How to access component value programmatically

开发者 https://www.devze.com 2023-04-07 07:59 出处:网络
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

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

精彩评论

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