アプリケーションでprimefaces(v.3.0)データテーブルを使用しています。Datatableには2つの列があり、1つの列はinputtextで、もう1つの列はSelectOneMenu(ドロップダウン)です。
ここで、入力テキストの色を次のような場合に変更したいと思います。
1. SelectOneMenu値が「単一」として選択された場合、入力テキストボックスの色はその特定のpIDに対してのみ「緑」になります。
2. SelectOneMenu値が「既婚」として選択された場合、入力テキストボックスの色はその特定のpIDに対してのみ「赤」になります。
3. SelectOneMenu値が「離婚」として選択された場合、入力テキストボックスの色はその特定のpIDに対してのみ「黄色」になります。
だから私はこのようにしようとしています...
<h:form id="form">
<h:panelGrid columns="2" cellpadding="10" id="h">
<p:dataTable id="table" var="s"
value="#{backingBean.arrayList}"
widgetVar="empTable" rowKey="#{pt.pID}"
paginator="true" rows="15"
style="width: 100%;margin-bottom: 10px;" rowStyleClass="#{s.status}">
<f:facet name="header">
List of Patients Appointments
</f:facet>
<p:column headerText="Status" id="t">
<p:inputText value="#{s.status}" />
</p:column>
<p:column headerText="EmployeeAction">
<p:selectOneMenu id="scAction" value="#{backingBean.obj.empStatus}"
style="width:125px">
<f:selectItem itemLabel="Select" itemValue="" />
<f:selectItems value="#{schedulerBB.scheduleActionSelect}"
itemLabel="#{backingBean.obj.empStatus}"
itemValue="#{backingBean.obj.empStatusID}" />
<p:ajax event="change" listener="#{backingBean.changeColor(s)}" update=":form" />
</p:selectOneMenu>
</p:column>
</p:dataTable>
</h:panelGrid>
</h:form>
In CSS
.Single td:nth-child(1) input {
background-color: green;
}
.Married td:nth-child(1) input {
background-color: red;
}
.Divorced td:nth-child(1) input {
background-color: yellow;
}
In BackingBean:
private Employee obj;
//Getter setter methods
public Employee getObj() {
if(obj==null){
obj=new Employee();
}
return obj;
}
public void setObj(Employee obj) {
this.obj = obj;
}
public void changeColor(Employee e){
if(obj.getEmpStatus().equals("1")){
EmployeeDAO.updateEmpTable(e.getPID,e.getStatus);
}
css
.Single td:nth-child(1) input {
background-color: green;
}
.Married td:nth-child(1) input {
background-color: red;
}
.Divorced td:nth-child(1) input {
background-color: yellow;
}
その特定のpIDのselectonemenuを変更すると、入力テキストの値を変更できますが、ご覧のとおり、列レベルでinputtextboxの色変更ロジックを適用したため、すべての列のinputtextの色が変更されます。
では、入力テキストボックスの色を行レベルで変更するロジックをどのように適用できますか(つまり、特定のIDのみ)