This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes Trying send three values with just one button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Trying send three values with just one button" Watch "Trying send three values with just one button" New topic
Author

Trying send three values with just one button

Dura Hurtado
Ranch Hand

Joined: Feb 16, 2011
Posts: 120
Hi I am trying that in a .xhtml page in which there are three combos each one sends it´s value to the bean, it works well with a button in each of them.

But I am looking for just one button which sends all of the values together.

The code is as follows:

[i]<p:panel header="m">
<center>
<h:selectOneListbox title="Choose your templateHeader: "
value="#{Content.templateHeader}" size="1">
<f:selectItem itemValue="templateHeader1" itemLabel="TemplateHeader1"/>
<f:selectItem itemValue="templateHeader2" itemLabel="TemplateHeader2"/>
</h:selectOneListbox>
<hutputText value=" " /><hutputText value=" " />
<h:commandButton value="send" action="#{Content.inTemplateHeaderBBDD}"></h:commandButton>
<br></br><br></br>
<h:selectOneListbox title="Choose your templateContent: "
value="#{Content.templateContent}" size="1">
<f:selectItem itemValue="templateContent1" itemLabel="TemplateContent1"/>
<f:selectItem itemValue="templateContent2" itemLabel="TemplateContent2"/>
</h:selectOneListbox>
<hutputText value=" " /><hutputText value=" " />
<h:commandButton value="send" action="{Content.inTemplateContentBBDD}"></h:commandButton>
<br></br><br></br>
<h:selectOneListbox title="Choose your templateFooter: "
value="#{Content.templateFooter}" size="1">
<f:selectItem itemValue="templateFooter1" itemLabel="TemplateFooter1"/>
<f:selectItem itemValue="templateFooter2" itemLabel="TemplateFooter2"/>
</h:selectOneListbox>
<hutputText value=" " /><hutputText value=" " />
<h:commandButton value="send" action="#{Content.inTemplateFooterBBDD}"></h:commandButton>
<br></br><br></br>

<h:commandButton value="Preview" action="#{Content.preview}"></h:commandButton>
<br></br><br></br>
<h:commandButton value="Continue" action="#{Content.continue1}"></h:commandButton>
<br></br>
</center>
</p:panel>
[/i]


Then instead of using the three buttons in bold, I am looking to send all the values with one button.

Thanks for reply.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

Dora, I think you clicked the "Italics" button instead of the "Code" button in your message editor.

When you click a commandButton or commandLink, an HTML FORM submit is issued. In HTML, every control within that form has its value returned to the server as part of the form request (there's some qualification to that statement, but it's basically correct).

If you place 3 buttons on one form, the all the data items (dropdown SELECT values) still all get sent, regardless of which button was clicked, so what you want is actually automatic.

JSF, of course, is not straight HTML, so there's some additional considerations.

1. Since JSF validates requests, all controls on the submitted form must pass validation or the backing bean won't be updated. So either all 3 values will be set via the "set" methods of the backing bean or nothing will update and the action method will not be called.

2. You have 3 buttons, each of which has a corresponding action method. JSF will invoke the method that corresponds to the button that was clicked. All 3 values from the selectOneListbox controls will have been set, regardless of which button was clicked, however.

Other than that, the only other consideration is that you're giving your backing bean instance name an initial capitalized letter. By convention, you shouldn't do that for instances, only for Classes. When you use JSF2 annotations, the generated instance name will reflect that convention automatically.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
Consider Paul's rocket mass heater.
 
subject: Trying send three values with just one button
 
Similar Threads
Problem using valueChangeListener and onchange
JSF - Missing source code using templating and composition
Navigation problem
drop down list question
Newbie selectOneListBox question