Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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: 24330
167
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: 24330
167
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.

 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic