Tapestry 5 - 两个组件之间的通信
我的 Java + Tapestry 5 应用程序中有一个页面,其中包含两个组件 - 表单和网格。表单字段用于过滤网格中显示的结果。该表单只是一个文本字段,用于设置它所映射到的对象 A 的值。网格是从对象 A 创建的。我需要将正确的实例从表单组件发送到网格组件。最好的方法是什么?我可以通过在上页中设置对象来使用普通的旧 java 方式来完成此操作,但应该有一种更干净的方式。我正在考虑环境注释,但这不是太重了吗?
public class I1 {
@Component
private WFRFormFilter wfrFormFilter;
@Component (parameters={ "wfrDataHolder=property:wfrFormFilter.wfrDataHolder" })
private WFRResultTable wfrResultTable;
}
public class WFRFormFilter {
@Inject
private WFRService wfrservice;
@Propperty
@Persist
private WFRDataHolder wfrDataHolder;
@PageAttached
void pageAttached() {
if (wfrDataHolder == null) {
wfrDataHolder = new WFRDataHolder();
}
}
@OnEvent(EventConstants.SUCCESS)
void processMyForm() { }
}
public class WFRResultTable {
@Parameter(defaultPrefix=BindingConstants.PROP)
@Property
private WFRDataHolder wfrDataHolder;
@Inject
private WFRService wfrservice;
public List<WFRDataHolder> getResultTableData() {
return wfrservice.getData(this.wfrDataHolder);
}
}
I have a page in my Java + Tapestry 5 application, which contains two components - a Form and a Grid. The form field is use to filter the results displayed in the grid. The form is just a textfield which sets the value of the object A on which it is mapped. The grid is created from the object A. I need to send the right instance to the grid component from the form component. What is the best way to do this? I could do it the plain old java way by setting the object in the upper page, but there should be an cleaner way. I was thinking about environment annotation, but isn't that too heavy?
public class I1 {
@Component
private WFRFormFilter wfrFormFilter;
@Component (parameters={ "wfrDataHolder=property:wfrFormFilter.wfrDataHolder" })
private WFRResultTable wfrResultTable;
}
public class WFRFormFilter {
@Inject
private WFRService wfrservice;
@Propperty
@Persist
private WFRDataHolder wfrDataHolder;
@PageAttached
void pageAttached() {
if (wfrDataHolder == null) {
wfrDataHolder = new WFRDataHolder();
}
}
@OnEvent(EventConstants.SUCCESS)
void processMyForm() { }
}
public class WFRResultTable {
@Parameter(defaultPrefix=BindingConstants.PROP)
@Property
private WFRDataHolder wfrDataHolder;
@Inject
private WFRService wfrservice;
public List<WFRDataHolder> getResultTableData() {
return wfrservice.getData(this.wfrDataHolder);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Tapestry 的参数是双向工作的:如果您将数据存储在页面类中(使用
@Persist
)并将其作为参数传递给表单组件,则可以在表单组件中更改其值,并且这将自动反映到您的页面:无需调用设置器。因此,如果您的页面和表单组件的布局如下:
...那么正确的值将始终出现在页面中,因此也出现在网格组件上。
另请参阅 Tapestry 文档中的 组件参数页面,特别是“参数是双向的”部分定向”。
Tapestry's parameters work bi-directionally: If you store your data in your page class (with
@Persist
) and pass it to your form component as a parameter, you can change its value in the form component, and that will be reflected to you page automatically: no calls to setters required.So if you have your page and form component laid out like this:
...then the proper value will always be present in the page, and thus also on the grid component.
Also see the Component Parameters page in the Tapestry docs, particularly the section "Parameters are Bi-Directional".