Kamis, 23 Januari 2014

Restore tabbedpanel


Maintain the tab selection after form submission


The IBM JSF version as is in Websphere Studio Application Developer 5.x doesn't return to the tab selected after submitting a form in a certain tab of the odc:tabbedPanel, while the IBM JSF version as is in WSAD 6.x does. This practice describes the javascript hack for IBM JSF in WSAD 5.x to maintain the tab selected after a form submission.



Use Javascript


The trick is to put boolean getter methods in the backing bean and handle the tab selection using Javascript. The boolean getter methods should return true if the appropriate form has been submitted before. All ODC elements are stored in the Javascript ODCRegistry object, you can retrieve the ODC element as object using getClientControl(). With the restoreUIState() function you can set the tab selection state. It is important that the managed bean has a session scope instead of a request scope. Otherwise, the data of the managed bean (vars, state, etc) will be garbaged directly after one request.


The relevant XML code of the faces-config file:




myBean
mypackage.MyBean
session


The basic JSF code example for the JSP file:




id="scriptCollector1">
...
id="tabbedPanel1">
id="bfpanelForm1">
id="form1">
...
value="submit" action="#{myBean.submitForm1}" />


id="bfpanelForm2">
id="form2">
...
value="submit" action="#{myBean.submitForm2}" />


...

...






Note: in JSF 1.2 those f:verbatim tags aren't needed however.


It is important that the Javascript is executed after the hx:scriptCollector part, otherwise the panel state will be overriden by the default value.


The relevant java code of the backing bean MyBean.java should look like:



package mypackage;

public class MyBean {

// Init --------------------------------------------------------------------------------------

private int submittedForm;

// Actions -----------------------------------------------------------------------------------

public void submitForm1() {
// Do your action thing for form1.
...
submittedForm = 1;
}

public void submitForm2() {
// Do your action thing for form2.
...
submittedForm = 2;
}

// Getters -----------------------------------------------------------------------------------

public int getSubmittedForm() {
return submittedForm;
}

}



Copyright - There is no copyright on the code. You can copy, change and distribute it freely. Just mentioning this site should be fair.


(C) May 2006, BalusC



Source:http://balusc.blogspot.com/2006/05/restore-tabbedpanel.html

Tidak ada komentar:

Posting Komentar