• Post Reply Bookmark Topic Watch Topic
  • New Topic

myFaces Tabs and validation  RSS feed

 
J Haley
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a problem with myFaces tabs and can't find a solution. I have a page that imports two pages with the same data. The first tab is a read only page, and the second tab allows the user to edit fields. If the user is on the second page and gets an error they are sent back to the first tab. How do I put the user back on the tab they were editing?

 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MyFaces's tab component does expose a selectedIndex property (not every tab component out there does):

If you don't want to select a tab, have your method return null.

I was facing an even messier problem: error messages on multiple tabs. The headache was that, when a user clicks on a tab to expose it, there is a roundtrip to the server, but that trip doesn't attempt to update backing beans or validate input, so this roundtrip causes previously generated error messages to disappear! I eventually wrote code that explicitly found and held onto the error messages and reattached them so they won't disappear because of that roundtrip, but it was a hack.

Then I realized another problem. If the user skips over a tab, the controls on that tab are not generated (or something like that). If the user submits the form, empty required fields on a skipped-over tab will not not complain. In the end, I gave up in disgust.
 
J Haley
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad that selectedIndex is available. I'm new enough to JSF that I'm not clear when I would set aBean.selectedIndex. Can I do this when I click on the tab, or do I wait until the user submits the tab they are on? I assume the first scenario would be with script, but is that possible? I tried using the panelTab's onclick event, but it would never fire. Even the myFaces simple project would not execute the onclick event.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want the second tab to be selected (the tab with index 1 -- indexing starts at 0, right?) you can have that method bound to selected index property look for messages -- take a look at the API for FacesContext.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!