JSF + confirmação com javascript

2 respostas
rbcunha

Olá,

Eu estou tentando colocar uma mensagem de confirmação com javascript antes de chamar meu Managed Bean, porém o que parece muito básico não esta funcionando. O método do MB é chamado porém o evento onsubmit não é executado.

Alguém teria alguma dica.

Abaixo segue o código do meu formulário.

Dentro do h:form tem o atributo onsubmit da seguinte forma:
onsubmit="return confirm(‘Confirma ?’)

Coloquei aqui pois o fórum não está apresentando o código completo.

Grato

<f:view>
<html>
<head>
<meta http-equiv=“Content-Type”
content=“text/html; charset=windows-1252”/>
<title>Teste</title>
</head>
<body>

&lt;h:form onsubmit="return confirm('Confirma ?');"&gt;    
    &lt;h:panelGrid columns="2"&gt;
      &lt;h:outputText value="Nome"/&gt;
      &lt;h:inputText value="#{agendaMB.nome}"/&gt;
      &lt;h:outputText value="Telefone"/&gt;
      &lt;h:inputText value="#{agendaMB.fone}"/&gt;
      &lt;h:commandButton value="Inserir" action="#{agendaMB.insere}"/&gt;
      &lt;h:commandButton value="Limpar" type="reset"/&gt;
    &lt;/h:panelGrid&gt;
  &lt;/h:form&gt;&lt;/body&gt;

</html>
</f:view>

2 Respostas

D

tente este código.

<f:view>
<html>
<head>
<meta http-equiv=“Content-Type”
content=“text/html; charset=windows-1252”/>
<title>Teste</title>
</head>
<body>

<h:form>

<h:panelGrid columns=“2”>

<h:outputText value=“Nome”/>

<h:inputText value="#{agendaMB.nome}"/>

<h:outputText value=“Telefone”/>

<h:inputText value="#{agendaMB.fone}"/>

<h:commandButton onclick=“return confirm(‘Confirma ?’);” value=“Inserir” action="#{agendaMB.insere}"/>

<h:commandButton value=“Limpar” type=“reset”/>

</h:panelGrid>

</h:form></body>

</html>

</f:view>
rbcunha

Valeu!
Desta forma funcionou!

DanielPaiva:
tente este código.

<f:view>
<html>
<head>
<meta http-equiv=“Content-Type”
content=“text/html; charset=windows-1252”/>
<title>Teste</title>
</head>
<body>

<h:form>

<h:panelGrid columns=“2”>

<h:outputText value=“Nome”/>

<h:inputText value="#{agendaMB.nome}"/>

<h:outputText value=“Telefone”/>

<h:inputText value="#{agendaMB.fone}"/>

<h:commandButton onclick=“return confirm(‘Confirma ?’);” value=“Inserir” action="#{agendaMB.insere}"/>

<h:commandButton value=“Limpar” type=“reset”/>

</h:panelGrid>

</h:form></body>

</html>

</f:view>

</blockquote>
Criado 18 de abril de 2006
Ultima resposta 19 de abr. de 2006
Respostas 2
Participantes 2