Galera, tou tentando aprender o ActionForm do Struts. Tou seguindo um exemplo da apostila da Caelum, adaptando-o a minha necessidade. Queria saber porque os valores dos campos da página JSP não estão sendo passados para ActionForm. Os métodos get’s do Form sempre retorna null.
JuncaoAction.java
public class JuncaoAction extends Action {
@Override
public ActionForward execute(ActionMapping map, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
JuncaoForm formulario = ((JuncaoForm) form);
System.out.println(formulario.getArquivo() + " /=/ " + formulario.getCd());
JuncaoBO bo = new JuncaoBO();
bo.gravarArquivo(formulario.getArquivo(), formulario.getCd());
return map.findForward("ok");
}
}
JuncaoForm.java
public class JuncaoForm extends ActionForm {
private String cd;
private String arquivo;
public String getCd() {
return this.cd;
}
public String getArquivo() {
return this.arquivo;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
this.cd = null;
this.arquivo = null;
}
}
juncao.jsp
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<html:html>
<head><title><bean:message key="projeto.nome" /></title></head>
<html:errors/>
<html:form action="/juncao" focus="cd">
CD:
<html:text property="cd"/><br/>
Arquivo:
<html:file property="arquivo"/><br/>
<html:submit>Junção</html:submit><br/>
</html:form>
</html:html>
struts-config.xml
<form-beans>
<form-bean name="juncaoForm" type="br.gov.serpro.struts.form.JuncaoForm"/>
</form-beans>
<action-mappings>
<action path="/listaCaixas" type="br.gov.serpro.struts.action.ListaCaixasAction">
<forward name="lista" path="/listaCaixas.jsp"/>
</action>
<action path="/juncao"
name="juncaoForm"
type="br.gov.serpro.struts.action.JuncaoAction">
<forward name="ok" path="/listaCaixas.do" />
</action>
</action-mappings>
Obrigado.