多阶段形式策略
目前,我正在构建一个页面,用于输入我公司处理的不同产品的定价数据。定价数据有些复杂,因此根据输入新数据的项目需要不同的表格。现在我处理这个问题的策略是将页面拆分为多个表单,并在输入有效数据时触发下一阶段的 AJAX 更新。每个表单都包含一个 ui:include ,它指向控制器 bean 上的一个方法,该方法返回一个指向 xhtml 片段的字符串,其中包含先前输入的数据的适当表单结构。
<form id="stageOne"> Some content that triggers an ajax update of stageTwo </form>
<form id="stageTwo"> <ui:include src="#{controller.getStageTwo()"> </form>
和支持 bean 方法:
public String getStageTwo() {
switch (stageOneContent) {
case 1: return "/context-root/snippetName.xhtml";
case 2: return "/context-root/snippetName2.xhtml";
}
}
这个解决方案对我来说感觉有些错误,特别是让控制器方法负责了解调用页面可能使用的所有 xhtml 片段的确切位置。我还是个比较新的人,感觉我可能错过了一些东西。有没有更好的方法来处理这种情况?
Currently I'm working on building a page for inputting pricing data for different products my company handles. Pricing data is somewhat complicated, and so different forms are needed depending on what item new data is being entered for. Right now my strategy for dealing with this is to split the page into multiple forms, with an AJAX update on the next stage triggered when valid data is entered. Each form contains a ui:include pointed to a method on a controller bean, which returns a string pointing to a xhtml snippet with the appropriate form structure for the previously entered data.
<form id="stageOne"> Some content that triggers an ajax update of stageTwo </form>
<form id="stageTwo"> <ui:include src="#{controller.getStageTwo()"> </form>
And the backing bean method:
public String getStageTwo() {
switch (stageOneContent) {
case 1: return "/context-root/snippetName.xhtml";
case 2: return "/context-root/snippetName2.xhtml";
}
}
This solution feels somehow wrong to me, particularly having the controller method be responsible for knowing the exact location of all the xhtml snippets the calling page might use. I am still relatively new, and feel like I might be missing something. Is there a better way to handle this scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就这样怎么样?
您只需将
snippetName.xhtml
重命名为snippetName1.xhtml
。How about just something like this?
You only need to rename
snippetName.xhtml
tosnippetName1.xhtml
.