我想創建一個方法,允許我通過一個帶有inputText字段的JSF頁面進行搜索。我打算從位於託管bean中的數組列表中獲取一個或多個條目,並在我點擊提交後將其顯示在JSF頁面上。 我試圖從這個問題中汲取靈感,但在創建搜索方法我堅持,因爲我在Java中的新手: JSF2 search boxArrayList的JSF2搜索方法
在我的JSF頁面,我打算有這樣的事情,「東西」是方法我失蹤:
<h:form>
<h:inputText id="search" value="#{order.something}">
<f:ajax execute="search" render="output" event="blur" />
</h:inputText>
<h2>
<h:outputText id="output" value="#{order.something}" />
</h2>
</h:form>
在我的java文件,我有以下的ArrayList 'orderList',我只是使用字符串:
private static final ArrayList<Order> orderList =
new ArrayList<Order>(Arrays.asList(
new Order("First", "Table", "description here"),
new Order("Second", "Chair", "2nd description here"),
new Order("Third", "Fridge", "3rd description here"),
new Order("Fourth", "Carpet", "4th description here"),
new Order("Fifth", "Stuff", "5th description here")
));
希望這是足夠的信息。 我想我必須從頭開始製作一些全新的方法,但我一分鐘也沒有太多。 我會怎樣把它們綁在一起?任何指針將不勝感激:)
〜編輯〜 這裏是我的訂單對象供參考,我假設我在這裏使用一個getters?
public static class Order{
String thingNo;
String thingName;
String thingInfo;
public Order(String thingNo, String thingName, String thingInfo) {
this.thingNo = thingNo;
this.thingName = thingName;
this.thingInfo = thingInfo;
}
public String getThingNo() {return thingNo;}
public void setThingNo(String thingNo) {this.thingNo = thingNo;}
public String getThingName() {return thingName;}
public void setThingName(String thingName) {this.thingName = thingName;}
public String getThingInfo() {return thingInfo;}
public void setThingInfo(String thingInfo) {this.thingInfo = thingInfo;}
}
謝謝,我相信這會幫助我很多。那麼我只有三個字符串的getter和setter:thingNo; thingName;和thingInfo ;. – Froob 2012-08-10 15:02:38
不明白setSelectedOrder,即使我導入java.lang,netbeans也不能識別長度。字符串 – Froob 2012-08-10 18:03:12
對不起,這是因爲我現在在跳躍語言,它的方法調用search.length(),而不是屬性(長度)。 Netbeans和eclipse都有很好的功能來提供修復。如果我記得(我可能沒有),Netbeans是ALT-ENTER,並且eclipse是用於修復的ctrl-space/ctrl-1。上面的代碼更多的是一個草圖而不是工作代碼。 – 2012-08-10 18:32:59