You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Postfach 4711 <po...@gmx.de> on 2002/11/07 16:11:13 UTC

Re[2]: NullpointerException in ActionForms

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>