• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Trying send three values with just one button  RSS feed

Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Posts: 19668
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!