我有带行编辑的dataTable,但我不需要编辑我的一个单元(user.username)。我怎么能在primefaces做这个?这可能吗?我尝试删除一个单元格的 p:cellEditor ,但它在我的平板电脑上不起作用,因为当我在DataTable中使用它时,此列为空。
谢谢!
我的代码:
<h:form id="form">
<p:growl id="messages" showDetail="true" />
<p:contextMenu for="dataTable">
<p:menuitem value="Delete" update="dataTable" icon="ui-icon-close"
actionListener="#{userMB.deleteUser}" />
</p:contextMenu>
<p:dataTable id="dataTable" var="user" styleClass="DataTableUsers"
value="#{userMB.userList}" paginator="true" rows="5"
rowKey="#{user.user_id}" selection="#{userMB.selectedUser}"
selectionMode="single" filteredValue="#{userMB.filteredUsers}"
editable="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:ajax event="rowEdit" immediate="true" listener="#{userMB.onEdit}"
update=":form:messages, :form:dataTable" process="@this" />
<p:column sortBy="name" filterBy="name" id="name" headerText="Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.name}" required="true"
requiredMessage="Please Enter Name"
validatorMessage="Name is too short!">
<f:validateLength minimum="2"></f:validateLength>
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="surname" filterBy="surname" headerText="Surname">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.surname}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.surname}" required="true"
requiredMessage="Please Enter Surname!"
validatorMessage="Surname is too short!">
<f:validateLength minimum="2"></f:validateLength>
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="username" filterBy="username"
headerText="Index number">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.username}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{user.username}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="userDescription" filterBy="userDescription"
headerText="descript">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.userDescription}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.userDescription}" required="true"
requiredMessage="Please Enter User Description" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6%" headerText="Edit">
<p:rowEditor />
</p:column>
<f:facet name="footer">
<p:commandButton value="New User" oncomplete="newUserDialog.show()"
icon="ui-icon-star" title="Creates new user" />
</f:facet>
</p:dataTable>
</h:form>
答案 0 :(得分:3)
只需将包含user.username
值的组件更改为<h:outputText>
<h:outputText value="#{user.username}" />
,您将获得只读值。