I am using primefaces 5.1, jsf 2.2 (Mojarra), spring 4.1.6, prettyfaces 2.3.3. I have a xhmtl which contains a tabview with more than one tab and spring managed view scope bean (viewBean). The issue is values of the page (view.xhmtl) and that of zeroth tab is displayed. but the rest of the data in remaining tabs is not being displayed.ie, the value in New Deals tab is not being displayed.
When newDeals object of viewBean is made static, the value gets displayed.
I went through jsf viewscoped bean - set values for every page(tabs), Using JSF with multiple tabs in one browser, and would like to know if what i understood from the above links is correct. ie, we have to use session scope for a bean or page having multiple tabs in a view xhtml??
The project is uses prettyfaces for redirection.
Update
In http://balusc.blogspot.in/2011/09/communication-in-jsf-20.html#ManagedBeanScopes, it is mentioned that
@ViewScoped: a bean in this scope lives as long as you're interacting with the same JSF view in the browser window/tab. It get created upon a HTTP request and get destroyed once you postback to a different view.
So how come the (1st to last) tab's data is not loaded in a page consisting of a tabview (with multiple tabs) while the 0th tab's data is loaded?
Code is as belows
List.xhmtl
<p:dataScroller value="#{listBean.pdtVOList}" var="pdt">
<p:commandLink value="#{pdt.name}" action="#{viewBean.viewPdtFrmList(pdt.id)}" ></p:commandLink>
</p:dataScroller>
ListBean
@Scope("view")
@Component
public class ListBean implements Serializable {
private List<Product> pdtVOList; //include getters and setters
public void fillPage() {
pdtVOList = ownerService.fillProductList(); //gets all product from db
}
}
viewBean is
@Component
@Scope("view")
public class ViewBean implements Serializable {
private static Product pdt = new Product();
private NewDeals newDeals = new NewDeals();
//include getter and setters
public void fillPage() {
//is Empty
}
public void viewPdtFrmList(String pdtIdStr) {
pdt = new Product();
//set pdt values
setPdt(getPdtValuesFromDB(pdtIdStr));
newDeals = pdtRepository.getNewDealsCOmbo();
FacesContext.getCurrentInstance().getExternalContext()
.redirect("/pdt/view");
}
public getPdtValuesFromDB(String pdtIdStr) {
//get values from database
pdt = pdtRepository.getValuesFromDB(Integer.parseInt(pdtIdStr));
}
}
Product Model
private int id;
private String name; //Include getter and setter
pdtView.xhtml
<h:outputText value="#{viewBean.pdt.id}"/>
<h:outputText value="#{viewBean.pdt.name}"/>
<p:tabView id="tabview" style="width:100%;float:right;">
<p:tab id="clientPricing" title=" Pricing">
<h:outputText value="#{viewBean.pdt.price}"/>
</p:tab>
<p:tab title="New Deals">
<h:outputText value="#{viewBean.newDeals.name}"/>
</p:tab>
</p:tabView>
prettyconfig.xml
<url-mapping id="ownerandpetsview">
<pattern value="/pdt/view" />
<view-id value="/WEB-INF/views/pdtView.xhtml" />
</url-mapping>
web.xml
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
web.xml
<context-param>
<param-name>javax.faces.STATE_SAVING</param-name>
<param-value>true</param-value>
</context-param
newDeals
is instantiated again. – vels4j