1
我有這個dataTable的XHTML代碼。使用JavaScript更改dataTable中列的標題
<p:dataTable id="processes" var="process" value="#{homeBean.processesList}" filteredValue="#{homeBean.filteredProcesses}"
rowKey="#{process.pid}" selection="#{homeBean.selectedProcesses}"
paginator="true" rows="8" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" >
<f:facet name="header">
<h:outputText value="Processes" />
</f:facet>
<p:column name="owner" filterBy="owner" filterMatchMode="contains" sortBy="owner" headerText="Owner">
<h:outputText value="#{process.owner}" />
</p:column>
<p:column name="pid" filterBy="pid" filterMatchMode="exact" sortBy="pid" headerText="PID">
<h:outputText value="#{process.pid}" />
</p:column>
<p:column name="ppid" filterBy="ppid" filterMatchMode="exact" sortBy="ppid" headerText="PPID">
<h:outputText value="#{process.ppid}" />
</p:column>
<p:column name="c" filterBy="c" filterMatchMode="exact" sortBy="c" headerText="C">
<h:outputText value="#{process.c}" />
</p:column>
<p:column name="stime" filterBy="stime" filterMatchMode="contains" sortBy="stime" headerText="STIME">
<h:outputText value="#{process.stime}" />
</p:column>
<p:column name="tty" filterBy="tty" filterMatchMode="contains" sortBy="tty" headerText="TTY">
<h:outputText value="#{process.tty}" />
</p:column>
<p:column name="time" filterBy="time" filterMatchMode="contains" sortBy="time" headerText="TIME">
<h:outputText value="#{process.time}" />
</p:column>
<p:column name="cmd" filterBy="cmd" filterMatchMode="contains" sortBy="cmd" headerText="CMD">
<h:outputText value="#{process.cmd}" />
</p:column>
</p:dataTable>
此代碼顯示在一個表中的擁有者,PID,PPID,C,STIME,時間,TTY並且每一個過程的CMD信息在所選擇的服務器。 我想改變headerText,當我得到一個Windows服務器,所以我寫這個JavaScript代碼,我要通過正確的方式?
<script type="text/javascript">
var server_os = "#{homeBean.selectedLogicalServer.os}";
if (server_os.search("Windows") != -1) {
document.getElementById("owner").headerText="User Name";
document.getElementById("ppid").headerText="Sesion Number";
document.getElementById("c").headerText="Sesion Number";
document.getElementById("stime").headerText="User Name";
document.getElementById("tty").headerText="Sesion Name";
document.getElementById("cmd").headerText="Image Name";
}
</script>
謝謝!這解決了它! –