jsf2 +<托管财产><属性名称>

发布于 2024-10-30 05:12:55 字数 1628 浏览 1 评论 0原文

我在 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 中正确制作这个管理 bean。有人可以帮助我吗?
提前致谢!

I have a mapped bean in faces-config.xml

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

The implementation in java is:

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;
    }
}

But I am getting this error when I refresh my application:

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.

The translation to english could be: can not create the administrated beanName due to the following problem: elemts property does not exist for beanName.

This problem came to me in the migration to JSF2. I was reading tutorials, but I could't figure out how to make this manage-bean propperly in JSF2. Could anybody help me??
Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光清浅 2024-11-06 05:12:55

这是错误的

<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 不存在,所以错误

It is wrong

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

here jsf will search for getters/setters of the field elements in java.util.HashMap which doesn't exist, and so the error

〆一缕阳光ご 2024-11-06 05:12:55

根据您想要如何对类 InputFormElementContainer 进行建模,您有两个选择

如果您需要将“elements”作为列表:

<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”属性作为映射:

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

You have two options depending of how you want to model your class InputFormElementContainer

If you need 'elements' to be a 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>

Or if you need 'elements' property to be a 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文