21/05/2009, 10:24
|
| | Fecha de Ingreso: mayo-2009
Mensajes: 20
Antigüedad: 15 años, 6 meses Puntos: 0 | |
Respuesta: Problema Struts el form:
<form-bean name="targetasForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="sensores" type="com.meteorologic.struts.Sensores[]"/>
</form-bean>
el mapping del action
<action
attribute="targetasForm"
input="/jsp/editarSensores.jsp"
name="targetasForm"
path="/editarSensores"
parameter="do"
scope="session"
type="com.meteorologic.struts.action.EditarSensore sAction">
<forward name="actualizarSensor" path="/jsp/editarSensores.jsp" />
<forward name="volver" path="/gestio.do?parameter=actualizar"/>
</action>
la jsp:
<html:form action="/editarSensores">
<logic:iterate name="targetasForm" property="sensores" id="Sensores" indexId="i">
<html:hidden name="Sensores" property="idsensores" indexed="true" />
<tr>
<td>Sensor ${i+1}</</td>
<td><html:text name="Sensores" property="tiposensor" indexed="true" /></td>
<td><html:checkbox name="Sensores" property="activo" indexed="true" /></td><br>
</tr>
</logic:iterate>
<html:hidden property="do" value="actualizarEstacion" />
<html:submit/>
</html:form>
y por último el action:
public class EditarSensoresAction extends org.apache.struts.actions.DispatchAction {
public ActionForward editarSensores(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaActionForm theForm = (DynaActionForm) form;
MeteorologicManager meteorologicManager = new MeteorologicManager();
Sensores[] sensores = meteorologicManager.getSensores((Integer)request.g etAttribute("idestacion"));
theForm.set("sensores", sensores);
int numSensores = sensores.length;
request.setAttribute("numsensors", numSensores);
return mapping.findForward("actualizarSensor");
}
public ActionForward actualizarEstacion(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm theForm = (DynaActionForm)form;
MeteorologicManager meteorologicManager = new MeteorologicManager();
Sensores[] sensores = (Sensores[])theForm.get("sensores");
meteorologicManager.actualizarSensores(sensores);
return mapping.findForward("volver");
}
} |