Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

h:selectOneListbox - causing navigation to fail

 
Ayan Afridi
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have come across a peculiar problem that probably has to do with the JSF lifecycle. Someone here might have some more insight.

I have an update detail page which is updating to a table. In this page, there is a selectOneListBox, whose value is set by a function called getFlowClassification(). What this does is resolve a key to a name, because in the list box there are names, not keys. So for example:

<h:selectOneListbox id="listbox2" value="#{flowFactAction.flowFactBean.flowProductName}" >
<f:selectItems value="#{flowFactAction.adjustmentsInit.flowProducts}"/>
</h:selectOneListbox>

The list returned by "flowProducts" comtains Names, not keys, so that is why I need this function, so the selectOneListBox can have the correct name picked when entering this page.

This works fine - the problem is when I add a navigation button or link to go back to the list of items. ie:

<h:commandLink id="link1" action="#{flowFactAction.cancelUpdateMappingDetail}">
<hutputText id="text6" value="BACK TO LIST"></hutputText>
</h:commandLink>

When I click this link, it just brings me back to this current detail page, and doesnt bring me back to the datatable listing. If I remove the "value="#{flowFactAction.flowFactBean.flowProductName}" " from the selectOneListBox, voila - problem solved, and I can return to the list. But I need to have the value selected upon entry into the page.

Any idea what the hay is goin on?

-Ayan
 
Sergey Smirnov
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most often, an undefined converter causes such problem, but not always.
First of all, try to determine the problem putting <h:messages /> somewhere on the page. If conversion problem exists, the message should be shown.
If nothing is shown try to understand on which phase the lifecicle is broken. You can do it phase listener tracker. Take the ready-to-use one from:
http://www.jsftutorials.net/faces-config/phaseTracker.html
The next steps should depends of the phase.
 
Ayan Afridi
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have a solution as to why I was experiencing this behavior, but I have achieved what I was looking for.

Basically I needed a list item to resolve to a key/id, and a key/id to resolve to a list item. I was unaware that the "SelectItem" class allows this functionality by its construction: new SelectItem(key, label)
So if you assign the value of the selectOneMen as the key, in the detail, the correct label will be highlighted, and upon save, the correct key will be saved.

-Ayan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic