Css 根据条件为表单元格着色
这是我的第一个primefaces项目,我不知道为什么我的细胞没有着色。 我的XHTML文件包含以下内容:Css 根据条件为表单元格着色,css,jsf-2,primefaces,Css,Jsf 2,Primefaces,这是我的第一个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"
<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>
<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>
但我的网络浏览器上仍然有未着色的单元格,有人能告诉我有什么问题吗
编辑:
当我改变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
有人能帮忙吗?你的情况和我的相似
h:dataTable
没有这样的属性,因为您使用的是PrimeFaces,所以应该使用它们的组件,因为它们提供了更多的功能
使用
以及其中的
如果在项目中生成样式类,可能会更具可读性,也更不容易出错,以防止EL表达式太长太复杂
您可能会注意到样式的差异,因为PrimeFaces呈现的组件使用的是jQuery UI CSS样式,但您可以像“h:”命名空间中的“旧”组件一样轻松地自定义它们。我终于找到了一个解决方案: 在myJob类中,我添加了以下方法:
public String createLabel(){
switch (jobStatus){
case "SUCCESS":
return "SUCCESS";
case "PARTIAL SUCCESS":
return "PARTIAL_SUCCESS";
case "FAILURE":
return "FAILURE";
default:
return "DEFAULT";
}
}
在我的globalReport.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>
<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>
而且它工作得很好。非常感谢@Lukasz为您提供的宝贵帮助。也许css的路径是错误的,是否喜欢这个可能的副本?我已经尝试过了,它不起作用,还有其他想法吗?@Lukasz:请阅读我的xhtml文件建议的解决方案已经完成,但没有效率,我没有得到任何积极的建议results@Djedai40哦,对不起,他们用的是战斧组件,但规则是一样的,h:dataTable没有这样的AttributeAnks,我没有注意到,但它没有改变任何东西,但当我改为时,它变得更糟,现在我收到了编辑过的错误消息,你知道这件事吗?@Djedai40看起来像是你的枚举值,或者类似的东西,而不是JSF/PrimeFaces错误消息。尝试我建议的方法,在bean中生成样式类。太长的EL表达式很难调试并且性能很差。当我在浏览器中调试时,我得到404 file not found错误,它似乎找不到该文件,是否可能我在声明时出错:@Djedai40
myJob
是没有方法的东西getJobStatus
。我不知道为什么你的收藏中有代理,这是另一个问题。您只需调试getJobs()方法返回的内容……请防止变色龙问题。标题是关于根据条件为行着色,添加其他错误会分散未来访问者的注意力。如果“某物”正在创建代理,而调试不会给您任何提示,那么最好创建一个新问题。