Skip to main content

JSP Bean, object methods

1 reply [Last post]
shmish111
Offline
Joined: 2008-09-30
Points: 0

I am using beans in JSP pages to collect my form data and put it in a database. What I also need to do is populate beans from the database. I currently have some methods which populate a container object correctly. However if I try using these methods when the container object is being used as a bean it won't work.

Some code:

<%
TransitionManager tm = new TransitionManager(); / /DB manager class
String TF_ID = request.getParameter("TF_ID");
if (null!= TF_ID){
summary = tm.getSummary(TF_ID); / /getSummary returns a Summary object
%>

Seemingly, what happens is the returned Summary object is shallow copied to the bean ("summary"). However it stops it being a bean any more. This means any changes I make to "summary" are not passed on to other pages that use the summary bean.

Once I've done this: summary = tm.getSummary(TF_ID); I can only change the bean using jsp:setProperty.

I started doing things long-handed with commands such as:

Summary summaryTemp = tm.getSummary(TF_ID);
summary.setCompanyName(summaryTemp.getCompanyName());
summary.setContract(summaryTemp.getContract());
summary.setAddress1(summaryTemp.getAddress1());

but I have realised as I work on my site that this is going to be a massive job. Is there anyway to cast an object to a bean object or another solution?

Any help would be greatly appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shmish111
Offline
Joined: 2008-09-30
Points: 0

Sorry, problems including comments in my code on the thread. here it is:


<%
TransitionManager tm = new TransitionManager();
String TF_ID = request.getParameter("TF_ID");
if (null!= TF_ID){
summary = tm.getSummary(TF_ID);
%>