Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Fetching/Passing Data  RSS feed

 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers
I'm facing a problem in fetching/passing calculated data from a bean. Actually I'm calculating some stuff in a bean, accessing that through a servlet and then displaying the calculated data using JSP/JSTL on the browser. Now there are 2 such bean classes which calculate separately and I want to access these two bean classes in another bean class and display the final result on the browser. It's something like this - say Bean class A does addition of 2 nos, Bean class B does subtraction of 2 other nos. Now Bean class C should fetch class A's sum, class B's subtraction and perform mutiplication on both these and display result on browser. This is easy if values are constant but the values here are being passed by user. Am using Prepared Statement(?) attribute to fetch data from user. So I cannot get the data again from the user and calculate the stuff.

How should I access calculated data of class A and class B without again writing a query or asking the user to enter values again or calculating again? Any possible way to get this? Kindly help, your help would be much appreciated !!! I'm struck with this.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does class C have A and B as members? Are these beans related to each other or completely independent?
 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martijn
I'm calling the bean classes from servlets and so am importing bean classes in servlets. Also both the classes A & B are independent, not related in any way. And I din't understand which members you are referring to here. Can you suggest me how to solve this?

 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand your situation correctly, I think you want to have Bean C as the main display bean, and it to have A and B as members, so



Alternatively if A and B have static util calculating methods on them then:


 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martijn
It's not a matter of static methods or instance methods. It's something like this:


Here both the method parameters are being fetched from the user, i.e. they are getting passed from servlet after querying. So if I have to call those methods in C class then I should again pass the parameters(or ask the user to enter) which is redundancy. I want to avoid this as if I pass again I need to calculate the whole lot again. How should I go ahead from here? Can you please show me a way out ? Hope I explained you the context to some extent.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I think what you need is to store values in the appropriate _scope_ for reuse. Remember in JSP/J2EE land you have pageContext, session context, application context (session context), have a think about which scope would be right for you in this case...

Moving to the servlet forum as there's lots of good advice there on this sort of thing (I've been out of front end development way to long).
 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah Martijn, will go through those contexts and see if my problem gets solved. Thanks a bunch for helping me ! I found a way out for this problem. Thanks again !!!
 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All
Can anyone help me? You can read the thread to get a gist of the problem am facing.

Even after changing the scope to session, I'm facing the same old problem. Instead of the excepted result, am able to display 0 which is wrong. I'm not sure if the respected methods are getting called because am not passing any method parameters while calling. And still am not getting any errors. And if I try to pass any parameters then am getting errors(actually the IDE is not accepting any parameters for that method call). How should I go ahead from here? Kindly help me !!!
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi swapna,

you are getting input from user right?...... then you are doing some logic with the help of three bean class right? you no need to get input from user again right? ........ i guess you are making difficult with simple logic .
 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah SeethaRaman, you got it right. Even I don't want to take the user input again. But am not knowing how to get the calculated stuff of first two bean classes into the third one. Do you have any idea how to get it?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Can try somthing like this ... no need of class C ...


<cut value="${A.xy}" />
<cut value="${B.xy}" />

<c:set var="mult" value="${A.xy * B.xy}" scope="request" />
<cut value="${mult}" />
 
Swapna Gouri Kalanidhi
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Balu, will try this and let you know if I face any problems.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!