Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

TabPanel - Retain the current tab  RSS feed

 
Astria Bothello
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have an issue to retain the current tab when an error occurs.

We have a requirement - When the user clicks on another tab - if there is any change in the current tab data - a message should be displayed saying 'You have unsaved data'

We have valueChangeListener event for the tabPanel - which captures the selectedTab.
We are able to display the message however the control does not stay in the current tab. It goes to the selected Tab after displaying the error.

The backing bean has a selectedTab attribute which is mapped to the rich TabPanel selectedTab property.

How can we force the control to be on the current tab - even though the user has clicked on the new tab?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Astria!

Just to clarify one thing, because a lot of people don't understand it: I trust you are aware that valueChangeListeners are not asynchronous event processors?

A valueChangeListener only fires when an HTTP request is made, and when the new value has passed validation. The only way to actually trigger a valueChangeEvent short of using a commandButton or commandLink is if you tie AJAX to the control whose value is changing. Or at least to something.

If you provide an action method (please don't use an actionListener!) on the submitting event, that action method will be invoked after all the validators have approved the data, the valueChangeListeners have fired, and the Model has been updated from the View. That action method can do whatever checks it wants to do above and beyond what the validators did, post error messages to JSF, and then select the new tab or return to the old one. Of course, it can also do the data save operation while it's at it.
 
Astria Bothello
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Tim.

The valueChangeListener of the tabPanel calls the following


public void tabChange(ValueChangeEvent vce) {

if (this.retainTab!=null) {
this.tabSaveFlag = true;
ValidationUtil.addFacesMessage((ValidationUtil.resourceBundle.getString(ValidationConstants.TAB_SAVE)));
setShowMainErrorPanel(true);
this.selectedTab=retainTab;
} else
setShowMainErrorPanel(false);
}

However I cannot get the control to remain in the current tab.
Appreciate your assistance
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe JSF is updating the selectedTab after you updated it. Remember, the lifecycle is validate, changelistener, update, action. So the place you really should update the tab is in the action, not the listener. valueChangeListeners are very constrained about what they can update and should never be used to actually update the model itself, although they're good places to update the model's context. For example, if I have 2 droplists and one depends on the other, I'll use the listener on the parent control to set a flag telling the later stages to refresh the dropdown list on the child control.

So, something like this:
 
Astria Bothello
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, thanks a lot for your help. The explanation provided helped me resolve the issue.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!