Inconsistent deployment of JSF ViewScoped CDI Bean accross two GF Servers
I'm working on an application comprising of mostly SessionScoped CDI beans with one ViewScoped CDI bean. I'm using 2 GF4 servers (test and production).
This bean applies filters on a Primefaces DataTable:
@Named(value = "filterBean")
@ViewScoped
public class FilterBean {
private List<Clientactions> filterDept;
public FilterBean() {
}
public List<Clientactions> getFilterDept() {
return filterDept;
}
public List<Clientactions> getFilterDept() {
return filterDept;
}
public void setFilterDept(List<Clientactions> filterDept) {
this.filterDept = filterDept;
}
// rest of bean code
This bean handles the main CRUD operations on the entities:
@Named(value = "actionBean")
@SessionScoped
public class ActionBean implements Serializable {
public stDataModel<Clientactions> getActionList() {
if (actionList == null) {
actionList = makeActionList();
}
return actionList;
}
public ListDataModel<Clientactions> makeActionList() {
List<Clientactions> caList = facade.findAll();
ListDataModel<Clientactions> model
= new ListDataModel<Clientactions>(caList);
return model;
}
// rest of bean code
These two beans are used in the following JSF DataTable:
<p:dataTable id="actiontable" value="#{actionBean.actionList}" var="actions"
styleClass="borderless" filteredValue="#{filterBean.filterDept}" widgetVar="masterTable"
emptyMessage="No records with given criteria found">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter" onkeyup="PF('masterTable').filter()"
style="width:150px" placeholder="Enter
</p:outputPanel>
</f:facet>
Deploying the application in my test server works perfectly. Deploying it in the production server results in:
015-08-06T08:45:49.183-0700] [glassfish 4.1] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=42 _ThreadName=admin-listener(3)] [timeMillis: 1438875949183] [levelValue: 1000] [[
Exception while loading the app : CDI deployment failure:WELD-000072: Bean declaring a passivating scope must be passivation capable. Bean: Managed Bean [class com.mantramods.ion.beans.FilterBean] with qualifiers [@Default @Named @Any]
org.jboss.weld.exceptions.DeploymentException: WELD-000072: Bean declaring a passivating scope must be passivation capable. Bean: Managed Bean [class com.mantramods.ion.beans.FilterBean] with qualifiers [@Default @Named @Any]
Implementing Serializable to the FilterBean fixes the deployment issue but the resulting DataTable is blank and the main ActionBean then becomes unreachable. I also deleted in the OSGI cache on the production server but this did not solve the problem.
I'm confused about ViewScoped beans in CDI. My research suggests that it is not recommended to use ViewScoped in CDI as this is a JSF standard. I"ve since been enlightened by BalusC that JSF2.2 provides out of the box ViewScoped for CDI.
Doing further research on my exception revealed that the exception is fixed by implementing Serializable. When I implement Serializable, however, the application becomes unstable and I get 'Target unreachable identifier. This time the exception is on the main actionBean which resolves to null' when trying to do any CRUD on the DataTable.
I tried using RequestScoped and ConversationScoped but this resulted in similar behavior. I suspect my problem has to do with the fact that the two beans are used to process the same DataTable and conflict when FilterBean implements Serializable. In this case I'm not sure how to treat the scope of the FilterBean. I just know the main ActionBean should remain SessionScoped.
I can't see any immediate rules I'm breaking for CDI beans so I then tried to do FilterBean as a JSF bean:
@ManagedBean (name = 'filterBean')
@ViewScoped
public class FilterBean {
....
...
}
Exactly the same behavior! My questions:
1) The concept - How can ViewScope requirenments be handled in CDI? 2) The concrete problem - Why am i able to successfully deploy in one server but not the other? 3) Since ViewScoped is available for CDI, can ViewScoped beans function without Serializable?
Before I start to think about this as a possible Glassfish problem I want to make sure I'm doing things right as far as JSF goes.
Thank you!
链接地址: http://www.djcxy.com/p/62214.html上一篇: Servlet和CDI bean的范围