不使用 Ajax 的 JSF 刷新
我正在开发一个使用 JSF 1.2 作为视图层的 Web 应用程序。过去,我们已经能够使用 Ajax 来刷新页面的部分内容。然而,我们被要求支持 Blackberry 设备,包括 BB OS 5.x。该设备的默认浏览器对 JS 支持非常有限。
例如,假设我有一个带有选项(水果、肉类、蔬菜)的初始分类列表,
<h:selectOneMenu id="foodCategorySelection" value="#{obj.foodCategory}">
<f:selectItem itemLabel="Select Food Category..." />
<f:selectItems value="#{foodService.foodCategories}" />
</h:selectOneMenu>
我想做的是能够刷新页面,以便下一个选择字段仅显示所选食物类别中的
<h:selectOneMenu id="foodSelection" value="#{obj.food}">
<f:selectItem itemLabel="Select a Food..." />
<f:selectItems value="#{foodService.filteredFoods}" />
</h:selectOneMenu>
食物有一个通用的模式可以用来完成这项工作吗?我假设必须以某种方式提交表单,以便在刷新食物选项之前将食物类别绑定到支持对象。
I am developing a web application that uses JSF 1.2 for the view layer. In the past, we have been able to use Ajax to refresh portions of a page. However, we have been given the requirement to support Blackberry devices including BB OS 5.x. The default browser for this device has very limited JS support.
For example, let's say I have an initial categorical list with options (Fruit, Meat, Vegetables)
<h:selectOneMenu id="foodCategorySelection" value="#{obj.foodCategory}">
<f:selectItem itemLabel="Select Food Category..." />
<f:selectItems value="#{foodService.foodCategories}" />
</h:selectOneMenu>
What I would like to do is be able to have the page refresh so that the next selection field only displays the foods in the selected food category
<h:selectOneMenu id="foodSelection" value="#{obj.food}">
<f:selectItem itemLabel="Select a Food..." />
<f:selectItems value="#{foodService.filteredFoods}" />
</h:selectOneMenu>
Is there a common pattern that can be used to make this work? I assume that the form has to be submitted somehow in order to bind the food category to the backing object before refreshing the food options.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于具有(有限)JS 支持的人,只需让下拉列表在更改时通过 JS 提交表单即可:
在 bean 中,根据第一个下拉列表提交的值填充第二个下拉列表。您可以在附加到第一个下拉列表的
valueChangeListener
方法中执行此操作。对于没有任何 JS 支持的用户,请在第一个下拉列表旁边添加一个提交按钮,以便最终用户可以在第一个下拉列表中选择值后手动提交表单。您填充附加到提交按钮的 bean 操作方法中的第二个下拉列表。
To ones with (limited) JS support, just let the dropdown submit the form by JS on change:
In the bean, populate the 2nd dropdown based on the submitted value of the 1st dropdown. You could do this in a
valueChangeListener
method which is attached to the 1st dropdown.To ones without any JS support, add a submit button next to the 1st dropdown so that the enduser can manually submit the form after selecting a value in the 1st dropdown. You populate the 2nd dropdown in the bean action method which is attached to the submit button.