Forums Register Login

A Very Newbie JSF Question

+Pie Number of slices to send: Send
Hello All

I am very new to JSF (v2.0) and I am attempting to learn it at places like netbeans.org and coreservlets.com. I am working on a very simple "add/subtract/multiply/divide" Java webapp and I have run into a problem. When I first started out, the application was enter two numbers and hit a '+' key and they would be automatically added together. Now that I have added more complexity I am having trouble getting the operation to the managed bean. This is what I had when it was just "add":



For the "answer" page, I displayed the answer like this:



I had the proper getters and setters in the Calculator.java managed bean and the operation worked perfectly.

Now I have added the other three operations and I am having trouble visualizing how to get the operation parameter to the bean so that I can switch around it. I tried this:



However, Glassfish complained that I have already used "operation" once and I am trying to use it four times here.

Any adivce/tips on how to get multiple operations to the managed bean so that it can preform the desired operation?

Thank you for taking the time to read.
+Pie Number of slices to send: Send
Hi John Douglas.

I've tried to test something like you do and I got the error: javax.servlet.jsp.JspException: Duplicate Id Found:operation
on Tomcat 6.
So we can't declare more than one component to have the same id.

There is some solutions such as using parameters to be sent with URL or setting attribute values for your commandButton components. For more details using these kind of solutions take a look at: Communication in JSF - From BalusC

But I prefer to define an action method for each operation inside the Calculator bean so it can do the right operation, hold the result in some Calculator attribute and then return the outcome string "answer".

I wrote something to give you some example:

Code for the jsp.


Code for the managed bean:
+Pie Number of slices to send: Send
Wow ... thank you for the detailed response. I feel it's going to take me forever to pick this up.
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 903 times.
Similar Threads
Cant store data in database table Hibernat/Spring/JSF
how to add a row dynamically in panel grid by clicking on command button using jsf
ajax and required field problem
Using Oracle sequence with JBOSS
Replacing inputText with buttons
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:49:06.