I have a web application made in Netbeans 8.1
, Java 8
and Maven
First of all in my class Managed Bean Controller.java
place the label @ViewScope
. When I compiled and deployed the application I got the error
Severe: Exception while loading the app Serious: Undeployment failed for context / CustomerData1 Grave: Exception while loading the app: CDI deployment failure: WELD-000072: Bean declaring a passivating scope must be passivation capable. Bean: Managed Bean [class net.ensode.glassfish.jsfajax.Controller] with qualifiers [@Default @Any @Named] org.jboss.weld.exceptions.DeploymentException: WELD-000072: Bean declaring a passivating scope must be passivation capable. Bean: Managed Bean [class net.ensode.glassfish.jsfajax.Controller] with qualifiers [@Default @Any @Named]
So what I did was remove the label @ViewScoped
and the application compiled correctly and also the deploy but when I click on the command button
the method code calculateTotal
is not executed, it simply does not do any action. Does the @ViewScoped
tag have to be removed from the controller.java
code?
I also attach the xhtml file.
import javax.faces.event.ActionEvent;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
//@ViewScoped elimine esta etiqueta y el proyecto compilo y deploy ok.
@Named
public class Controller {
private String text;
private int firstOperand;
private int secondOperand;
private int total;
public Controller() {
}
public void calculateTotal(ActionEvent actionEvent) {
total = firstOperand + secondOperand;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public int getFirstOperand() {
return firstOperand;
}
public void setFirstOperand(int firstOperand) {
this.firstOperand = firstOperand;
}
public int getSecondOperand() {
return secondOperand;
}
public void setSecondOperand(int secondOperand) {
this.secondOperand = secondOperand;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
}
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>JSF Ajax Demo</title>
</h:head>
<h:body>
<h2>JSF Ajax Demo</h2>
<h:form>
<h:messages/>
<h:panelGrid columns="2">
<h:outputText value="Echo input:"/>
<h:inputText id="textInput" value="#{controller.text}">
<f:ajax render="textVal" event="keyup"/>
</h:inputText>
<h:outputText value="Echo output:"/>
<h:outputText id="textVal" value="#{controller.text}"/>
</h:panelGrid>
<hr/>
<h:panelGrid columns="2">
<h:panelGroup/>
<h:panelGroup/>
<h:outputText value="First Operand:"/>
<h:inputText id="first" value="#{controller.firstOperand}" size="3"/>
<h:outputText value="Second Operand:"/>
<h:inputText id="second" value="#{controller.secondOperand}" size="3"/>
<h:outputText value="Total:"/>
<h:outputText id="sum" value="#{controller.total}"/>
<h:commandButton actionListener="#{controller.calculateTotal}"
value="Calculate Sum">
<f:ajax execute="first second" render="sum"/>
</h:commandButton>
</h:panelGrid>
</h:form>
</h:body>
</html>
Thanks for your help.