Boa noite pessoal, estou começando com Jboss seam e estou tentando fazer um formulário
para cadastro de usuários utilizando “a4j”.
O problema é que tenho meu formulário, tenho meu “a4j:commandButton”, e tenho um “rich:modalPanel”
que é exibido para confirmar a ação do usuário.
No começo tive problemas com o insert do usuário, com o “a4j:commandButton” ele exibia o modal
mesmo quando havia erros de válidação, ou seja, o modal só funcionava corretamente com o “h:commandButton”,
mas esse já resolvi. Agora meu problema é, estou editando um usuário e clico no botão para realizar o update
das informações, eles está atualizando os dados no banco independente de haver ou não o modal para confirmação,
independente inclusive de haver ou não um action no botão. Meu código está assim:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="/layout/template.xhtml">
<ui:define name="body">
<h:form id="usuarioForm">
<a4j:outputPanel ajaxRendered="true">
<s:decorate id="nmUsuarioField" template="/layout/edit.xhtml">
<ui:define name="label">
<h:outputText value="Nome: " />
</ui:define>
<h:inputText id="nmUsuario" required="true"
value="#{userHome.instance.nmUsuario}" />
</s:decorate>
<s:decorate id="dsLoginField" template="/layout/edit.xhtml">
<ui:define name="label">
<h:outputText value="Login: " />
</ui:define>
<h:inputText id="dsLogin" required="true"
value="#{userHome.instance.dsLogin}" />
</s:decorate>
<s:decorate id="dsSenhaField" template="/layout/edit.xhtml">
<ui:define name="label">
<h:outputText value="Senha: " />
</ui:define>
<h:inputSecret id="dsSenha" required="true" redisplay="true"
value="#{userHome.instance.dsSenha}" />
</s:decorate>
<h:panelGroup layout="block" style="clear: both" />
<br />
<a4j:commandButton id="save" value="Inserir"
rendered="#{!userHome.managed}"
oncomplete="Richfaces.showModalPanel('confirmInsert')">
</a4j:commandButton>
<a4j:commandButton id="update" value="Salvar"
rendered="#{userHome.managed}"
oncomplete="Richfaces.showModalPanel('confirmUpdate')">
</a4j:commandButton>
<a4j:commandButton id="delete" value="Remover"
rendered="#{userHome.managed}"
oncomplete="Richfaces.showModalPanel('confirmDelete')">
</a4j:commandButton>
<s:button id="cancel" value="Cancelar" propagation="end"
view="/services/user/userList.xhtml" />
<rich:modalPanel id="confirmInsert" width="250" height="90"
resizeable="false" autosized="true"
rendered="#{empty facesContext.maximumSeverity}">
<f:facet name="header">
<h:panelGroup>
<h:graphicImage value="/img/help.png" styleClass="imgLabel" />
<h:outputText value="Confirmação" />
</h:panelGroup>
</f:facet>
<h:panelGrid columns="1" styleClass="confirmTable"
rowClasses="confirmText, confirmButtons">
<h:column>
<h:outputText value="#{messages.cCreate}" />
</h:column>
<h:column>
<s:button id="insertYesOption" value="Sim"
action="#{userHome.persist}" propagation="end"
view="/services/user/userList.xhtml">
<rich:componentControl for="confirmInsert"
attachTo="insertYesOption" operation="hide" event="onclick" />
</s:button>
<a4j:commandButton id="insertNoOption" value="Não">
<rich:componentControl for="confirmInsert"
attachTo="insertNoOption" operation="hide" event="onclick" />
</a4j:commandButton>
</h:column>
</h:panelGrid>
</rich:modalPanel>
<rich:modalPanel id="confirmUpdate" width="250" height="90"
resizeable="false" autosized="true"
rendered="#{empty facesContext.maximumSeverity}">
<f:facet name="header">
<h:panelGroup>
<h:graphicImage value="/img/help.png" styleClass="imgLabel" />
<h:outputText value="Confirmação" />
</h:panelGroup>
</f:facet>
<h:panelGrid columns="1" styleClass="confirmTable"
rowClasses="confirmText, confirmButtons">
<h:column>
<h:outputText value="#{messages.cUpdate}" />
</h:column>
<h:column>
<s:button id="updateYesOption" value="Sim"
action="#{userHome.update}" propagation="end"
view="/services/user/userList.xhtml">
<rich:componentControl for="confirmUpdate"
attachTo="updateYesOption" operation="hide" event="onclick" />
</s:button>
<a4j:commandButton id="updateNoOption" value="Não">
<rich:componentControl for="confirmUpdate"
attachTo="updateNoOption" operation="hide" event="onclick" />
</a4j:commandButton>
</h:column>
</h:panelGrid>
</rich:modalPanel>
<rich:modalPanel id="confirmDelete" width="250" height="90"
resizeable="false" autosized="true"
rendered="#{empty facesContext.maximumSeverity}">
<f:facet name="header">
<h:panelGroup>
<h:graphicImage value="/img/help.png" styleClass="imgLabel" />
<h:outputText value="Confirmação" />
</h:panelGroup>
</f:facet>
<h:panelGrid columns="1" styleClass="confirmTable"
rowClasses="confirmText, confirmButtons">
<h:column>
<h:outputText value="#{messages.cDlete}" />
</h:column>
<h:column>
<s:button id="deleteYesOption" value="Sim"
action="#{userHome.remove}" propagation="end"
view="/services/user/userList.xhtml">
<rich:componentControl for="confirmDelete"
attachTo="deleteYesOption" operation="hide" event="onclick" />
</s:button>
<a4j:commandButton id="deleteNoOption" value="Não">
<rich:componentControl for="confirmDelete"
attachTo="deleteNoOption" operation="hide" event="onclick" />
</a4j:commandButton>
</h:column>
</h:panelGrid>
</rich:modalPanel>
</a4j:outputPanel>
</h:form>
</ui:define>
</ui:composition>
Minha classe é muito simples:
@Name("userHome")
public class UserHome extends EntityHome<User> {
private static final long serialVersionUID = -5340839264696555417L;
@RequestParameter
private Long idUsuario;
@Begin
@Override
public void create() {
super.create();
}
@Override
public Object getId() {
return this.idUsuario;
}
}
Se alguem tiver uma solução, será de grande ajuda !
Valeu !