【发布时间】:2016-04-25 13:59:22
【问题描述】:
<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 Ya 这可能是可能的,我只是想在这里解释问题。
标签: jsf primefaces