Tapestry 5 将操作添加到选择菜单
我正在尝试向我的挂毯选择菜单添加一个操作。我目前正在通过注入 selectModelFactory 并为其提供来自休眠查询的列表来生成选择菜单。然后,我想在菜单中提供一个附加项目,当给定的选项未提供所需的选择时,该项目会显示“+ 添加新项目”之类的内容。当选择+添加新项目时,我尝试使用 onValueChanged 方法来捕获新对象并返回一个区域。我一直无法完成这项工作。有人能指出我正确的方向吗?我还需要防止该对象被提交到数据库中,这使我相信我不应该将其添加到现有列表中。
void onPrepare() {
List<MyClass> results = session.createCriteria(MyClass.class).list();
MyClass tempObject = new MyClass();
tempObject .setName("+ Add New Item");
results.add(tempObject);
selectModel = selectModelFactory.create(results, "label");
}
public Object onValueChanged(MyClass myClass) {
if(myClass!= null && myClass.getName().equals("+ Add New Item")) {
return myZone.getBody();
}
return null;
}
I'm trying to add an action to my tapestry select menu. I'm currently generating the select menu by injecting selectModelFactory and providing it with a list from a hibernate query. I then want to provide an additional item to the menu that says something like "+ Add New Item" when the given choices do not present the desired choice. When selecting + Add New Item, I tried using the onValueChanged method to capture the new object and return a zone. I have been unable to make this work. Could someone point me in the right direction. I need to prevent this object from being commited to the database as well which leads me to believe I should not be adding it to the existing list.
void onPrepare() {
List<MyClass> results = session.createCriteria(MyClass.class).list();
MyClass tempObject = new MyClass();
tempObject .setName("+ Add New Item");
results.add(tempObject);
selectModel = selectModelFactory.create(results, "label");
}
public Object onValueChanged(MyClass myClass) {
if(myClass!= null && myClass.getName().equals("+ Add New Item")) {
return myZone.getBody();
}
return null;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下这个工作示例。您的事件处理方法的命名不正确,应为
onValueChangedNameOfYourSelect(MyClass value)
。或者我更喜欢使用的是 OnEvent注解。Have a look at this working example. The naming of your event handing method is not correct and should be
onValueChangedNameOfYourSelect(MyClass value)
. Or what I prefer to use is the OnEvent annotation.您好,请参阅nabble http://tapestry.1045711.n5.nabble.com/T5-Select-Menu-with-Other-Option-td4520881.html#a4529383 邮件列表进行讨论。以下最终是解决方案,但是阻止保存“其他”选择会带来其他复杂性。
Hello see nabble http://tapestry.1045711.n5.nabble.com/T5-Select-Menu-with-Other-Option-td4520881.html#a4529383 mailing list for discussion. The following ended up being the solution, however preventing the "Other" choice from being saved presented other complexities.