• Post Reply Bookmark Topic Watch Topic
  • New Topic

trying to add a simple calculation in a bean

 
william chaple
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp that has a simple input, confirm, and process page (in that order). I am trying to add a simple calculation that will give it a fix price.
Example,

Please enter the processor you want: (fixed price of $200)
Please enter the GPU you want: (fixed price of 100$)
Please enter the tower you want: (fixed price of 50$)

How do I add the calculation in the bean? It does not have to be selective on the item, just adding up numbers per an input
. If I need accessor methods or something similar thats already in my bean
I would know how to do it in regular java, but not sure in JSP. Maybe I am over thinking it? I am just looking for someone to guide me along this. Not for an answer, but some tips


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're overthinking it.

Just add an accessor for a property that returns what you want.

For example:

And in the JSP: ${myBean.someValue}
 
william chaple
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You're overthinking it.

Just add an accessor for a property that returns what you want.

For example:

And in the JSP: ${myBean.someValue}



cool thanks I went and added the getter and setter and called it in my jsp but wont come out.

Was hoping maybe someone can take a careful look at my code to give me where the error lies? Let me know if that is ok and ill post the code. Thanks a bunch guys
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
william chaple wrote:cool thanks I went and added the getter and setter and called it in my jsp but wont come out.

Setter? For what? A calculated value would only need a getter.

Was hoping maybe someone can take a careful look at my code to give me where the error lies? Let me know if that is ok and ill post the code.


We can't do much if you don't. Please be sure to UseCodeTags and to post an SSCCE.
 
william chaple
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks ill keep it short and the basic. Sorry just trying to get the hang of this. Not sure why its not coming out in EL when its in the bean



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the bean established in scope? What is "helper.data"? What is "help.data"? Why are they different?

What's not working? Getting an error? Incorrect data? No data? Flaming keyboard?
 
william chaple
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol @ flaming keyboard

helper.data is the correct EL. I am just trying to show that the cpu is 200$ on the jsp and to confirm it is correct on the next page they click

This is my Controller Helper which extends helperbasech4 from another package that grabs loggers and stuff and inputs the data into a log



this is my actual controller where is gets method helper




 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${helper.data.cpu} <-- I see no accessor (getter) for a property named cpu.
 
william chaple
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh no it is there, I just cut the code a bit shorter to focus on why it is not displaying the amount of cost. I have a jsp page saying what computer you want "input from user as text" but trying to add the calculation method but its not displaying and cant figure out why


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
william chaple wrote: but trying to add the calculation method but its not displaying


Be explicit: what EL expression are you using that is not evaluating?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!