Tengo una aplicacion web hecha en Netbeans 8.1
, Java 8
y Maven
En primer lugar en mi clase Managed Bean Controller.java
coloque la etiqueta @ViewScope
. Cuando compile e hice el deploy de la aplicacion me aparecia el error
Grave: Exception while loading the app Grave: 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]
Así que lo que hice fue retirar la etiqueta @ViewScoped
y la aplicacion compilo correctamente y tambien el deploy pero cuando hago click en el command button
no se ejecuta el codigo del metodo calculateTotal
, simplemente no hace nunguna accion. ¿ Tiene que ver la etiqueta @ViewScoped
que elimine del codigo de controller.java
?
Tambien adjunto el archivo xhtml.
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>
Gracias por su ayuda.