Glassfish complaining about JSF component IDs

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2010-06-16T15:45:29Z Indexed on 2010/06/16 16:12 UTC
Read the original article Hit count: 196

Filed under:

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":

<h:inputText styleClass="display" id="number01" size="4" maxlength="3" value="#{Calculator.number01}" />  
<h:inputText styleClass="display" id="number02" size="4" maxlength="3" value="#{Calculator.number02}" />  
<h:commandButton id="add" action="answer" value="+" />  

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

<h:outputText value="#{Calculator.answer}" />  

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:

<h:commandButton id="operation" action="answer" value="+" />       
<h:commandButton id="operation" action="answer" value="-" />  
<h:commandButton id="operation" action="answer" value="*" />  
<h:commandButton id="operation" action="answer" value="/" />  

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.

© Stack Overflow or respective owner

Related posts about jsf