JSF中只读/编辑模式的最佳实践



谁能建议一种方法来执行版本/只读模式?我正在使用PF,我已经这样做了:

<composite:interface>
        <composite:attribute name="size"/>
        <composite:attribute name="value"/>
        <composite:attribute name="editable"/>
    </composite:interface>
    <composite:implementation>
        <p:inputText value="#{cc.attrs.value}"  size="#{cc.attrs.size}" rendered="#{cc.attrs.editable}"/>
        <h:outputText value="#{cc.attrs.value}" rendered="#{!cc.attrs.editable}"/>
    </composite:implementation>

根据布尔值显示输入文本或输出文本。但显然PF的inputText有一个bug,因为我收到一个targetClass null异常。如果我在组件外使用inputText,它就会工作,但我想将这种行为封装在一个组件内。还有其他建议吗?

我建议使用disabled属性,如果必要的话,使用CSS样式化输入,使其看起来像输出。

<p:inputText value="#{bean.value}" disabled="#{!bean.editable}" />
用CSS

.ui-inputfield[disabled], .ui-inputfield[disabled].ui-state-focus {
    border: 0 !important;
    box-shadow: none !important;
    outline: 0 !important;
}

最新更新