You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Randy Kennedy <rk...@appriss.com> on 2005/05/20 14:20:07 UTC

Easy form populate question for gurus

Why does an object reference (e.g. java.lang.Object@75ea85) show up in 
my text fields when I prepopulate the form using Jakarta commons 
BeanUtils.copyProperties(...)?  The values in the database are null, and 
I know this has something to do with it, so I guess my real question is, 
"How do I fix it?".

--
Randy Kennedy
Appriss, Inc.


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


Re: Easy form populate question for gurus

Posted by Randy Kennedy <rk...@appriss.com>.
Well, I finally figured out a solution to this problem outlined below.  Thought I would share it with the group in case someone else runs into this same problem.

The problem is somewhere between the Jakarta Commons BeanUtils in conjunction with a LazyValidatorForm.  Since the LazyValidatorForm class is all about being lazy (like me) where you don't have to define your fields unless they're associated with custom classes, there is a problem when you go to initialize the form with database data that contains null values.  I thought that since my value object had the fields defined as java.lang.String objects that they would be translated to that in the form object when using BeanUtils.copyProperties(...), but that's not always the case.  I had to actually use a <form-property> element in the LazyValidatorForm definition in the struts config file defining that the field is a String field.  This defeats the whole purpose for me using the LazyValidatorForm method in the first place.

