JSF中readOnly/edition模式的最佳实践?

1 jsf primefaces composite-component

任何人都可以建议一种方法来执行编辑/只读模式?我正在使用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>
Run Code Online (Sandbox Code Playgroud)

只是根据布尔值显示inputText或outPutText.但显然PF的inputText中存在一个错误,因为我收到了一个targetClass null异常.如果我在组件外使用inputText它可以工作,但我想用comp来封装这种行为.还有其他建议吗?

Bal*_*usC 5

我建议使用该disabled属性,如果需要,使用CSS将输入设置为看起来像输出.

例如

<p:inputText value="#{bean.value}" disabled="#{!bean.editable}" />
Run Code Online (Sandbox Code Playgroud)

用CSS

.ui-inputfield[disabled], .ui-inputfield[disabled].ui-state-focus {
    border: 0 !important;
    box-shadow: none !important;
    outline: 0 !important;
}
Run Code Online (Sandbox Code Playgroud)