You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Allen <da...@mojavelinux.com> on 2003/03/15 10:44:23 UTC

BeanUtils.copyProperties between from and DAO issues

I just wanted to see if I am working an uphill battle here or this
is really the reality of the situation.  I think you all might find
this question particularly intriguing.

Assume that my DAO (Data Access Object) is storing a list of ids
which matches with a relationship.  For example sake, it is a list
of Service Ids which coorespond to services available.  I have the
following method definitions

public List setServices(List services) {}

public List getServices() {}

public void setServicesIds(int[] serviceIds) {}

public int[] getServiceIds() {}

In my form a have a mutiple-select which I populate with all the
industries from the database table.  The multiple-select is set as a
java.lang.String[] since all form elements must be of type String
(am I right?)

Now, either I am populating from my form or populating to my form
using BeanUtils.copyProperties().  It would appear as though the
following conversion is failing horribly

int[] --> String[]

and

String[] --> int[]

..since the data never populates or saves (I did change the methods to
using String[] instead of int[] and it worked, so I know the issue
is the datatype, not because I don't know how to setup a form in
struts, I did finally figure that much out).

Short of creating method defintions which take and recieve String[]
arrays or manually iterating the form property in my Action class
and converting them to int[], is there any hope?

<rant>
Why is is so d*** hard to convert between a string and a primitive
integer in Java???  Damn, in PHP you don't even blink when you have
these two types.
</rant>

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
The idea of implementing a serious complex set of business 
logic rules in a scripting language like Perl really scares me. 
Perl is too much 'write once, read never again'. And that's no good 
for business logic that requires maintenance. 
 - voostind
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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


Re: BeanUtils.copyProperties between from and DAO issues

Posted by Dan Allen <da...@mojavelinux.com>.
> The FormBean can easily be populated by an array.
> "casting" is easy, and done once in a util function.
> beanUtils is usefull, but ... maybe not in this case.
> Maybe, I am just not getting you question, so someone else jump in.

Let me clarify.  My business object has a signature

public void setIndustryIds(int[] industryIds) {}

my form has a field

<field name="industryIds" type="java.lang.String[]"/>

the BeanUtils.copyProperties doesn't see that these two properties
should be linked, it simply doesn't call the setIndustryIds()
method.  Can I do something like

<field name="industryIds" type="int[]"/>

????

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Since no one can ever know for certain whether or not his own 
view of creation is the correct one, it is impossible for him 
to know if someone else's is the wrong one.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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


Re: BeanUtils.copyProperties between from and DAO issues

Posted by Vic Cekvenich <vc...@basebeans.com>.
The FormBean can easily be populated by an array.
"casting" is easy, and done once in a util function.
beanUtils is usefull, but ... maybe not in this case.
Maybe, I am just not getting you question, so someone else jump in.


.V

Dan Allen wrote:
> Right, but I was hoping that perhaps it should do this conversion
> itself.  Here's why.  It doesn't make sense for my DAO to be talking
> about ids in string format, for that would be "out of character,"
> catering to the view.  There isn't a way (that I know of) to get the
> form to populate itself with an array of primitive or lang integers.
> So therefore, I am asking, do I have to make my DAO bend over
> backwards to fix this hole in the view?  And why can't
> copyProperties handle this conversion?  Seems simple to me.
> 
> Dan
> 
> 
>>Write a util function link longString in here:
>>http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/bP/WEB-INF/src/war/org/apache/scaffoldingLib/util/BUtil.java
>>
>>You can just say in bean:
>>List l = getDAOx().getResult();
>>
>>And now you have a list in you bean, populated by dao.
>>
>>.V
>>
>>Dan Allen wrote:
>>
>>>I just wanted to see if I am working an uphill battle here or this
>>>is really the reality of the situation.  I think you all might find
>>>this question particularly intriguing.
>>>
>>>Assume that my DAO (Data Access Object) is storing a list of ids
>>>which matches with a relationship.  For example sake, it is a list
>>>of Service Ids which coorespond to services available.  I have the
>>>following method definitions
>>>
>>>public List setServices(List services) {}
>>>
>>>public List getServices() {}
>>>
>>>public void setServicesIds(int[] serviceIds) {}
>>>
>>>public int[] getServiceIds() {}
>>>
>>>In my form a have a mutiple-select which I populate with all the
>>>industries from the database table.  The multiple-select is set as a
>>>java.lang.String[] since all form elements must be of type String
>>>(am I right?)
>>>
>>>Now, either I am populating from my form or populating to my form
>>>using BeanUtils.copyProperties().  It would appear as though the
>>>following conversion is failing horribly
>>>
>>>int[] --> String[]
>>>
>>>and
>>>
>>>String[] --> int[]
>>>
>>>...since the data never populates or saves (I did change the methods to
>>>using String[] instead of int[] and it worked, so I know the issue
>>>is the datatype, not because I don't know how to setup a form in
>>>struts, I did finally figure that much out).
>>>
>>>Short of creating method defintions which take and recieve String[]
>>>arrays or manually iterating the form property in my Action class
>>>and converting them to int[], is there any hope?
>>>
>>><rant>
>>>Why is is so d*** hard to convert between a string and a primitive
>>>integer in Java???  Damn, in PHP you don't even blink when you have
>>>these two types.
>>></rant>
>>>
>>>Dan
> 
> 



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