Anyway, it fixed my problem, and it appears that I have to stop being lazy.  ;-(

--
Randy Kennedy
Software Engineer
Appriss, Inc. (Provider of the VINE Service)
10401 Linn Station Road, Suite 200
Louisville, KY  40223-3842

Web   : http://www.vineco.com, http://www.appriss.com
Email : rkennedy@appriss.com



Randy Kennedy wrote:

>
> Here is a snippet from my initializing action before it goes to the 
> form view:
>
> ...
>        LazyValidatorForm ppForm = (LazyValidatorForm)form;
>        ProtectedPersonLocal ppl = null;
>        ProtectedPersonDTO dto = null;
>        String sid = null;
>              sid = request.getParameter("sid");
>                  ppl = 
> (ProtectedPersonLocal)EJBHelper.getLocalInstance(ProtectedPersonLocalHome.JNDI_NAME); 
>
>        dto = ppl.getProtectedPersonBySid(sid);
>        BeanUtils.copyProperties(ppForm, dto);
> ....
>
> The values in question are java.lang.String objects.  Should be basic 
> stuff right?  I stepped through the debugger, and the 
> LazyValidatorForm object is being set correctly for the null strings 
> from my VO; however, when it comes to displaying the form for editing, 
> the "null" fields contain an object reference like 
> java.lang.Object@75ea85.  If I update the form with any type of text 
> values, it'll show correctly the next time that I go to update the 
> data.  It's only happening when there are null values involved.
>
> Hubert Rabago wrote:
>
>> Please provide more information.  How is your form configured/written?
>> Are there "initial" values?  What is the type of the data from which
>> you're copying a value?
>>
>> Hubert
>>
>>
>> On 5/20/05, Randy Kennedy <rk...@appriss.com> wrote:
>>  
>>
>>> Why does an object reference (e.g. java.lang.Object@75ea85) show up in
>>> my text fields when I prepopulate the form using Jakarta commons
>>> BeanUtils.copyProperties(...)?  The values in the database are null, 
>>> and
>>> I know this has something to do with it, so I guess my real question 
>>> is,
>>> "How do I fix it?".
>>>
>>> -- 
>>> Randy Kennedy
>>> Appriss, Inc.
>>>
>>>
>>>   
>>
> -- 
>
> Randy Kennedy
> Software Engineer
> Appriss, Inc. (Provider of the VINE Service)
> 10401 Linn Station Road, Suite 200
> Louisville, KY  40223-3842
>
> Web   : http://www.vineco.com, http://www.appriss.com
> Email : rkennedy@appriss.com




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


FRIDAY - WebGVO Struts-Groove app - help wanted

Posted by Neil Finlayson <ne...@mysterian.com>.
People,

I'm looking for bug/enhancement assistance on the following Struts app which
is I believe the first J2EE connector to the very cool Microsoft Groove
virtual office.

http://mrquintron.gla.mysterian.com/WebGVO/execute/listWorkspaceSetup

Its built on John Carnell's very nice Struts starter project from that Wrox
book of a couple of years ago.

I hope I haven't broken protocol on the list with this request and by
mentioning Microsoft!!

Regards,

Neil Finlayson
______________________
Dr. Neil Finlayson
Technical Director, AtlanticShack
Website: http://www.atlanticshack.com/
Weblog: http://radio.weblogs.com/0112316/
Tel: +44 (01851) 810124
Mobile: 07919 445909



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


Re: Easy form populate question for gurus

Posted by Randy Kennedy <rk...@appriss.com>.
Here is a snippet from my initializing action before it goes to the form 
view:

...
        LazyValidatorForm ppForm = (LazyValidatorForm)form;
        ProtectedPersonLocal ppl = null;
        ProtectedPersonDTO dto = null;
        String sid = null;
       
        sid = request.getParameter("sid");
           
        ppl = 
(ProtectedPersonLocal)EJBHelper.getLocalInstance(ProtectedPersonLocalHome.JNDI_NAME);
        dto = ppl.getProtectedPersonBySid(sid);
        BeanUtils.copyProperties(ppForm, dto);
....

The values in question are java.lang.String objects.  Should be basic 
stuff right?  I stepped through the debugger, and the LazyValidatorForm 
object is being set correctly for the null strings from my VO; however, 
when it comes to displaying the form for editing, the "null" fields 
contain an object reference like java.lang.Object@75ea85.  If I update 
the form with any type of text values, it'll show correctly the next 
time that I go to update the data.  It's only happening when there are 
null values involved.

Hubert Rabago wrote:

>Please provide more information.  How is your form configured/written?
> Are there "initial" values?  What is the type of the data from which
>you're copying a value?
>
>Hubert
>
>
>On 5/20/05, Randy Kennedy <rk...@appriss.com> wrote:
>  
>
>>Why does an object reference (e.g. java.lang.Object@75ea85) show up in
>>my text fields when I prepopulate the form using Jakarta commons
>>BeanUtils.copyProperties(...)?  The values in the database are null, and
>>I know this has something to do with it, so I guess my real question is,
>>"How do I fix it?".
>>
>>--
>>Randy Kennedy
>>Appriss, Inc.
>>
>>
>>    
>>
--

Randy Kennedy
Software Engineer
Appriss, Inc. (Provider of the VINE Service)
10401 Linn Station Road, Suite 200
Louisville, KY  40223-3842

Web   : http://www.vineco.com, http://www.appriss.com
Email : rkennedy@appriss.com



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


Re: Easy form populate question for gurus

Posted by Hubert Rabago <hr...@gmail.com>.
Please provide more information.  How is your form configured/written?
 Are there "initial" values?  What is the type of the data from which
you're copying a value?

Hubert


On 5/20/05, Randy Kennedy <rk...@appriss.com> wrote:
> Why does an object reference (e.g. java.lang.Object@75ea85) show up in
> my text fields when I prepopulate the form using Jakarta commons
> BeanUtils.copyProperties(...)?  The values in the database are null, and
> I know this has something to do with it, so I guess my real question is,
> "How do I fix it?".
> 
> --
> Randy Kennedy
> Appriss, Inc.
> 
>

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


RE: Easy form populate question for gurus

Posted by Mark Benussi <ma...@hotmail.com>.
If your Database values are null then the corresponding Object should be
null and not an Object Reference.

Make sure when you read a ResultSet you call

Integer column = null;

int tmpColumn = results.getInteger("COLUMN");
if(!results.wasNull()) {
	// I think it is wasNull(). You don't need to worry about it with
Strings.
	column = new Integer(tmpColumn);
}

// Assuming column was the property you were attempting to populate your
form with using BeanUtils.

I placed a method in my DBHelper for all the data type gets to avoid
duplicating all this code.

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Randy Kennedy
Sent: 20 May 2005 13:20
To: user@struts.apache.org
Subject: Easy form populate question for gurus

Why does an object reference (e.g. java.lang.Object@75ea85) show up in 
my text fields when I prepopulate the form using Jakarta commons 
BeanUtils.copyProperties(...)?  The values in the database are null, and 
I know this has something to do with it, so I guess my real question is, 
"How do I fix it?".

--
Randy Kennedy
Appriss, Inc.


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


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


Re: Easy form populate question for gurus

Posted by DG...@EvergreenInvestments.com.
Did you observe any odd behavior when you started the debugger and stepped 
through the source for BeanUtils.copyProperties(Object dest, Object orig)?


Randy Kennedy <rk...@appriss.com> 
Sent by: news <ne...@sea.gmane.org>
05/20/2005 08:20 AM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
user@struts.apache.org
cc

Subject
Easy form populate question for gurus






Why does an object reference (e.g. java.lang.Object@75ea85) show up in 
my text fields when I prepopulate the form using Jakarta commons 
BeanUtils.copyProperties(...)?  The values in the database are null, and 
I know this has something to do with it, so I guess my real question is, 
"How do I fix it?".

--
Randy Kennedy
Appriss, Inc.


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