Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling Action class from Radio and AJAX  RSS feed

 
Raj Shekar H
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My scenario is .. I do have a group radio buttons as one of the columns . When I select I need not only chnage the radio button value but also DB value .
I am able to get the value of primary ONLICK when using h:selectRadio . IS there any tag I can do a call to action calls and update the DB. ( i can use the hidden variable for the Primary key ) .

<h:selectOneRadio

value="#{xxxxxxxxxxx.flag}"
onclick="example(this); id="id"
title="tFlag">
<f:selectItem itemValue="#{example.Flag}" />
</h:selectOneRadio>

Let me know should i add any more tags / can i use h:selectOneRadio extensively


Thanks,
Rj
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Radio buttons are sets of controls attached to a single value (backing bean property, in JSF). Only one button can be "down" at any given time and each button has a different selection value, so the value of the target property is determined by which radiobutton in the set has been selected. The whole thing is modelled after old-time mechanical automobile radios, and I cannot recall any modern-day physical devices that act like that, but they were still around when GUIs were new, so they were more intuitive back then.

Actually, I have a 4-port KVM device that's kind of like that, but the buttons don't mechanically pop in and out. Instead an associated LED lights up depending on which of the 4 computers I have selected. That's about as close as I can get.

Anyway, since the web isn't a continuous communications process, actually click-selecting a button doesn't trigger any application action. It just updates the GUI display. To get application action, the form containing the button controls has to be submitted.

You can do that in one of 2 ways. A Full form submit submits every input control's current value to the JSF lifecycle process on the server and is triggered by a commandButton or commandLink firing on the client.

A Partial form submit is just like a Full form submit, except that only selected input controls get submitted instead of every control on the form that contains them. A partial form submit is done by an AJAX request, and instead of an action method, an AjaxListener method will be invoked if the inputs are valid and posted to the backing been by JSF.

So if you wish a database table to update immediately on selection of a radiobutton, add an f:ajax tag to the control and write an Ajax action listener method to your backing bean. The listener method can then take the backing bean property value that was posted and write it out to your database in the usual way of communicting with databases.

Incidentally, onclick does not communicate with the server. It is for client-side javascript code that is to be executed when the control is clicked on. In order for it to initiate server-side processing, it would have to invoke a form submit. AJAX can do that in a much easier way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!