我试图根据载体对象上的“ Team__c”字段中的ID是否与用户列表中的任何ID匹配,来更改列表中值的颜色。我的控制器一次返回了该颜色,并且该颜色适用于所有记录(请参见调试日志)。列表中的所有值均为蓝色,有些应为红色。先感谢您。
Visualforce代码:::
<apex:pageblocktable value="{!carriers}" var="c">
<apex:column headervalue="Carrier">
<font color="{!color2}">
<apex:outputtext value="{!c.name}"/>
</font>
</apex:column>
控制器:::
public string getcolor2() {
list<carrier__c> carriers = [select team__c from carrier__c where team__c != NULL];
list<user> users= new list<user>();
users = [select id from user where userrole.name = 'Executive'];
set<string> uid = new set<string>();
for(user us: users){
uid.add(us.id);
}
string color = 'red';
for(carrier__c car: carriers){
system.debug('*****List of carriers: ' + carriers);
system.debug('*****List of users: ' + uid);
system.debug('*****Current carrier= '+car);
if(uid.contains(car.team__c) ){
color='blue';
system.debug('***** Set color to:'+color);
}
}
system.debug('***** Returning color: ' + color);
return color;
}
调试日志
*****List of carriers: (Carrier__c:{Team__c=005U0000001D3E5IAK, Id=a0HJ0000003bl8nMAA}, Carrier__c:{Team__c=005J0000001EEIHIA4, Id=a0HJ0000003bitnMAA}, Carrier__c:{Team__c=005U0000001BHRKIA4, Id=a0HJ0000003eD64MAE})
*****List of users: {005U0000001D3E5IAK}
*****Current carrier= Carrier__c:{Team__c=005U0000001D3E5IAK, Id=a0HJ0000003bl8nMAA}
***** Set color to:blue
*****List of users: {005U0000001D3E5IAK}
*****Current carrier= Carrier__c:{Team__c=005J0000001EEIHIA4, Id=a0HJ0000003bitnMAA}
*****List of users: {005U0000001D3E5IAK}
*****Current carrier= Carrier__c:{Team__c=005U0000001BHRKIA4, Id=a0HJ0000003eD64MAE}
***** Returning color: blue
您的控制器中只有一种颜色变量,因此您不能期望在VisualForce页面中获得多种颜色。您将要创建一个同时存储carrier__c
对象和颜色的类,然后创建一个列表以存储每个对象的实例carrier__c
。
public class colorAndObject {
public string color{get; set;}
public carrier__c carrier{get;set;}
public colorAndObject(string carColor, carrier__c carrierName) {
color = carColor;
carrier = carrierName;
}
}
list<colorAndObject> carriersWithColors = new list<colorAndObject>();
在VisualForce页面中{!carriers}
,使用carriersWithColors
列表代替使用表值。
<apex:pageblocktable value="{!carriersWithColors }" var="c">
<apex:column headervalue="Carrier">
<font color="{!c.color}">
<apex:outputtext value="{!c.carrier.name}" />
</font>
</apex:column>
那应该足以让您入门。我让你填补空白。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句