You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jan Fetyko <ja...@phase2online.com> on 2002/09/10 15:53:24 UTC

NullPointerException while extending DynaValidatorForm

Hi all,

I have a problem setting values of a form in my action.
The form extends the "org.apache.struts.validator.DynaValidatorForm". 
The struts-config.xml defines all the properties of the form except 2, 
that are defined in the actual Java source of the form.

This is the error I'm getting :

java.lang.NullPointerException
	at org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java:551)


In struts config I have :

    <form-bean name="CustomerForm" type="com.forms.CustomerForm">
        <form-property name="cid" type="java.lang.String"/>
    </form-bean>

The action is trying to set the property of the form :

form = new CustomerForm();
CustomerForm cf = (CustomerForm) form;
cf.set("cid", customer.getCid()); // THIS iS WHERE IT ERRORS OUT.



Any ideas what I'm doing wrong ?

Jf


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: NullPointerException while extending DynaValidatorForm

Posted by Robert Taylor <rt...@mulework.com>.
Define a "set up" action mapping which is called prior to displaying your
page.

<action path="/showSomePage"
            type="com.companyname.SomeAction"
            name="customerForm"
            validate="false"
            scope="request">

      <forward name="success"
               path="/somePage.jsp"
               redirect="false"/>

    </action>

In the corresponding XXXXAction class for the mapping do the following:
public ActionForward execute(ActionMapping mapping,
                 ActionForm form,
                 HttpServletRequest request,
                 HttpServletResponse response)
    		throws Exception {

    DynaBean bean = (DynaBean) form;
    Customer customer = // get customer somehow

    bean.set("cid", customer.getCid());

    return mapping.findForward("success");

    }


When Struts encounters the /showSomePage it will create the form, invoke
SomeAction (which will populate the form), and then forward to somePage.jsp
where the form will reside in the request scope.

HTH,

robert

> -----Original Message-----
> From: Jan Fetyko [mailto:struts@phase2online.com]
> Sent: Wednesday, September 11, 2002 7:45 AM
> To: Struts Users Mailing List
> Subject: Re: NullPointerException while extending DynaValidatorForm
>
>
> How do I allow Struts to create the form ?
> Sorry, but I'm lost here ( and there :(( ).
>
> Jf
>
> Robert Taylor wrote:
>
> >Depending on which version of Struts you are using, you may
> >need to set the dynamic attribute of the form-bean element to "true".
> >
> >I'm assuming you are explicitely creating the form to convey that
> >the NPE is not because the form is null. If this is not the case,
> >you should allow Struts to create the form.
> >
> >robert
> >
> >
> >
> >
> >>-----Original Message-----
> >>From: Jan Fetyko [mailto:struts@phase2online.com]
> >>Sent: Tuesday, September 10, 2002 11:32 AM
> >>To: struts
> >>Subject: Re: NullPointerException while extending DynaValidatorForm
> >>
> >>
> >>Looks like nobody has a recommendation on how to resolve issue described
> >>below ( at least till now).
> >>Is this working at all OR is this still a bug in the Beta version ?
> >>So, should I stick with the "old" forms for now ?
> >>
> >>Jf
> >>
> >>----------------------------------------------------------------
> ---------
> >>
> >>
> >>
> >>>Hi all,
> >>>
> >>>I have a problem setting values of a form in my action.
> >>>The form extends the "org.apache.struts.validator.DynaValidatorForm".
> >>>The struts-config.xml defines all the properties of the form except 2,
> >>>that are defined in the actual Java source of the form.
> >>>
> >>>This is the error I'm getting :
> >>>
> >>>java.lang.NullPointerException
> >>>at
> >>>
> >>>
> >>>
> >>org.apache.struts.action.DynaActionForm.getDynaProperty(DynaAction
> >>Form.java:551)
> >>
> >>
> >>>
> >>>In struts config I have :
> >>>
> >>><form-bean name="CustomerForm" type="com.forms.CustomerForm">
> >>><form-property name="cid" type="java.lang.String"/>
> >>></form-bean>
> >>>
> >>>The action is trying to set the property of the form :
> >>>
> >>>form = new CustomerForm();
> >>>CustomerForm cf = (CustomerForm) form;
> >>>cf.set("cid", customer.getCid()); // THIS iS WHERE IT ERRORS OUT.
> >>>
> >>>
> >>>
> >>>Any ideas what I'm doing wrong ?
> >>>
> >>>Jf
> >>>
> >>>
> >>>
> >>--
> >>To unsubscribe, e-mail:
> >>
> >>
> ><ma...@jakarta.apache.org>
> >For additional commands, e-mail:
> ><ma...@jakarta.apache.org>
> >
> >
> >--
> >To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
>For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
>
>


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: NullPointerException while extending DynaValidatorForm

Posted by Jan Fetyko <st...@phase2online.com>.
How do I allow Struts to create the form ?
Sorry, but I'm lost here ( and there :(( ).

Jf

Robert Taylor wrote:

