You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Reinhard Spisser <re...@gruppotc.com> on 2002/11/07 15:27:43 UTC

NullpointerException in ActionForms

Hi all,

i was wondering how to handle correctly the following behaviour:
if a user calls directly from the url an action that has a Jsp in his
input and validate=true, i get a Nullpointerexception inside the
validate().

I think that this happens because the FormBean has never been
initialized with the values from the Jsp (the jsp has not been
displayed). All values in the FormBean are nulls.


I have added an instruction at the beginning of the validate() that
checks if one of the text fields are null, the validate returns null. 

Is there a better way to handle this? 

Thanks 

Reinhard




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


Re: NullpointerException in ActionForms

Posted by Eddie Bush <ek...@swbell.net>.
It's really hard to say without seeing the relevant pieces of your 
config file.

Do you declare a form-bean?  Do you use the name of the form-bean as the 
name attribute to the action you wish to have access to the form?

... if not, that is your problem.

Reinhard Spisser wrote:

>Hi all,
>
>i was wondering how to handle correctly the following behaviour:
>if a user calls directly from the url an action that has a Jsp in his
>input and validate=true, i get a Nullpointerexception inside the
>validate().
>
>I think that this happens because the FormBean has never been
>initialized with the values from the Jsp (the jsp has not been
>displayed). All values in the FormBean are nulls.
>
>
>I have added an instruction at the beginning of the validate() that
>checks if one of the text fields are null, the validate returns null. 
>
>Is there a better way to handle this? 
>
>Thanks 
>
>Reinhard
>

-- 
Eddie Bush





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


Re[2]: NullpointerException in ActionForms

Posted by Postfach 4711 <po...@gmx.de>.
Hello Eddie,



Thursday, November 7, 2002, 5:01:38 PM, you wrote:

EB> Postfach 4711 wrote:

>>Hello Reinhard,
>>
>>what will happen if the user calls the action from the jsp without
>>entering any data? If you also get the exception something is wrong
>>with your validate method.
>>
EB> There is a contract between actions and the forms they use:  The form 
EB> *will* be created.  This can be evidenced by the source (see 
EB> RequestProcessor.java).

Yes, the form does exist. As Reinhard wrote the NPE occurs
*inside* the validate methods. Seems like the validate methods is
using objects which do not exist.

EB> Your job, as an application developer, is to communicate to Struts (by 
EB> placing the name of the form-bean in the name attribute of the 
EB> action-mapping that needs access to the form) that a particular action 
EB> needs a particular form.  By doing Struts can (and will!) look for that 
EB> action to be executed and instantiate the form-bean if needed.  As such, 
EB> you should never get an NPE because of a form-bean.  If you do, it's 
EB> *most likely* because you did not tell Struts that the action requires 
EB> access to a form-bean.

>>Thursday, November 7, 2002, 3:27:43 PM, you wrote:
>>
>>RS> Hi all,
>>
>>RS> i was wondering how to handle correctly the following behaviour:
>>RS> if a user calls directly from the url an action that has a Jsp in his
>>RS> input and validate=true, i get a Nullpointerexception inside the
>>RS> validate().
>>
>>RS> I think that this happens because the FormBean has never been
>>RS> initialized with the values from the Jsp (the jsp has not been
>>RS> displayed). All values in the FormBean are nulls.
>>
>>
>>RS> I have added an instruction at the beginning of the validate() that
>>RS> checks if one of the text fields are null, the validate returns null. 
>>
>>RS> Is there a better way to handle this? 
>>
>>RS> Thanks 
>>
>>RS> Reinhard
>>



-- 
Best regards,
Dirk


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


Re: NullpointerException in ActionForms

Posted by Eddie Bush <ek...@swbell.net>.
Postfach 4711 wrote:

>Hello Reinhard,
>
>what will happen if the user calls the action from the jsp without
>entering any data? If you also get the exception something is wrong
>with your validate method.
>
There is a contract between actions and the forms they use:  The form 
*will* be created.  This can be evidenced by the source (see 
RequestProcessor.java).

Your job, as an application developer, is to communicate to Struts (by 
placing the name of the form-bean in the name attribute of the 
action-mapping that needs access to the form) that a particular action 
needs a particular form.  By doing Struts can (and will!) look for that 
action to be executed and instantiate the form-bean if needed.  As such, 
you should never get an NPE because of a form-bean.  If you do, it's 
*most likely* because you did not tell Struts that the action requires 
access to a form-bean.

>Thursday, November 7, 2002, 3:27:43 PM, you wrote:
>
>RS> Hi all,
>
>RS> i was wondering how to handle correctly the following behaviour:
>RS> if a user calls directly from the url an action that has a Jsp in his
>RS> input and validate=true, i get a Nullpointerexception inside the
>RS> validate().
>
>RS> I think that this happens because the FormBean has never been
>RS> initialized with the values from the Jsp (the jsp has not been
>RS> displayed). All values in the FormBean are nulls.
>
>
>RS> I have added an instruction at the beginning of the validate() that
>RS> checks if one of the text fields are null, the validate returns null. 
>
>RS> Is there a better way to handle this? 
>
>RS> Thanks 
>
>RS> Reinhard
>
-- 
Eddie Bush




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


Re: NullpointerException in ActionForms

Posted by Postfach 4711 <po...@gmx.de>.
Hello Reinhard,

what will happen if the user calls the action from the jsp without
entering any data? If you also get the exception something is wrong
with your validate method.

Thursday, November 7, 2002, 3:27:43 PM, you wrote:

RS> Hi all,

RS> i was wondering how to handle correctly the following behaviour:
RS> if a user calls directly from the url an action that has a Jsp in his
RS> input and validate=true, i get a Nullpointerexception inside the
RS> validate().

RS> I think that this happens because the FormBean has never been
RS> initialized with the values from the Jsp (the jsp has not been
RS> displayed). All values in the FormBean are nulls.


RS> I have added an instruction at the beginning of the validate() that
RS> checks if one of the text fields are null, the validate returns null. 

RS> Is there a better way to handle this? 

RS> Thanks 

RS> Reinhard




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



-- 
Best regards,
Dirk


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