rich:panelBar save state (selectedPanel)
aland Mar 10, 2008 10:02 AMI have a problem saving the state of the panelBar component. I like to have the same panelBarItem opened between request.
The following code shows my problem.
A fragment of my page containing the panelBar component.
<a4j:form> <rich:panelBar selectedPanel="#{menuState.selectedPanelBar}" valueChangeListener="#{menuState.panelBarChanged}"> <a4j:support event="onclick" /> <rich:panelBarItem name="fooPanel"> Foo </rich:panelBarItem> <rich:panelBarItem name="barPanel"> Bar </rich:panelBarItem> </rich:panelBar> </a4j:form>
A session scoped bean to remember the selectPanelBar
@Name("menuState") @Scope(value = ScopeType.SESSION) public class MenuState implements Serializable { @Logger private Log log; @In private FacesContext facesContext; private String selectedPanelBar = "barPanel"; public void panelBarChanged(final ValueChangeEvent evt) { log.debug("Got a value changed event, new value: #0, old value #1", evt.getNewValue(), evt.getOldValue()); UIPanelBarItem barItem = (UIPanelBarItem) facesContext.getViewRoot().findComponent(evt.getNewValue().toString()); UIPanelBar panelBar = barItem.getPanel(); log.debug("selected panelBar: #0", panelBar.getSelectedPanel()); log.debug("submittedValue #0", panelBar.getSubmittedValue()); log.debug("value: #0", panelBar.getValue()); String name = (String) barItem.getName(); log.debug("name: #0", name); } public String getSelectedPanelBar() { return selectedPanelBar; } public void setSelectedPanelBar(final String selectedPanelBar) { this.selectedPanelBar = selectedPanelBar; } }
The result of running this code is that intial the barPanel is opened, as expected. When the user clicks on the fooPanel the panel is opened but the new value of the valueChanged event is the previous panel and the old value is null.
First the setter is called with the previous selectedTabPanel name. Thus: barPanel. After that the valueChangeListener. The resulting name is also the previous tab before the user selected a new tab.
Can somebody explain this? Is there another way to keep hold of the selectedPanel?
I am using Richfaces 3.1.4, Jboss 4.2.0 and SEAM 1.2.1