struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dale Newfield <d...@newfield.org>
Subject Re: Problem with paramsPrepareParamsStack
Date Mon, 10 Aug 2009 14:47:46 GMT
spsarolkar wrote:
>>     public void prepare(){
>>         if(emailId==null){
>>             this.user=new User();             
>>         }
>>         else{
>>             this.user=userService.findByEmail(emailId);
>>         }
>>     }

So if emailId is null you construct a new one, but if it is not null and 
findByEmail() fails, it is still null.

> java.lang.IllegalArgumentException: attempt to create create event with null
> entity

> When i tried to debug it I am getting user object in prepare() function i.e.
> user is not null  but when i check the same value in update method it comes
> out to be null


>         <s:hidden name="emailId" />
>         <s:if test="email==null">
>           <s:submit value="Register" />
>         </s:if>

This generates <input type="hidden" name="emailId" value=""/>, right?
So it'll submit a parameter &emailId=, which will result in emailId not 
being null, but rather being the empty string.  The prepare lookup 
fails, so user is still null.

Try these two fixes:


 >         <s:if test="%{email == null}">
 >           <s:submit value="Register" />
 >         </s:if>
 >         <s:else>
 >           <s:hidden name="emailId" />
 >           <s:submit value="Update" />
 >         </s:else>

 >     public void prepare() {
 >         if (emailId != null) {
 >             this.user=userService.findByEmail(emailId);
 >         }
 >         if (this.user == null) {
 >             this.user = new User();
 >         }
 >     }

-Dale

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


Mime
View raw message