How to access component value programmatically

拜拜、爱过 提交于 2021-02-19 07:52:29

问题


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 = (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

来源:https://stackoverflow.com/questions/7554789/how-to-access-component-value-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!