Re: BeanUtils.copyProperties between from and DAO issues

Posted by Vic Cekvenich <vc...@basebeans.com>.
I see where you were going:

#1. Post a request for enhancement in bugzilla for commons.(which will 
CC commons-dev), not in Struts, and not in User.

#2. Wait a while.

#3. Give up waiting, and extend BennUtils to do what you need it to do.

#4. Submit a  enhancement code to BeanUtils bugzila, thus benefiting 
open source.

hth,
.V

Dan Allen wrote:
> Khalid K. (groups@maikada.com) wrote:
> 
> 
>>If this is the case, I would think that
>>org.apache.commons.beanutils.BeanUtils should be modified to do String[]
>>to int[] conversion ???
>>Thati s my 2 cents :)
> 
> 
> Thank you!!  Me too.  Okay, let's go with this!  Devs?
> 
> Also, when doing the conversion, anything which does not parse to an
> int should become 0 (naturally you won't attempt the conversion an
> expect anything else).
> 
> Dan
> 



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


Re: BeanUtils.copyProperties between from and DAO issues

Posted by Dan Allen <da...@mojavelinux.com>.
Khalid K. (groups@maikada.com) wrote:

> If this is the case, I would think that
> org.apache.commons.beanutils.BeanUtils should be modified to do String[]
> to int[] conversion ???
> Thati s my 2 cents :)

Thank you!!  Me too.  Okay, let's go with this!  Devs?

Also, when doing the conversion, anything which does not parse to an
int should become 0 (naturally you won't attempt the conversion an
expect anything else).

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Hey, somebody, sometime, somewhere, said something I think that 
just maybe might have been true but I think that I maybe 
didn't like it. 
 
F^CK IT, I'm suing everybody. 
 -- slashdot member in response to 
    petswarehouse.com sueing google.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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


Re: BeanUtils.copyProperties between from and DAO issues

Posted by Dan Allen <da...@mojavelinux.com>.
Here it is:

--- StringArrayConverter.java.orig	2003-03-21 04:43:17.000000000 -0500
+++ StringArrayConverter.java	2003-03-21 04:43:20.000000000 -0500
@@ -113,6 +113,10 @@
 
     // ------------------------------------------------------- Static Variables
 
