struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neil Mendoza" <>
Subject Map-backed ActionForms PLEASE HELP!!!!
Date Wed, 09 Nov 2005 18:58:49 GMT
OK, I'm climbing up the walls trying to make Struts populate a map-backed action form.  This
should be a simple task but I cannot get it to f*&king work and it is driving me insane...
 The reset method is called before the form is first displayed and the resulting jsp is populated
with the value set in the reset method, i.e. it's accessing the map correctly.  However, when
the form is submitted the reset is called again but the form bean is not populated from the
request before it gets to the action...


Action Form class

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class StrutsTestForm extends ActionForm  {
	private Map things = new HashMap(); 
    public void setThing(String key, String value) {
    		things.put(key, value);
    public Object getThing(String key) {
        return things.get(key);
    public void reset(
    	    ActionMapping arg0, 
    	    HttpServletRequest arg1) {
    		setThing("name", "test");
    		System.out.println("reset called");

form jsp

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<title>Employee Form</title>
<h1>Employee Form</h1>
<html:form action="sta" focus="name" method="get">
    <td >Name:</td>
    <td><html:text property="thing(name)"/></td>
    <td><html:text property="thing(age)"/></td>

Action class

package com.prytaniagroup.www;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
//import org.apache.commons.
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public final class StrutsTestAction extends Action {
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {
    			StrutsTestForm strutsTestForm = (StrutsTestForm)form;
        		return (mapping.findForward("success"));

extracts from strusts-config.xml



            <forward name="success" path="/confirmation.jsp"/>
This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution

of the material in this e-mail is strictly forbidden. The Prytania Group has taken every 
reasonable precaution to ensure that any attachment to this e-mail has been swept for 
viruses. However, we cannot accept liability for any damage sustained as a result of 
software viruses and would advise that you carry out your own virus checks before 
opening any attachment.

  • Unnamed multipart/alternative (inline, 7-Bit, 0 bytes)
View raw message