javaScript+JSF

3 respostas
fabioebner

Pessoal alguem sabe se tem como eu fazer o segiunte? quero fazer um botao normal de cadastro porem so quero q ele EXECUTE O MEU METODO(de submit no form) apos eu executar um javascript… por exemplo para validacao de formulario via javascript… eu so quero q ele de o submit se o formulario estiver ok… se nao estiver nao de o submit…

obrigado

3 Respostas

MrDataFlex

fabioebner:
Pessoal alguem sabe se tem como eu fazer o segiunte? quero fazer um botao normal de cadastro porem so quero q ele EXECUTE O MEU METODO(de submit no form) apos eu executar um javascript… por exemplo para validacao de formulario via javascript… eu so quero q ele de o submit se o formulario estiver ok… se nao estiver nao de o submit…

obrigado

no evento onclick do botão: return fazTodasAsValidacoes();

se retornar true o método (significando que tudo está ok) ele dá submit, senão retorna false :smiley:

fabioebner

cara eu fiz isso daqui :

<f:subview id="menu">
    <html>
        <head>
            <script language="javaScript">
                function teste(){
                    alert('eee');
                    return false;
                    }
            </script>
            <title>Campanha</title>
            <style type="text/css">
                <!--
                body {
                    margin-left: 0px;
                    margin-top: 0px;
                    margin-right: 0px;
                    margin-bottom: 0px;
                }
                -->
            </style>
            <link href="../css/folha.css" rel="stylesheet" type="text/css" />
            
        </head>
        <body><h:form> 
            
            <table width="780" align="center" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <th width="170" rowspan="2" valign="top" scope="col"><a href="../principal/principal.jsf" ><img src="../imagens/topo_logo.jpg" width="170" height="190" border="0" /></a></th>
                    <th width="610" height="57" colspan="2" valign="top" background="../imagens/topo.jpg" scope="col">
                        <table width="100%" height="55" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <th height="19" class="fonte_branca" scope="col">
                                    
                                </th>
                            </tr>
                            <tr>
                                <th scope="row">
                                    
                                    
                                </th>
                            </tr>
                        </table>
                    </th>
                </tr>
                <tr>
                    <td colspan="2" valign="top">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="fonte">
                            <tr>
                                <td height="10" colspan="2" class="fonte"></td>
                            </tr>
                            <tr>
                                <td colspan="2" class="fonte"><strong class="fonte_titulo">Login no sistema</strong></td>
                            </tr>
                            <tr>
                                <td height="10" colspan="2">Preencha os campos abaixo para entrar no sistema</td>
                            </tr>
                            <tr>
                                <td height="10" colspan="2">&nbsp;</td>
                            </tr>
                            <tr>
                                <td width="13%" height="25">
                                    
                                &nbsp;Usu&aacute;rio:</td>
                                <td width="87%" height="10">
                                        <h:inputText value="#{PerfilBean.emailUsuario}" size="50" id="emailUsuario" >
                                            <f:validator validatorId="dnasolution.ValidaEmail" />
                                        </h:inputText>
                                        
                                        <rich:message for="emailUsuario">
                                            <f:facet name="errorMarker">
                                                <h:graphicImage  value="/images/error.gif" />  
                                            </f:facet>
                                        </rich:message>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="25">&nbsp;Senha:</td>
                                    <td height="10"><h:inputSecret value="#{PerfilBean.senhaUsuario}" id="senhaUsuario" required="true">
                                            <f:validateLength minimum="3" maximum="80"  />
                                        </h:inputSecret>
                                        <rich:message for="senhaUsuario">
                                            <f:facet name="errorMarker">
                                                <h:graphicImage  value="/images/error.gif" />
                                            </f:facet>
                                        </rich:message>
                                        </td>
                                </tr>
                                <tr>
                                    <td height="25">&nbsp;</td>
                                    <td height="10">
                                        <h:commandButton  value="Log33333333in" action="#{PerfilBean.perfilUsuario}" onclick="teste()" />
                                        
                                </tr>
                                
                                <tr>
                                    <td colspan="2" height="330">&nbsp;</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table> 
                <br>
                <%@ include file="../principal/rodape.jsp" %>
                
                
            </h:form>
            
        </body>
    </html>
    </f:subview>

e ele executa o submit .. nao funcionou

Ataxexe

Tem que ser:

onclick="return teste()"
Criado 3 de abril de 2008
Ultima resposta 3 de abr. de 2008
Respostas 3
Participantes 3