File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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">
<h:selectOneListbox title="Choose your templateHeader: "
value="#{Content.templateHeader}" size="1">
<f:selectItem itemValue="templateHeader1" itemLabel="TemplateHeader1"/>
<f:selectItem itemValue="templateHeader2" itemLabel="TemplateHeader2"/>
<hutputText value=" " /><hutputText value=" " />
<h:commandButton value="send" action="#{Content.inTemplateHeaderBBDD}"></h:commandButton>
<h:selectOneListbox title="Choose your templateContent: "
value="#{Content.templateContent}" size="1">
<f:selectItem itemValue="templateContent1" itemLabel="TemplateContent1"/>
<f:selectItem itemValue="templateContent2" itemLabel="TemplateContent2"/>
<hutputText value=" " /><hutputText value=" " />
<h:commandButton value="send" action="{Content.inTemplateContentBBDD}"></h:commandButton>
<h:selectOneListbox title="Choose your templateFooter: "
value="#{Content.templateFooter}" size="1">
<f:selectItem itemValue="templateFooter1" itemLabel="TemplateFooter1"/>
<f:selectItem itemValue="templateFooter2" itemLabel="TemplateFooter2"/>
<hutputText value=" " /><hutputText value=" " />
<h:commandButton value="send" action="#{Content.inTemplateFooterBBDD}"></h:commandButton>

<h:commandButton value="Preview" action="#{Content.preview}"></h:commandButton>
<h:commandButton value="Continue" action="#{Content.continue1}"></h:commandButton>

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

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.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Trying send three values with just one button
It's not a secret anymore!