<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”);
}
}
}
}
的点击元素上面的代码将在所有5个文本执行按钮的点击更新,虽然它会改变文本只含有字母“R”这样两个更新的其余的都是文本只是浪费。 但我想只更新其中有字母'r'的文字为'无效颜色'。我怎样才能做到这一点?动态/选择性地更新按钮
Java代码无法编译。 – Unknown
@未知雅可能是可能的,我只是试图解释这里的问题。 – nikhilsuri