<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