rynmrtn
rynmrtn

Reputation: 3419

JSF Refresh without Ajax

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.

Upvotes: 0

Views: 780

Answers (1)

BalusC
BalusC

Reputation: 1108577

To ones with (limited) JS support, just let the dropdown submit the form by JS on change:

<h:selectOneMenu onchange="submit()">

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.

Upvotes: 3

Related Questions