David,

Thanks for the response.

Your selectone bean is request scope. The list of items is populated
only during your first action. That mean when user select an item and
submit the form, the bean is recreated (request scope) with an empty
list (your own initalization code) and jsf can not find a selectItem
corresponding to the one you have choosen.

Suppose that we are using Struts or WebWork to handle this scenario.
In our showItems action we populate the list, then render the result
to the browser. The user selects one of the items and submits the
form. In Struts or WebWork, this simply sets the selectedItemId and
continues to the next page. Why does JSF mandates to ensure that the
selected item is in the list? If I really needed to assure that the
selected item is still in the database before proceeding any further,
I could do this in the selectItem action method more efficiently.
Actually if this loss of performance was due to gains in productivity,
that wouldn't be a problem. But I can't see a productivity gain here.

Actually, if I had constructed the menu programatically like this:

   List<SelectItem> selectItems = new ArrayList<SelectItem>();

   Database d = new Database();
   List<Item> items = d.findAllItems();
   for (Item i : items) {
     SelectItem si = new SelectItem(i.getId(), i.getName());
     selectItems.add(si);
   }

   UISelectItems uiSelectItems = new UISelectItems();
   uiSelectItems.setValue(selectItems);

   selectOneMenu = (HtmlSelectOneMenu)
FacesContext.getCurrentInstance().getApplication().createComponent(HtmlSelectOneMenu.COMPONENT_TYPE);
   selectOneMenu.getChildren().add(uiSelectItems);

this check wouldn't be a problem because it wouldn't lead to another
round-trip to the database, as the select items could be restored
during the restore view phase.

Today I stepped into the MyFaces source code to see how things are
being done. I found out that during the Render Response phase, the
value bindings are executed to render the view, i.e.
#{SelectOneMenuBean.selectItems} is executed during the Render
Response phase.

Then, again, when I submit the form, #{SelectOneMenuBean.selectItems}
is at least executed once again, in the decode method of the
HtmlSelectOneMenu. I think it would be better that we had cached the
value of #{SelectOneMenuBean.selectItems} during Render Response and
just reused those entries during the decode process, although I might
be missing something fundamental here.

Just for the sake of curiosity, do you know if this check to ensure
that the selected item is still in the list, is also performed in
ASP.NET?


Thanks in advance,
Behi

--
"Science is a differential equation. Religion is a boundary condition"
- Alan Turing

Behrang Saeedzadeh
http://www.jroller.com/page/behrangsa
http://my.opera.com/behrangsa

Reply via email to