Ae pessoal, estou com problemas ao utilizar o evento onComplete no JSF 2.0. Criei um app simples para demonstrar tal questão. Estou utilizando o componente Primefaces versão 2.0.1, e a tag p:commandButton possui esse evento. Porém o mesmo não se comporta da mesma maneira que o <a4j:support onComplete="" /> existente na versão 1.2 do JSF. O problema é o seguinte. Ao disparar uma action, o evento onComplete recebe uma string do Managed Bean, como no exemplo abaixo, exibindo um alert. Só que nesse caso, o alert não está sendo exibido, apenas se eu colocá-lo diretamente no evento onComplete da tag do p:commandButton. Mas ai nesse caso, o alert é exibido mesmo quando os campos não estão preenchidos, verificado atraves do required dos inputs. Quem puder me ajudar, fica aí o desafio, seguem os códigos abaixo:
Página index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Teste</title>
</h:head>
<h:body>
<h:form>
<p:panel style="margin-top: 200px; margin-left: 500px; width: 300px;">
<f:facet name="header">
<h:outputText value="Teste de Soma" />
</f:facet>
<h:panelGrid id="pgrTotal" columns="2">
<h:outputText id="optValor1" value="Valor 1:" />
<h:inputText id="iptValor1" size="30" maxlength="20" value="#{bean.valor1}"
required="true" requiredMessage="Informe o primeiro valor" />
<h:inputHidden />
<h:message for="iptValor1" styleClass="fonteAlerta" showDetail="true" showSummary="false" />
<h:outputText id="optValor2" value="Valor 2:" />
<h:inputText id="iptValor2" size="30" maxlength="20" value="#{bean.valor2}"
required="true" requiredMessage="Informe o segundo valor" />
<h:inputHidden />
<h:message for="iptValor2" showDetail="true" showSummary="false" />
<h:outputText value="Soma:" />
<h:outputText id="optTotal" value="#{beanController.total}" />
</h:panelGrid>
<f:facet name="footer">
<p:commandButton id="btnSomar" value="Somar" action="#{beanController.realizaSoma}"
update="pgrTotal" oncomplete="#{beanController.mensagem}" />
<h:outputText value=" " />
<h:commandButton value="Limpar" immediate="true" type="reset" />
</f:facet>
</p:panel>
</h:form>
</h:body>
</html>
Bean:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
/**
*
* @author Lessandro
*/
@ManagedBean(name = "bean")
@RequestScoped
public class Bean {
private double valor1, valor2;
public double getValor1() {
return valor1;
}
public void setValor1(double valor1) {
this.valor1 = valor1;
}
public double getValor2() {
return valor2;
}
public void setValor2(double valor2) {
this.valor2 = valor2;
}
}
Managed Bean:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
/**
*
* @author Lessandro
*/
@ManagedBean(name = "beanController")
@SessionScoped
public class BeanController {
private double total;
private String mensagem;
public void realizaSoma() {
FacesContext facesContext = FacesContext.getCurrentInstance();
Bean bean = (Bean) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(),
null, "bean");
total = bean.getValor1() + bean.getValor2();
setMensagem("alert('Done');");
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public String getMensagem() {
return mensagem;
}
public void setMensagem(String mensagem) {
this.mensagem = mensagem;
}
}
Agradeço desde já pela atenção,
Att,
Lessandro
