<p:dataTable value=”#{myBean.myList}” var=”item”>
<h:outputText id=”mytext” value=”#{item.valueText}”/>
</p:dataTable>
//Item class
Class Item
{
String valueText;
Item(String valueText)
{
this.valueText = valueText;
}
}
//myList has 5 elements.
Item(“red”);
Item(“orange”);
Item(“yellow”);
Item(“green”);
Item(“blue”);`
//Button
<p:commandButton value=’submit’ actionListener=”#{myBean.checkColor}” update=”myText”/>` // This will update all the five texts.
//MyBean Class
Class MyBean
{
List<Item> myList;
public void checkColor()
{
Iterator itr = myList.iterator();
while(itr.hasNext())
{
Item item = itr.getNext();
if(item.getValueText().contains(‘r’))
{
item.setValueText(“Invalid Color”);
}
}
}
}
The above code will execute update on all 5 texts on click of the button though it will change the text only for texts containing letter 'r' so rest of two updates are just waste. But i want to update only texts having letter 'r' in them to 'Invalid Color'. How can i do that?