You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Claudia Woestheinrich <cl...@vit.de> on 2004/09/06 10:57:22 UTC

map-backed ActionForm

Hello,

my JSP-Code is:
<html:form action="/ProjektDDE.do">
......

    <tr>
        <td class=tl1><html:checkbox property="value" value="
<%=ent.getEntity_id().toString()%>" >&nbsp;<%=ent.getDde
()%></html:checkbox></td>

        <td class=tl1>Anzahl: <html:text property="value(key)" size
="2"/></td>
     </tr>

and the ActionForm:

public class ProjektDDEForm extends ActionForm{

    private Map enten;


    /** Creates a new instance of ProjektDDEForm */
    public ProjektDDEForm() {

    }

    public Map getEnten(){
        return enten;
    }

    public void setEnten(Map _map){
        enten=_map;
    }

    public void setValue(String _key, String _value)throws Exception
{
        getEnten().put(_key,_value);
    }

    public Object getValue(String _key)throws Exception{
        return enten.get(_key);
    }


}

In the Action-Class:

... ProjektDDEForm form=(ProjektDDEForm)actionForm;

           Map map=form.getEnten();
  Line 60:      Iterator it=map.keySet().iterator();
      while (it.hasNext()){
                String key=(String)it.next();
                System.out.println("key  "+key);
                System.out.println("value "+map.get(key));
            }



2004-09-06 10:19:57 StandardWrapperValve[action]: Servlet.service()
for servlet action threw exception
java.lang.NullPointerException
     at
de.vit.AdisAded.actions.ProjektDDEAction.execute(ProjektDDEAction.java:60)
     at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
     at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
     at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
     at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
     at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
     at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.jav

What is wrong???

Thanks Claudia


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: map-backed ActionForm

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Claudia,

> and the ActionForm:
> 
> public class ProjektDDEForm extends ActionForm{
> 
>    private Map enten;
> 
>    /** Creates a new instance of ProjektDDEForm */
>    public ProjektDDEForm() {
> 
>    }
> 
>    public Map getEnten(){
>        return enten;
>    }
> 
>    public void setEnten(Map _map){
>        enten=_map;
>    }

> In the Action-Class:
> 
> ... ProjektDDEForm form=(ProjektDDEForm)actionForm;
> 
>           Map map=form.getEnten();
>  Line 60:      Iterator it=map.keySet().iterator();

> 2004-09-06 10:19:57 StandardWrapperValve[action]: Servlet.service()
> for servlet action threw exception
> java.lang.NullPointerException
>     at
> de.vit.AdisAded.actions.ProjektDDEAction.execute(ProjektDDEAction.java:60)
Since Map#keySet() will not return null, I would say that your enten is
null.  Are you explicitly setting it via setEnten()?  If so, where?  If
not, set it before you use it.  (Or you can just initialize it on object
creation.)

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai(shinobu.kawai@gmail.com)

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org