You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Pillay, Kiren KN" <Ki...@standardbank.co.za> on 2006/07/11 10:15:14 UTC

Indexed Bean Copy

Hi

I've got a domain object which stored an indexed array of objects.

<-- Extract of Domain Object
public class GroupExposures {

	private Exposure [] exposures=new Exposure[]{new Exposure(),new
Exposure(),new Exposure()};
	
	  
	class Exposure{
	float totalSBSABroughtForward;
	float otherSBSAFacilitiesPerParagraph;
	float SBSAExposureToTheApplicant;
	float otherSBGFacilitiesPerParagraph;
	float totalSBGExposureToTheApplicant;
	float otherSBSAFacilitesWholeGroup;
	float otherSBGFacilitiesWholeGroup;
	float totalSBGExposureWholeGroup;
	float SBGBorrowingsWholeGroup;
	float otherBankBorrowings;
	float otherLenders;
	float totalArrangedBorrowings;
	}
	
public float getOtherLenders(int type) {
		return exposures[type].otherLenders;
	}
	public void setOtherLenders(float otherLenders,int type) {
		exposures[type].otherLenders = otherLenders;
	}

-->
Form extract:
public float getOtherLendersUtilisation(){return
OtherLendersUtilisation;
	}

----

In my Action class I have to say the following:
 
groupExposures.setOtherLenders(groupExposuresForm.getOtherLendersUtilisa
tion(),LimitTypes.UTILISATION);	
 

------
The way this class is set up, I cannot use BeanUtils.copy() to copy the
values across. The Action class is huge because of this and it was quite
tedious putting in the code. Is there a quicker, easier way to do this? 

Regards
Kiren Pillay



__________________________________________________________________________________________________________________________________

Standard Bank Disclaimer and Confidentiality Note

This e-mail, its attachments and any rights attaching hereto are, unless the context clearly indicates otherwise, the property of Standard Bank Group Limited
and/or its subsidiaries ("the Group"). It is confidential, private and intended for the addressee only. Should you not be the addressee and receive this e-mail by
mistake, kindly notify the sender, and delete this e-mail, immediately and do not disclose or use same in any manner whatsoever. Views and opinions
expressed in this e-mail are those of the sender unless clearly stated as those of the Group. The Group accepts no liability whatsoever for any loss or
damages whatsoever and howsoever incurred, or suffered, resulting, or arising, from the use of this email or its attachments. The Group does not warrant the integrity
of this e-mail nor that it is free of errors, viruses, interception or interference. Licensed divisions of the Standard Bank Group are authorised financial services providers
in terms of the Financial Advisory and Intermediary Services Act, No 37 of 2002 (FAIS).
For information about the Standard Bank Group Limited visit our website http://www.standardbank.co.za
___________________________________________________________________________________________________________________________________

RE: Indexed Bean Copy

Posted by "Pillay, Kiren KN" <Ki...@standardbank.co.za>.
Thanks for the reply, I will consider your suggestion.

I could have written the business objects to fit the form bean with a
one-to-one mapping, but then I don't think it's a good idea to make the
domain objects match your framework's solution (even though it would
have been quicker this way).

I could have used a collection, I'll add it in when I refactor the code.

Regards
Kiren 

-----Original Message-----
From: Adam Gordon [mailto:adam.gordon@readytalk.com] 
Sent: 11 July 2006 05:24 PM
To: Struts Users Mailing List
Subject: Re: Indexed Bean Copy

Kiren-

I assume you mean BeanUtils.copyProperties(...) right?

If so, I believe the reason you cannot use it is because
BeanUtils.copyProperties(...) performs a shallow copy and per the
javadocs (HTML tags removed):  "...and so complex properties (for
example, nested ones) will not be copied."

I would suggest removing it from the Action code by creating a utility
class and implement your own copy() method.  Say, a static "duplication"

method that takes an instance of your bean as a parameter and returns a
new instance of the same bean.  I'm curious as to why you're using
arrays as opposed to the Collections framework....

I don't believe that any copy methods in the J2SE are deep copy methods,
so if this is what you need, then a static utility method is probably
your best bet.

