Revisiting the topic : Programmatically disclosing a ShowDetailItem in a <af:panelTabbed>

Sometime back I blogged about Programmatically disclosing a ShowDetailItem in a <af:panelTabbed>. In today's post I'm revisiting this topic to address the same usecase for applications with customization(change persistence) ON. If the customization is enabled you may need to use appropriate ChangeManager APIs for persisting the changes that you do programmatically. Otherwise during rendering  ChangeManager will override your programmatic changes with the state for the component that is persisted in the change manger during the last user interaction. So the code snippet posted in my previous blog post needs to have following ChangeManager APIs as well to make this working for an application that use "Change Persistence/Customization". The precious post has the full code sample. For a complete working sample, you need to change displaySelectedItem(...) given in the last post's sample with the code snippet given below.

import org.apache.myfaces.trinidad.change.AttributeComponentChange;
import org.apache.myfaces.trinidad.change.ChangeManager;
import org.apache.myfaces.trinidad.change.ComponentChange;
import org.apache.myfaces.trinidad.context.RequestContext;
//Other imports...

public class TestBean {
public void displaySelectedItem(ActionEvent actionEvent) {
 RichPanelTabbed richPanelTabbed = getPanelTabbed();
 for (UIComponent child : richPanelTabbed.getChildren()) {
   RichShowDetailItem sdi = (RichShowDetailItem) child;
   boolean isDisclosed = isThisItemToBeDisclosed(sdi);
   sdi.setDisclosed(isDisclosed);
   if (isDisclosed) {
     ChangeManager cm = RequestContext.getCurrentInstance().
        getChangeManager();
     ComponentChange cc = new AttributeComponentChange(
        "disclosed",true);
     cm.addComponentChange(FacesContext.getCurrentInstance(),
        sdi, cc);
   } else {
     ChangeManager cm = RequestContext.getCurrentInstance().
        getChangeManager();
     ComponentChange cc = new AttributeComponentChange(
        "disclosed", false);
     cm.addComponentChange(FacesContext.getCurrentInstance(), 
       sdi, cc);
   }
  }
 }

//Other methods........
}


Download

You can download the modified sample workspace from here.
[Runs with Oracle JDeveloper  12C 12.1.2.0.0 ]

How to run this sample?

Run the test.jspx. This page displays drop down list displaying the tab names and a button close to it for disclosing  the selected tab programmatically.

Comments

Hitesh Patel said…
WOW...great post...thanks a lot. It has fixed my issue.
Anand Yerrapati said…
Jobinesh, thanks for the post. It helped me a lot to fix my issue.
Jobinesh, brilliant sample, which solved my tab refresh issue... Thanks and well done mate.

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.