多值的 JSF 托管属性 [英] JSF managed property for multivalues

查看:25
本文介绍了多值的 JSF 托管属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如 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,即使我有一个或多个 是否有可能因为主要的配置技术使用 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 确实不是一个选项,原因不明,那么您需要删除 以解决问题.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