多值的JSF托管属性 [英] JSF managed property for multivalues
问题描述
正如BalusC建议的,作为对此问题的答案,我想创建一个如下的托管属性:>
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;
}
在我的项目中,每个受管bean的声明和设置都在faces-config.xml文件中完成.按照建议将注释放入代码中,不会给我带来任何结果.
ftValues始终为null,即使我有一个或多个<input name="freetext">
可能因为主要配置技术使用XML文件而没有考虑注释吗?
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?
如何将ManagedProperty声明放入faces-config.xml
?我尝试添加
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>
在适当的托管bean部分中,但由于该错误而崩溃
in the appropriate managed bean section, but it crashes with this error
找不到托管bean myBean的bean或属性类java.lang.String [].
Bean or property class java.lang.String[] for managed bean myBean cannot be found.
推荐答案
实际上,每当您在faces-config.xml
中声明bean时,注释都将被忽略.如果出于某些不清楚的原因,实际上不能从faces-config.xml
删除bean,那么您需要删除<property-class>
来解决问题. JSF可以完美地自己解决这个问题.
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.
这篇关于多值的JSF托管属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!