1
我想通過單擊一個commandbutton來更改datgrid元素的背景顏色。我目前不知道如何做到這一點。Primefaces通過單擊按鈕單擊切換dataGrid元素的顏色
當我點擊下面的按鈕時,網格項目的元素被添加到列表中,我想將面板項目的顏色更改爲(例如黃色),以便用戶可以看到,此元素被標記。
<p:commandButton icon="ui-icon-pin-w"
action="#{cmsMarkedDocumentHandler.addDocument(_document)}"/>
這是我的dataGrid的代碼。
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:m="http://java.sun.com/jsf/composite/components/mmnet">
<h:form id="docDataGridForm">
<p:dataGrid id="docDataGrid"
value="#{cmsDocumentSearchHandler.documentList}"
var="_document"
columns="2"
rows="10"
lazy="true"
paginator="true"
paginatorPosition="bottom"
paginatorAlwaysVisible="false"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15,20,25,50">
<p:panel header="#{_document.shortName}" style="text-align:center">
<h:panelGrid columns="2" style="width:100%" >
<p:outputLabel value="#{labels.name}" />
<p:outputLabel value="#{_document.name}" />
<p:outputLabel value="#{labels.dateiName}" />
<p:outputLabel value="#{_document.fileName}"/>
<p:outputLabel value="#{labels.aenderungsDatum} #{labels.aenderer}" />
<m:outputDateUser valueDate="#{_document.modDate}" valueUser="#{_document.modUser}" />
<p:commandLink update=":eastPanel" title="#{labels.details}">
<h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" />
<f:setPropertyActionListener value="#{_document}" target="#{documentHandler.entity}" />
</p:commandLink>
<m:cmsDocumentVersionLinks value="#{_document}" newLine="true" showDate="true"></m:cmsDocumentVersionLinks>
<p:outputLabel value="#{labels.merken}"></p:outputLabel>
<p:commandButton icon="ui-icon-pin-w"
action="#{cmsMarkedDocumentHandler.addDocument(_document)}"/>
</h:panelGrid>
</p:panel>
</p:dataGrid>
</h:form>
<h:form id="createCmsDocument">
<p:outputPanel rendered="#{documentCategoryHandler.entity != null}">
<m:formButtons id="createCmSDocButton"
entity="#{documentHandler.entity}"
renderCreate="true"
renderAbort="false"
renderDelete="false"
renderSave="false"
actionCreate="#{documentHandler.create()}"
updateCreate=":contentPanel :eastPanel"
rendered="true">
</m:formButtons>
</p:outputPanel>
</h:form>
</ui:composition>