• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TabPanel - Retain the current tab

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim, thanks a lot for your help. The explanation provided helped me resolve the issue.

 
This is awkward. I've grown a second evil head. I'm going to need a machete and a tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic