我在 faces-config.xml
中有一个映射的bean<managed-bean>
<managed-bean-name>beanName</managed-bean-name>
<managed-bean-class>java.util.HashMap</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
<managed-property>
<property-name>elements</property-name>
<map-entries>
<key-class>java.lang.String</key-class>
<value-class>path.InputFormElementContainer</value-class>
</map-entries>
</managed-property>
</managed-bean>
java中的实现是:
public class InputFormElementContainer implements List<InputFormElement>, Serializable{
private static final long serialVersionUID = -4685106549564090233L;
private List<InputFormElement> elements;
//Empty Constructor
public InputFormElementContainer() {
elements = new ArrayList<InputFormElement>();
}
public List<InputFormElement> getElements() {
return elements;
}
public void setElements(List<InputFormElement> elements) {
this.elements = elements;
}
}
但是当我刷新我的应用程序时,我收到了这个错误:
com.sun.faces.mgbean.ManagedBeanCreationException: No se puede crear el bean administrado beanName. Se han encontrado los problemas siguientes:
- No existe la propiedad elements para el bean administrado beanName.
对英语的翻译可能是:由于以下问题,无法创建管理的beanName:beanName不存在elemts属性。
迁移到JSF2时遇到了这个问题。我正在阅读教程,但我无法弄清楚如何在JSF2中正确地创建这个manage-bean。有人能帮助我吗? 提前谢谢!
答案 0 :(得分:1)
这是错误的
<managed-bean-name>beanName</managed-bean-name>
<managed-bean-class>java.util.HashMap</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
<managed-property>
<property-name>elements</property-name>
此处jsf将搜索java.util.HashMap中不存在的字段elements
的getter / setter,因此错误
答案 1 :(得分:0)
根据您对InputFormElementContainer类的建模方式,您有两种选择
如果您需要'elements'作为List:
<managed-bean>
<managed-bean-name>beanName</managed-bean-name>
<managed-bean-class>java.util.HashMap</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
<managed-property>
<property-name>elements</property-name>
<property-class>java.util.ArrayList</property-class>
<list-entries>
<value-class>path.InputFormElementContainer</value-class>
<value>...</value
...
</list-entries>
</managed-property>
</managed-bean>
或者如果您需要'elements'属性作为Map:
<managed-bean>
<managed-bean-name>beanName</managed-bean-name>
<managed-bean-class>java.util.HashMap</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
<managed-property>
<property-name>elements</property-name>
<property-class>java.util.HashMap</property-class>
<map-entries>
<key-class>java.lang.String</key-class>
<value-class>path.InputFormElementContainer</value-class>
<map-entry>
<key></key>
<value></value>
</map-entry>
</map-entries>
</managed-property>
</managed-bean>