>Depending on which version of Struts you are using, you may
>need to set the dynamic attribute of the form-bean element to "true".
>
>I'm assuming you are explicitely creating the form to convey that
>the NPE is not because the form is null. If this is not the case,
>you should allow Struts to create the form.
>
>robert
>
>
>  
>
>>-----Original Message-----
>>From: Jan Fetyko [mailto:struts@phase2online.com]
>>Sent: Tuesday, September 10, 2002 11:32 AM
>>To: struts
>>Subject: Re: NullPointerException while extending DynaValidatorForm
>>
>>
>>Looks like nobody has a recommendation on how to resolve issue described
>>below ( at least till now).
>>Is this working at all OR is this still a bug in the Beta version ?
>>So, should I stick with the "old" forms for now ?
>>
>>Jf
>>
>>-------------------------------------------------------------------------
>>
>>    
>>
>>>Hi all,
>>>
>>>I have a problem setting values of a form in my action.
>>>The form extends the "org.apache.struts.validator.DynaValidatorForm".
>>>The struts-config.xml defines all the properties of the form except 2,
>>>that are defined in the actual Java source of the form.
>>>
>>>This is the error I'm getting :
>>>
>>>java.lang.NullPointerException
>>>at
>>>
>>>      
>>>
>>org.apache.struts.action.DynaActionForm.getDynaProperty(DynaAction
>>Form.java:551)
>>    
>>
>>>
>>>In struts config I have :
>>>
>>><form-bean name="CustomerForm" type="com.forms.CustomerForm">
>>><form-property name="cid" type="java.lang.String"/>
>>></form-bean>
>>>
>>>The action is trying to set the property of the form :
>>>
>>>form = new CustomerForm();
>>>CustomerForm cf = (CustomerForm) form;
>>>cf.set("cid", customer.getCid()); // THIS iS WHERE IT ERRORS OUT.
>>>
>>>
>>>
>>>Any ideas what I'm doing wrong ?
>>>
>>>Jf
>>>
>>>      
>>>
>>--
>>To unsubscribe, e-mail:
>>    
>>
><ma...@jakarta.apache.org>
>For additional commands, e-mail:
><ma...@jakarta.apache.org>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>  
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: NullPointerException while extending DynaValidatorForm

Posted by Robert Taylor <rt...@mulework.com>.
Depending on which version of Struts you are using, you may
need to set the dynamic attribute of the form-bean element to "true".

I'm assuming you are explicitely creating the form to convey that
the NPE is not because the form is null. If this is not the case,
you should allow Struts to create the form.

robert


> -----Original Message-----
> From: Jan Fetyko [mailto:struts@phase2online.com]
> Sent: Tuesday, September 10, 2002 11:32 AM
> To: struts
> Subject: Re: NullPointerException while extending DynaValidatorForm
>
>
> Looks like nobody has a recommendation on how to resolve issue described
> below ( at least till now).
> Is this working at all OR is this still a bug in the Beta version ?
> So, should I stick with the "old" forms for now ?
>
> Jf
>
> -------------------------------------------------------------------------
>
> > Hi all,
> >
> > I have a problem setting values of a form in my action.
> > The form extends the "org.apache.struts.validator.DynaValidatorForm".
> > The struts-config.xml defines all the properties of the form except 2,
> > that are defined in the actual Java source of the form.
> >
> > This is the error I'm getting :
> >
> > java.lang.NullPointerException
> > at
> >
> org.apache.struts.action.DynaActionForm.getDynaProperty(DynaAction
> Form.java:551)
> >
> >
> >
> > In struts config I have :
> >
> > <form-bean name="CustomerForm" type="com.forms.CustomerForm">
> > <form-property name="cid" type="java.lang.String"/>
> > </form-bean>
> >
> > The action is trying to set the property of the form :
> >
> > form = new CustomerForm();
> > CustomerForm cf = (CustomerForm) form;
> > cf.set("cid", customer.getCid()); // THIS iS WHERE IT ERRORS OUT.
> >
> >
> >
> > Any ideas what I'm doing wrong ?
> >
> > Jf
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: NullPointerException while extending DynaValidatorForm

Posted by Jan Fetyko <st...@phase2online.com>.
Looks like nobody has a recommendation on how to resolve issue described 
below ( at least till now).
Is this working at all OR is this still a bug in the Beta version ?
So, should I stick with the "old" forms for now ?

Jf

-------------------------------------------------------------------------

> Hi all,
>
> I have a problem setting values of a form in my action.
> The form extends the "org.apache.struts.validator.DynaValidatorForm". 
> The struts-config.xml defines all the properties of the form except 2, 
> that are defined in the actual Java source of the form.
>
> This is the error I'm getting :
>
> java.lang.NullPointerException
> at 
> org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java:551) 
>
>
>
> In struts config I have :
>
> <form-bean name="CustomerForm" type="com.forms.CustomerForm">
> <form-property name="cid" type="java.lang.String"/>
> </form-bean>
>
> The action is trying to set the property of the form :
>
> form = new CustomerForm();
> CustomerForm cf = (CustomerForm) form;
> cf.set("cid", customer.getCid()); // THIS iS WHERE IT ERRORS OUT.
>
>
>
> Any ideas what I'm doing wrong ?
>
> Jf
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: NullPointerException while extending DynaValidatorForm

Posted by micael <ca...@harbornet.com>.
You are not initializing a variable for an object.  I know that is rather 
obvious, but sometimes the obvious helps.  I hope it does here.

At 09:53 AM 9/10/2002 -0400, you wrote:
>Hi all,
>
>I have a problem setting values of a form in my action.
>The form extends the "org.apache.struts.validator.DynaValidatorForm". The 
>struts-config.xml defines all the properties of the form except 2, that 
>are defined in the actual Java source of the form.
>
>This is the error I'm getting :
>
>java.lang.NullPointerException
>         at 
> org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java:551)
>
>
>In struts config I have :
>
>    <form-bean name="CustomerForm" type="com.forms.CustomerForm">
>        <form-property name="cid" type="java.lang.String"/>
>    </form-bean>
>
>The action is trying to set the property of the form :
>
>form = new CustomerForm();
>CustomerForm cf = (CustomerForm) form;
>cf.set("cid", customer.getCid()); // THIS iS WHERE IT ERRORS OUT.
>
>
>
>Any ideas what I'm doing wrong ?
>
>Jf
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>