+	/**
+	 * <p> Model object for int arrays.</p>
+	 */
+	private static int ints[] = new int[0];
 
     /**
      * <p>Model object for type comparisons.</p>
@@ -149,6 +153,19 @@
             return (value);
         }
 
+		// Deal with the input value as an int array
+		if (ints.getClass() == value.getClass())
+		{
+			int[] values = (int[]) value;
+			String[] results = new String[values.length];
+			for (int i = 0; i < values.length; i++)
+			{
+				results[i] = new StringBuffer().append(values[i]).toString();
+			}
+			
+			return (results);
+		}
+
         // Parse the input value as a String into elements
         // and convert to the appropriate type
         try {


As you can see, it was just necessary to check to see if an int[]
was passed to the converter.  Now this class mirrors its inverse,
IntegerArrayConvertor.java which first checks for a String[] to be
passed in, and then works with a String (in the format {2,3,4}).
Obviously if you pass in an int[] you want to get out the exact same
values converted to a String[] and as you can see, it is failproof
since StringBuffer can deal with any type.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
"Personally, I'm not finding Windows 
to be less expensive to administer, 
but those security holes--that'll kill 'em," 
-- Al Gillen, IDC
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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


Re: BeanUtils.copyProperties between from and DAO issues

Posted by Dan Allen <da...@mojavelinux.com>.
Dan Allen (dan@mojavelinux.com) wrote:

> Mitchell Morris (mmorris@mindspring.com) wrote:
> 
> > Hmmm ... looking in the BeanUtils javadocs, I see there's already an
> > IntegerArrayConverter which turns a String[] into an int[]. Oh look! The
> > author's name seems oddly familiar; anybody know some guy named "Craig R.
> > McClanahan"?
> > 
> > just-need-to-register-it-then-I-suppose-ly y'rs,
> Aha!  Finally got to the bottom of this one by creating a little
> test suite for myself.  Turns out that, besides ConvertUtils being
> awesome, there is a dichotomy.
> 
> The conversion from String[] => int[] works as expected.
> 
> The conversion from int[] => String[] is some quirky shit.
> 
> Basically, int[] => String[] looks for some format like {1,2,3} as a
> string and makes that into a String[] array, so it takes a String
> and makes a string array.  To me, this is not really the right
> converter at all.  Here is the issue, my model returns an int[]
> array of industryIds.  My form has a select box which is
> LabelValueBean collection which takes an array of String[].  So when
> copyProperties takes my model bean to populate the form bean, it
> turns a nice int array like
> 
> int[] industryIds = {2,8,9,2};
> 
> into 
> 
> String[] industryIds = {null,I,null,fd54d6}
> 
> As you can see, this will certainly not populate the form correctly.
> So now I am digging into adding my own converter.  I will get back
> to you when it is done.
> 
> Dan

I almost have a patch for this, it is really simple.  Where should I
direct the patch proposal.  To the dev list?

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Hey, somebody, sometime, somewhere, said something I think that 
just maybe might have been true but I think that I maybe 
didn't like it. 
 
F^CK IT, I'm suing everybody. 
 -- slashdot member in response to 
    petswarehouse.com sueing google.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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


Re: BeanUtils.copyProperties between from and DAO issues

Posted by Dan Allen <da...@mojavelinux.com>.
Mitchell Morris (mmorris@mindspring.com) wrote:

> Hmmm ... looking in the BeanUtils javadocs, I see there's already an
> IntegerArrayConverter which turns a String[] into an int[]. Oh look! The
> author's name seems oddly familiar; anybody know some guy named "Craig R.
> McClanahan"?
> 
> just-need-to-register-it-then-I-suppose-ly y'rs,
Aha!  Finally got to the bottom of this one by creating a little
test suite for myself.  Turns out that, besides ConvertUtils being
awesome, there is a dichotomy.

The conversion from String[] => int[] works as expected.

The conversion from int[] => String[] is some quirky shit.

Basically, int[] => String[] looks for some format like {1,2,3} as a
string and makes that into a String[] array, so it takes a String
and makes a string array.  To me, this is not really the right
converter at all.  Here is the issue, my model returns an int[]
array of industryIds.  My form has a select box which is
LabelValueBean collection which takes an array of String[].  So when
copyProperties takes my model bean to populate the form bean, it
turns a nice int array like

int[] industryIds = {2,8,9,2};

into 

String[] industryIds = {null,I,null,fd54d6}

As you can see, this will certainly not populate the form correctly.
So now I am digging into adding my own converter.  I will get back
to you when it is done.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
"Personally, I'm not finding Windows 
to be less expensive to administer, 
but those security holes--that'll kill 'em," 
-- Al Gillen, IDC
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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


RE: BeanUtils.copyProperties between from and DAO issues

Posted by Mitchell Morris <mm...@mindspring.com>.
Hmmm ... looking in the BeanUtils javadocs, I see there's already an
IntegerArrayConverter which turns a String[] into an int[]. Oh look! The
author's name seems oddly familiar; anybody know some guy named "Craig R.
McClanahan"?

just-need-to-register-it-then-I-suppose-ly y'rs,
+Mitchell

> -----Original Message-----
> From: Craig R. McClanahan [mailto:craigmcc@apache.org]
> Sent: Sunday, March 16, 2003 9:21 PM
> To: Struts Users Mailing List
> Subject: RE: BeanUtils.copyProperties between from and DAO issues
>
>
>
>
> On Sat, 15 Mar 2003, Khalid K. wrote:
>
> > Date: Sat, 15 Mar 2003 13:21:01 -0800
> > From: Khalid K. <gr...@maikada.com>
> > Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> > To: 'Struts Users Mailing List' <st...@jakarta.apache.org>
> > Subject: RE: BeanUtils.copyProperties between from and DAO issues
> >
> > If this is the case, I would think that
> > org.apache.commons.beanutils.BeanUtils should be modified
> to do String[]
> > to int[] conversion ???
> > Thati s my 2 cents :)
> > Khalid
> >
>
> The set of supported conversions is extensible -- simply
> create your own
> String[] to int[] Converter and register it with
> ConvertUtils.register().
> See the BeanUtils javadocs for more info:
>
>   http://jakarta.apache.org/commons/beanutils/api/
>
> Then, you can vastly increase the chance of this getting included in
> BeanUtils (and therefore in Struts) by submitting an
> enhancement request
> (against Commons Beanutils) and including your coinverter class as an
> attachment.
>
> Craig McClanahan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>



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


RE: BeanUtils.copyProperties between from and DAO issues

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sat, 15 Mar 2003, Khalid K. wrote:

> Date: Sat, 15 Mar 2003 13:21:01 -0800
> From: Khalid K. <gr...@maikada.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: 'Struts Users Mailing List' <st...@jakarta.apache.org>
> Subject: RE: BeanUtils.copyProperties between from and DAO issues
>
> If this is the case, I would think that
> org.apache.commons.beanutils.BeanUtils should be modified to do String[]
> to int[] conversion ???
> Thati s my 2 cents :)
> Khalid
>

The set of supported conversions is extensible -- simply create your own
String[] to int[] Converter and register it with ConvertUtils.register().
See the BeanUtils javadocs for more info:

  http://jakarta.apache.org/commons/beanutils/api/

Then, you can vastly increase the chance of this getting included in
BeanUtils (and therefore in Struts) by submitting an enhancement request
(against Commons Beanutils) and including your coinverter class as an
attachment.

Craig McClanahan

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


RE: BeanUtils.copyProperties between from and DAO issues

Posted by "Khalid K." <gr...@maikada.com>.
If this is the case, I would think that
org.apache.commons.beanutils.BeanUtils should be modified to do String[]
to int[] conversion ???
Thati s my 2 cents :)
Khalid


-----Original Message-----
From: Ken & Connie [mailto:ken_connie@bigfoot.com] 
Sent: Saturday, March 15, 2003 1:03 PM
To: Struts Users Mailing List
Subject: RE: BeanUtils.copyProperties between from and DAO issues




-----Original Message-----
From: Dan Allen [mailto:dan@mojavelinux.com]
Sent: Saturday, March 15, 2003 9:14 AM
To: Struts Users Mailing List
Subject: Re: BeanUtils.copyProperties between from and DAO issues


Right, but I was hoping that perhaps it should do this conversion
itself.  Here's why.  It doesn't make sense for my DAO to be talking
about ids in string format, for that would be "out of character,"
catering to the view.  There isn't a way (that I know of) to get the
form to populate itself with an array of primitive or lang integers. So
therefore, I am asking, do I have to make my DAO bend over backwards to
fix this hole in the view?  And why can't copyProperties handle this
conversion?  Seems simple to me.

Dan

> Write a util function link longString in here:
>
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/bP/WEB-INF/sr
c/wa
r/org/apache/scaffoldingLib/util/BUtil.java
>
> You can just say in bean:
> List l = getDAOx().getResult();
>
> And now you have a list in you bean, populated by dao.
>
> .V
>
> Dan Allen wrote:
> > I just wanted to see if I am working an uphill battle here or this 
> > is really the reality of the situation.  I think you all might find 
> > this question particularly intriguing.
> >
> > Assume that my DAO (Data Access Object) is storing a list of ids 
> > which matches with a relationship.  For example sake, it is a list 
> > of Service Ids which coorespond to services available.  I have the 
> > following method definitions
> >
> > public List setServices(List services) {}
> >
> > public List getServices() {}
> >
> > public void setServicesIds(int[] serviceIds) {}
> >
> > public int[] getServiceIds() {}
> >
> > In my form a have a mutiple-select which I populate with all the 
> > industries from the database table.  The multiple-select is set as a

> > java.lang.String[] since all form elements must be of type String 
> > (am I right?)
> >
> > Now, either I am populating from my form or populating to my form 
> > using BeanUtils.copyProperties().  It would appear as though the 
> > following conversion is failing horribly
> >
> > int[] --> String[]
> >
> > and
> >
> > String[] --> int[]
> >
> > ...since the data never populates or saves (I did change the methods

> > to using String[] instead of int[] and it worked, so I know the 
> > issue is the datatype, not because I don't know how to setup a form 
> > in struts, I did finally figure that much out).
> >
> > Short of creating method defintions which take and recieve String[] 
> > arrays or manually iterating the form property in my Action class 
> > and converting them to int[], is there any hope?
> >
> > <rant>
> > Why is is so d*** hard to convert between a string and a primitive 
> > integer in Java???  Damn, in PHP you don't even blink when you have 
> > these two types. </rant>
> >
> > Dan

--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Daniel
Allen, <da...@mojavelinux.com> http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "This is a
test of the Emergency Broadcast System.  If this had been an actual
emergency, do you really think we'd stick around to tell you?"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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


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




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


RE: BeanUtils.copyProperties between from and DAO issues

Posted by Ken & Connie <ke...@bigfoot.com>.

-----Original Message-----
From: Dan Allen [mailto:dan@mojavelinux.com]
Sent: Saturday, March 15, 2003 9:14 AM
To: Struts Users Mailing List
Subject: Re: BeanUtils.copyProperties between from and DAO issues


Right, but I was hoping that perhaps it should do this conversion
itself.  Here's why.  It doesn't make sense for my DAO to be talking
about ids in string format, for that would be "out of character,"
catering to the view.  There isn't a way (that I know of) to get the
form to populate itself with an array of primitive or lang integers.
So therefore, I am asking, do I have to make my DAO bend over
backwards to fix this hole in the view?  And why can't
copyProperties handle this conversion?  Seems simple to me.

Dan

> Write a util function link longString in here:
>
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/bP/WEB-INF/src/wa
r/org/apache/scaffoldingLib/util/BUtil.java
>
> You can just say in bean:
> List l = getDAOx().getResult();
>
> And now you have a list in you bean, populated by dao.
>
> .V
>
> Dan Allen wrote:
> > I just wanted to see if I am working an uphill battle here or this
> > is really the reality of the situation.  I think you all might find
> > this question particularly intriguing.
> >
> > Assume that my DAO (Data Access Object) is storing a list of ids
> > which matches with a relationship.  For example sake, it is a list
> > of Service Ids which coorespond to services available.  I have the
> > following method definitions
> >
> > public List setServices(List services) {}
> >
> > public List getServices() {}
> >
> > public void setServicesIds(int[] serviceIds) {}
> >
> > public int[] getServiceIds() {}
> >
> > In my form a have a mutiple-select which I populate with all the
> > industries from the database table.  The multiple-select is set as a
> > java.lang.String[] since all form elements must be of type String
> > (am I right?)
> >
> > Now, either I am populating from my form or populating to my form
> > using BeanUtils.copyProperties().  It would appear as though the
> > following conversion is failing horribly
> >
> > int[] --> String[]
> >
> > and
> >
> > String[] --> int[]
> >
> > ...since the data never populates or saves (I did change the methods to
> > using String[] instead of int[] and it worked, so I know the issue
> > is the datatype, not because I don't know how to setup a form in
> > struts, I did finally figure that much out).
> >
> > Short of creating method defintions which take and recieve String[]
> > arrays or manually iterating the form property in my Action class
> > and converting them to int[], is there any hope?
> >
> > <rant>
> > Why is is so d*** hard to convert between a string and a primitive
> > integer in Java???  Damn, in PHP you don't even blink when you have
> > these two types.
> > </rant>
> >
> > Dan

--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"This is a test of the Emergency Broadcast System.  If this had
been an actual emergency, do you really think we'd stick around
to tell you?"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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


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


[HK] DynaActionForm ?

Posted by harish krishnaswamy <wh...@yahoo.com>.
In the following .jsp code, can modelBeans be a
property array in a DynaActionForm (view2SubmitForm in
this case) bean?

<logic:iterate id="mb" name="view2SubmitForm"
property="modelBeans"
type="com.agilix.myapp.view.view1.ModelBean2">

<tr>
	<td><html:text name="mb" property="id"/></td>
	<td><html:text name="mb" property="name"
size="50"/></td>
	<td><html:text name="mb" property="price"/></td>
</tr>

</logic:iterate>

I tried the above code, I don't get an error but the
values entered in the text tag never makes it to
ModelBean2 bean.

Also, I see from the BeanUtils docs that the DynaBean
properties can be indexed and mapped, can
DynaActionForm do the same too? If yes, can someone
please point me to resources?

-Harish


__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - establish your business online
http://webhosting.yahoo.com

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


Re: BeanUtils.copyProperties between from and DAO issues

Posted by Dan Allen <da...@mojavelinux.com>.
Right, but I was hoping that perhaps it should do this conversion
itself.  Here's why.  It doesn't make sense for my DAO to be talking
about ids in string format, for that would be "out of character,"
catering to the view.  There isn't a way (that I know of) to get the
form to populate itself with an array of primitive or lang integers.
So therefore, I am asking, do I have to make my DAO bend over
backwards to fix this hole in the view?  And why can't
copyProperties handle this conversion?  Seems simple to me.

Dan

> Write a util function link longString in here:
> http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/bP/WEB-INF/src/war/org/apache/scaffoldingLib/util/BUtil.java
> 
> You can just say in bean:
> List l = getDAOx().getResult();
> 
> And now you have a list in you bean, populated by dao.
> 
> .V
> 
> Dan Allen wrote:
> > I just wanted to see if I am working an uphill battle here or this
> > is really the reality of the situation.  I think you all might find
> > this question particularly intriguing.
> > 
> > Assume that my DAO (Data Access Object) is storing a list of ids
> > which matches with a relationship.  For example sake, it is a list
> > of Service Ids which coorespond to services available.  I have the
> > following method definitions
> > 
> > public List setServices(List services) {}
> > 
> > public List getServices() {}
> > 
> > public void setServicesIds(int[] serviceIds) {}
> > 
> > public int[] getServiceIds() {}
> > 
> > In my form a have a mutiple-select which I populate with all the
> > industries from the database table.  The multiple-select is set as a
> > java.lang.String[] since all form elements must be of type String
> > (am I right?)
> > 
> > Now, either I am populating from my form or populating to my form
> > using BeanUtils.copyProperties().  It would appear as though the
> > following conversion is failing horribly
> > 
> > int[] --> String[]
> > 
> > and
> > 
> > String[] --> int[]
> > 
> > ...since the data never populates or saves (I did change the methods to
> > using String[] instead of int[] and it worked, so I know the issue
> > is the datatype, not because I don't know how to setup a form in
> > struts, I did finally figure that much out).
> > 
> > Short of creating method defintions which take and recieve String[]
> > arrays or manually iterating the form property in my Action class
> > and converting them to int[], is there any hope?
> > 
> > <rant>
> > Why is is so d*** hard to convert between a string and a primitive
> > integer in Java???  Damn, in PHP you don't even blink when you have
> > these two types.
> > </rant>
> > 
> > Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
"This is a test of the Emergency Broadcast System.  If this had 
been an actual emergency, do you really think we'd stick around 
to tell you?"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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


Re: BeanUtils.copyProperties between from and DAO issues

Posted by Vic Cekvenich <vc...@basebeans.com>.
Write a util function link longString in here:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/bP/WEB-INF/src/war/org/apache/scaffoldingLib/util/BUtil.java

You can just say in bean:
List l = getDAOx().getResult();

And now you have a list in you bean, populated by dao.

.V

Dan Allen wrote:
> I just wanted to see if I am working an uphill battle here or this
> is really the reality of the situation.  I think you all might find
> this question particularly intriguing.
> 
> Assume that my DAO (Data Access Object) is storing a list of ids
> which matches with a relationship.  For example sake, it is a list
> of Service Ids which coorespond to services available.  I have the
> following method definitions
> 
> public List setServices(List services) {}
> 
> public List getServices() {}
> 
> public void setServicesIds(int[] serviceIds) {}
> 
> public int[] getServiceIds() {}
> 
> In my form a have a mutiple-select which I populate with all the
> industries from the database table.  The multiple-select is set as a
> java.lang.String[] since all form elements must be of type String
> (am I right?)
> 
> Now, either I am populating from my form or populating to my form
> using BeanUtils.copyProperties().  It would appear as though the
> following conversion is failing horribly
> 
> int[] --> String[]
> 
> and
> 
> String[] --> int[]
> 
> ...since the data never populates or saves (I did change the methods to
> using String[] instead of int[] and it worked, so I know the issue
> is the datatype, not because I don't know how to setup a form in
> struts, I did finally figure that much out).
> 
> Short of creating method defintions which take and recieve String[]
> arrays or manually iterating the form property in my Action class
> and converting them to int[], is there any hope?
> 
> <rant>
> Why is is so d*** hard to convert between a string and a primitive
> integer in Java???  Damn, in PHP you don't even blink when you have
> these two types.
> </rant>
> 
> Dan
> 



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