JSF managed property for multivalues

会有一股神秘感。 提交于 2019-12-11 06:37:28

问题


As suggested by BalusC as an answer to this question, I wanto to create a managed property like this:

@ManagedProperty("#{paramValues.freetext}")
private String[] ftValues;

public String[] getFtValues(){ 
    return ftValues;
}

public void setFtValues(String[] values){
    ftValues = values;
}

In my project every managed bean declaration and settings has done in the faces-config.xml file. Putting the annotation in the code as suggested, doesn't bring me any result. ftValues is always null, even if I have one or more <input name="freetext"> Is it possible that the annotation is not take into consideration because the main configuration technique use the XML file?

How can I put the ManagedProperty declaration into the faces-config.xml? I tried adding

<managed-property>
    <property-name>ftValues</property-name>
    <property-class>java.lang.String[]</property-class>
    <value>#{paramValues.freetext}</value>
</managed-property>

in the appropriate managed bean section, but it crashes with this error

Bean or property class java.lang.String[] for managed bean myBean cannot be found.


回答1:


Indeed, the annotations are ignored whenever you declare the bean in faces-config.xml. If removing the bean from faces-config.xml is really not an option for some unclear reason, then you need to remove the <property-class> to fix the problem. JSF can perfectly figure it by itself.



来源:https://stackoverflow.com/questions/8067100/jsf-managed-property-for-multivalues

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