Button jsp struts

1 resposta
diogoprosoft

Galera olha esse meu JSP, preciso colocar um button para buscar um metodo na minha action como posso fazer isso me sujeriram usar javascript mais nao teria outra maneira?

JSP

<html:html locale="true">
    <head>        
        <title><bean:message key="titulo"/></title>
    <html:base/>
    </head>
    <body>
        <html:form action="conta" focus="idconta">
            <html:hidden name="salvar" property="method" value="salvar"/>                
            Id:<html:text property="idconta"/>
            Data_Cadastro<html:text property="datacadastro"/>
            Nome:<html:text property="nome"/>
            Obs:<html:text property="obs"/>
            <html:submit value="Salvar"/>            
        </html:form>
    </body>
</html:html>

Action

public class ContaAction extends DispatchAction {
    
private final static String SUCCESS = "success";    
           
    public ActionForward salvar(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
           
        HttpSession session = request.getSession();
        
        ContaForm contaForm = (ContaForm) form;
        Conta conta = new Conta();
        BeanUtils.copyProperties(conta, contaForm);
        
        PersistenciaDAO persistencia = new PersistenciaDAO();
        
        persistencia.salvar(conta);
        
        return mapping.findForward(SUCCESS);        
                
    }
    
    public ActionForward deletar(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
           
        HttpSession session = request.getSession();
        
        ContaForm contaForm = (ContaForm) form;
        Conta conta = new Conta();
        BeanUtils.copyProperties(conta, contaForm);
        
        PersistenciaDAO persistencia = new PersistenciaDAO();
        
        persistencia.deletar(conta);
        
        return mapping.findForward(SUCCESS);        
                
    }
    
}

Susgentão que me deram

1. funtion funcaoExemplo(){  
   2. document.forms[0].action="suaAction.do";  
   3. document.submit(0);  
   4. }

Mais onde irei passar o methodo deletar nesse javascript, pq ali so mostra como chamar a action

1 Resposta

alves.Felipe
<html:html locale="true">   
    <head>           
        <title><bean:message key="titulo"/></title>   
    <html:base/>   
    </head>   
    <body>   
        <html:form action="conta" focus="idconta">   
            <html:hidden name="salvar" property="method" value="salvar"/>                   
            Id:<html:text property="idconta"/>   
            Data_Cadastro<html:text property="datacadastro"/>   
            Nome:<html:text property="nome"/>   
            Obs:<html:text property="obs"/>   
            <html:submit value="Salvar"/>  
            <html:button property="consultar" value="Consultar" onclick="acao('consultar');"/>
        </html:form>   
    </body>   
</html:html>
js
function acao(metodo)
{
            document.getElementById("method").value=metodo;
            document.seuForm.submit();
}
Criado 6 de junho de 2008
Ultima resposta 6 de jun. de 2008
Respostas 1
Participantes 2