Thanks everybody,
I solved this problem with a not very good way (but it worked out !), but i think perhaps you can help me to improve this way. I would like to throw a Ajax error into my "catch", and the "onerror" (insted of oncomplete) recive it, and open the dialog.
Is there possibility ??
Example that worked out , with a poor way:
<p:panel id="PanelLogin" header="Login" >
<h:form id="FormLogin" >
<br/>
<h:panelGrid columns="2">
<h:outputLabel for="user" value="Usuario:" />
<p:inputText id="user" required="true" value=" " size="75" />
<h:outputLabel for="pin" value="Senha:" />
<p:password id="pin" required="true" value=" " size="55" />
</h:panelGrid>
<p:commandButton styleClass="botaoLogin" value="OK" action="#{loginBean.checkLogin()}" ajax="true" oncomplete="if (#{loginBean.dialog}) confirmation.show()" />
</h:form>
</p:panel>
<p:dialog id="atencaoDialog" resizable="false" appendToBody="true" header="Atencao" widgetVar="confirmation" height="85" width="300" showEffect="bounce">
<div align="center">
<p:messages id="outputTextAtencaoDialog" autoUpdate="true" redisplay="false" />
</div>
<div style="text-align: center;">
<p:commandButton id="okButtonAtencaoDialog" value="OK" onclick="confirmation.hide();" />
</div>
</p:dialog>
MyBean
@ManagedBean(name = "loginBean")
@SessionScoped
public class LoginBean implements Serializable {
private boolean dialog;
...
public String checarAutenticacao() {
...
try {
...
return "/templantes/telaAplicacao.xhtml";
} catch (Throwable e) {
this.dialog = true;
// try to throw Ajax error instead of this below ??
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(e.getMessage()));
return null;
}
}
()
in your action method? depending on what container you are using, that won't work... – Elias Dorneles