我想创建一个方法,允许我通过一个带有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