Gui*_*o03 7 css primefaces jsf-2
这是我的第一个带有primefaces的项目,我无法找出为什么我的细胞没有着色.我的XHTML文件包含以下内容:
<h:head>
<title>Job Status Reporter</title>
<link rel="stylesheet" type="text/css" href="/jobstatusreport/colors.css" />
</h:head>
...
<h:dataTable var="myJob" value="#{workPackage.jobs}"
rowStyleClass="#{myJob.jobStatus == 'SUCCESS' ? 'green' :
(myJob.jobStatus == 'PARTIAL SUCCESS' ? 'yellow' : (myJob.jobStatus == 'FAILURE' ? 'red' :'white'))}">
<h:column>
<h:outputText value="#{myJob.jobId}" />
</h:column>
<h:column>
<h:outputText value="#{myJob.jobType}" />
</h:column>
<h:column>
<h:outputText value="#{myJob.jobStatus}" />
</h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
我的colors.css文件在WebContent/resources/css /文件夹中创建,定义如下:
.green.ui-datatable { background: green;}
.red.ui-datatable {background: red;}
.yellow.ui-datatable {background: yellow;}
.white.ui-datatable {background: white;}
Run Code Online (Sandbox Code Playgroud)
但我仍然在我的网络浏览器上获得无色细胞,有谁能告诉我这是什么问题?
编辑:
当我将h:dataTable ...更改为p:dataTable时......我收到以下消息:
/globalReport.xhtml @32,169 rowStyleClass="#{myJob.jobStatus == 'SUCCESS' ? 'green' : (myJob.jobStatus == 'PARTIAL SUCCESS' ? 'yellow' : (myJob.jobStatus == 'FAILURE' ? 'red' : 'white'))}": Property 'jobStatus' not found on type org.hibernate.collection.internal.AbstractPersistentCollection$SetProxy
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我终于找到了一个解决方案:在myJob类中我添加了以下方法:
public String createLabel(){
switch (jobStatus){
case "SUCCESS":
return "SUCCESS";
case "PARTIAL SUCCESS":
return "PARTIAL_SUCCESS";
case "FAILURE":
return "FAILURE";
default:
return "DEFAULT";
}
}
Run Code Online (Sandbox Code Playgroud)
在我的globalReport.xhtml中,我更改了以下内容:
<h:head>
<title>Job Status Reporter</title>
<h:outputStylesheet library="css" name="colors.css" target="head" />
</h:head>
....
<h:dataTable var="myJob" value="#{workPackage.jobs}">
<h:column>
<h:outputText value="#{myJob.jobId}"/>
</h:column>
<h:column>
<h:outputText value="#{myJob.jobType}"/>
</h:column>
<h:column>
<h:outputText value="#{myJob.jobStatus}" styleClass="#{myJob.createLabel()}"/>
</h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
和我的colors.css是:
.SUCCESS{
background-color : green !important;
}
.FAILURE{
background-color: red !important;
}
.PARTIAL_SUCCESS{
background-color: yellow !important;
}
.DEFAULT{
background-color: white !important;
}
Run Code Online (Sandbox Code Playgroud)
它完美无缺.非常感谢@Lukasz的宝贵帮助.
| 归档时间: |
|
| 查看次数: |
16116 次 |
| 最近记录: |