【问题标题】:Create parameterized primefaces components of different types创建不同类型的参数化primefaces组件
【发布时间】:2014-07-29 07:34:10
【问题描述】:

在我的 JSF webapp(使用 primefaces 5.0)中,我在不同页面上有多个非常相似的输入表单来编辑从名为 DataContainer 的抽象类派生的实体:

public abstract class DataContainer<ValueType>{

   ValueType val; // Generic type for the value
   //...
}

一个可能的子类是:

public class IntegerContainer extends DataContainer<Integer>{
   public Type getType(){
     return Type.NUMBER; // Type is an enum to determine the type during runtime.
   }
   // ...
}

在前端,我想使用不同的 PF 组件来编辑不同的数据类型(因此,DataContainer 的不同子类):例如p:spinner 用于数字,p:input 用于文本。

我目前的做法是使用组件的rendered 属性,根据getType() 返回的实际Type 与我的枚举(Type.*) 相比,是真还是假:

<p:dataGrid ... var="entity">
   <p:spinner value="#{anyPM.intValue"} rendered="#{entity.type eq Type.NUMBER}" />
   <p:inputText  value="#{anyPM.stringValue}" rendered="#{entity.type eq Type.TEXT} />
</dataGrid>

不同的页面使用不同的 PM - 所以每当我需要编辑 &lt;? extends DataContainer&gt; 类型的实体时,我都会写下相同的表格,只是替换 PM 的名称。

有没有什么办法可以动态生成上面dataGrid的内容(比如把它作为一个模板,通过参数设置PM)? 避免在我的 xhtml 中几乎重复的代码的其他建议?

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    也许你可以看看 PrimeFaces Extensions DynaForm -> http://www.primefaces.org/showcase-ext/views/dynaForm.jsf

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      • 1970-01-01
      • 2014-07-23
      • 2013-08-18
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      相关资源
      最近更新 更多