cheers,

-Adam

Pillay, Kiren KN wrote:
> Hi
>
> I've got a domain object which stored an indexed array of objects.
>
> <-- Extract of Domain Object
> public class GroupExposures {
>
> 	private Exposure [] exposures=new Exposure[]{new Exposure(),new 
> Exposure(),new Exposure()};
> 	
> 	  
> 	class Exposure{
> 	float totalSBSABroughtForward;
> 	float otherSBSAFacilitiesPerParagraph;
> 	float SBSAExposureToTheApplicant;
> 	float otherSBGFacilitiesPerParagraph;
> 	float totalSBGExposureToTheApplicant;
> 	float otherSBSAFacilitesWholeGroup;
> 	float otherSBGFacilitiesWholeGroup;
> 	float totalSBGExposureWholeGroup;
> 	float SBGBorrowingsWholeGroup;
> 	float otherBankBorrowings;
> 	float otherLenders;
> 	float totalArrangedBorrowings;
> 	}
> 	
> public float getOtherLenders(int type) {
> 		return exposures[type].otherLenders;
> 	}
> 	public void setOtherLenders(float otherLenders,int type) {
> 		exposures[type].otherLenders = otherLenders;
> 	}
>
> -->
> Form extract:
> public float getOtherLendersUtilisation(){return
> OtherLendersUtilisation;
> 	}
>
> ----
>
> In my Action class I have to say the following:
>  
>
groupExposures.setOtherLenders(groupExposuresForm.getOtherLendersUtilisa
> tion(),LimitTypes.UTILISATION);	
>  
>
> ------
> The way this class is set up, I cannot use BeanUtils.copy() to copy 
> the values across. The Action class is huge because of this and it was

> quite tedious putting in the code. Is there a quicker, easier way to
do this?
>
> Regards
> Kiren Pillay
>
>
>
> ______________________________________________________________________
> __ __________________________________________________________
>
> Standard Bank Disclaimer and Confidentiality Note
>
> This e-mail, its attachments and any rights attaching hereto are, 
> unless the context clearly indicates otherwise, the property of 
> Standard Bank Group Limited and/or its subsidiaries ("the Group"). It 
> is confidential, private and intended for the addressee only. Should 
> you not be the addressee and receive this e-mail by mistake, kindly 
> notify the sender, and delete this e-mail, immediately and do not 
> disclose or use same in any manner whatsoever. Views and opinions 
> expressed in this e-mail are those of the sender unless clearly stated

> as those of the Group. The Group accepts no liability whatsoever for 
> any loss or damages whatsoever and howsoever incurred, or suffered, 
> resulting, or arising, from the use of this email or its attachments. 
> The Group does not warrant the integrity of this e-mail nor that it is

> free of errors, viruses, interception or interference. Licensed 
> divisions of the Standard Bank Group are authorised financial services

> providers in terms of the Financial Advisory and Intermediary Services

> Act, No 37 of 2002 (FAIS).
> For information about the Standard Bank Group Limited visit our 
> website http://www.standardbank.co.za 
> ______________________________________________________________________
> __ ___________________________________________________________
>
>   

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

__________________________________________________________________________________________________________________________________

Standard Bank Disclaimer and Confidentiality Note

This e-mail, its attachments and any rights attaching hereto are, unless the context clearly indicates otherwise, the property of Standard Bank Group Limited
and/or its subsidiaries ("the Group"). It is confidential, private and intended for the addressee only. Should you not be the addressee and receive this e-mail by
mistake, kindly notify the sender, and delete this e-mail, immediately and do not disclose or use same in any manner whatsoever. Views and opinions
expressed in this e-mail are those of the sender unless clearly stated as those of the Group. The Group accepts no liability whatsoever for any loss or
damages whatsoever and howsoever incurred, or suffered, resulting, or arising, from the use of this email or its attachments. The Group does not warrant the integrity
of this e-mail nor that it is free of errors, viruses, interception or interference. Licensed divisions of the Standard Bank Group are authorised financial services providers
in terms of the Financial Advisory and Intermediary Services Act, No 37 of 2002 (FAIS).
For information about the Standard Bank Group Limited visit our website http://www.standardbank.co.za
___________________________________________________________________________________________________________________________________

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


Re: Indexed Bean Copy

Posted by Adam Gordon <ad...@readytalk.com>.
Kiren-

I assume you mean BeanUtils.copyProperties(...) right?

If so, I believe the reason you cannot use it is because 
BeanUtils.copyProperties(...) performs a shallow copy and per the 
javadocs (HTML tags removed):  "...and so complex properties (for 
example, nested ones) will not be copied."

