Boa tarde, gostaria de saber se no meu action eu consigo recuperar os campos do jsp. sem precisar usar o s:form?
JSP
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Struts 2 - Example</title>
</head>
<body>
<div>
<table>
<tr>
<td>
<s:form action="moradorConsulta">
<s:textfield label="Nome" name="morador.nome" size="20"></s:textfield>
<s:combobox label="Bloco" name="morador.bloco"
headerValue="--- Selecione o Bloco ---"
headerKey="1" list="{'A','B'}" />
<s:combobox label="Apartamento" name="morador.apartamento"
headerValue="--- Selecione o Apartamento ---"
headerKey="1" list="{'101','102','103','104','105','106','107','108'}" />
<s:submit value="Consultar" notifyTopics="" />
<!-- s:submit type="image" label="Consultar" src="../../images/ok.jpeg"/-->
</s:form>
</td>
</tr>
</table>
<a href="<s:url action='moradorConsulta!clear.action'></s:url>" style="text-decoration:none" target="principal">Clear2</a>
<table border="2">
<tr>
<td style="width: 150px; text-align: center">Name</td>
<td style="width: 150px; text-align: center">Bloco</td>
<td style="width: 150px; text-align: center">Apartamento</td>
<td style="width: 150px; text-align: center">Picture</td>
</tr>
<s:if test="%{listaMoradores != null}">
<s:iterator value="listaMoradores">
<tr>
<td><s:property value="nome" /></td>
<td><s:property value="bloco" /></td>
<td><s:property value="apartamento" /></td>
<td>.<!-- img src="<s:property value="foto" />" width="150" height="70" alt="Achatada" border="0"--></td>
</tr>
</s:iterator>
</s:if>
</table>
</div>
</body>
</html>
Action
package com.stec.scr.actions;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.stec.scr.dao.FactoryDAO;
import com.stec.scr.dao.SessionDAO;
import com.stec.scr.exception.DAOException;
import com.stec.scr.model.morador.Morador;
import com.stec.scr.model.morador.dao.MoradorDAO;
public class MoradorConsultaAction extends ActionSupport {
private static final long serialVersionUID = 402422198448619470L;
private List<Morador> listaMoradores;
private Morador morador;
public String execute() {
FactoryDAO factory = FactoryDAO.getFactory();
SessionDAO session = factory.createSessionDAO();
MoradorDAO moradorDAO = factory.getMoradorDAO(session);
try {
session.beginTrans();
listaMoradores = moradorDAO.pesquisaByNome(morador);
} catch (DAOException e) {
e.printStackTrace();
} finally {
session.close();
}
return "success";
}
public String clear(){
// aqui preciso recuperar o morador
return "success";
}
//Gets e Sets
}
Aqui no metodo “clear” gostaria de recuperar o morador.
No “execute” trabalho normalmente com o morador, isto esta funcionado.