I would suggest removing it from the Action code by creating a utility 
class and implement your own copy() method.  Say, a static "duplication" 
method that takes an instance of your bean as a parameter and returns a 
new instance of the same bean.  I'm curious as to why you're using 
arrays as opposed to the Collections framework....

I don't believe that any copy methods in the J2SE are deep copy methods, 
so if this is what you need, then a static utility method is probably 
your best bet.

cheers,

-Adam

Pillay, Kiren KN wrote:
> Hi
>
> I've got a domain object which stored an indexed array of objects.
>
> <-- Extract of Domain Object
> public class GroupExposures {
>
> 	private Exposure [] exposures=new Exposure[]{new Exposure(),new
> Exposure(),new Exposure()};
> 	
> 	  
> 	class Exposure{
> 	float totalSBSABroughtForward;
> 	float otherSBSAFacilitiesPerParagraph;
> 	float SBSAExposureToTheApplicant;
> 	float otherSBGFacilitiesPerParagraph;
> 	float totalSBGExposureToTheApplicant;
> 	float otherSBSAFacilitesWholeGroup;
> 	float otherSBGFacilitiesWholeGroup;
> 	float totalSBGExposureWholeGroup;
> 	float SBGBorrowingsWholeGroup;
> 	float otherBankBorrowings;
> 	float otherLenders;
> 	float totalArrangedBorrowings;
> 	}
> 	
> public float getOtherLenders(int type) {
> 		return exposures[type].otherLenders;
> 	}
> 	public void setOtherLenders(float otherLenders,int type) {
> 		exposures[type].otherLenders = otherLenders;
> 	}
>
> -->
> Form extract:
> public float getOtherLendersUtilisation(){return
> OtherLendersUtilisation;
> 	}
>
> ----
>
> In my Action class I have to say the following:
>  
> groupExposures.setOtherLenders(groupExposuresForm.getOtherLendersUtilisa
> tion(),LimitTypes.UTILISATION);	
>  
>
> ------
> The way this class is set up, I cannot use BeanUtils.copy() to copy the
> values across. The Action class is huge because of this and it was quite
> tedious putting in the code. Is there a quicker, easier way to do this? 
>
> Regards
> Kiren Pillay
>
>
>
> ________________________________________________________________________
> __________________________________________________________
>
> Standard Bank Disclaimer and Confidentiality Note
>
> This e-mail, its attachments and any rights attaching hereto are, unless
> the context clearly indicates otherwise, the property of Standard Bank
> Group Limited
> and/or its subsidiaries ("the Group"). It is confidential, private and
> intended for the addressee only. Should you not be the addressee and
> receive this e-mail by
> mistake, kindly notify the sender, and delete this e-mail, immediately
> and do not disclose or use same in any manner whatsoever. Views and
> opinions
> expressed in this e-mail are those of the sender unless clearly stated
> as those of the Group. The Group accepts no liability whatsoever for any
> loss or
> damages whatsoever and howsoever incurred, or suffered, resulting, or
> arising, from the use of this email or its attachments. The Group does
> not warrant the integrity
> of this e-mail nor that it is free of errors, viruses, interception or
> interference. Licensed divisions of the Standard Bank Group are
> authorised financial services providers
> in terms of the Financial Advisory and Intermediary Services Act, No 37
> of 2002 (FAIS).
> For information about the Standard Bank Group Limited visit our website
> http://www.standardbank.co.za
> ________________________________________________________________________
> ___________________________________________________________
>
>   

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