How to use ajax in JSF inputtextbox to update h:selectOneRadio? - ajax

I was usinig JSF 2.0, richfaces, and a4j in my development. I have a radio button group that consist of 3 radio button, and there is a inputtextbox next to each of the radio button, just like the layout shown below:
radio button A | input textbox A
radio button B | input textbox B
radio button C | input textbox C
Whenever there is a focus on textbox, can this be done using ajax to update on radio button selection? E.g. when focus on input textbox B, then radio button B will be selected. May I know how this can be done?

There are many ways to this, first using plain javascript and using ajax on jsf or richfaces components.
You can try using a4j:ajax nested inside your h:inputText and fire it whenever there is focus on your textbox.
<h:selectOneRadio value="#{bean.value}" id="radio" />
<h:inputText id="input" value="#{bean.textValue}" >
<a4j:ajax event="onfocus" render="radio" action="{bean.setRadioSelected}"/>
</h:inputText>
On the action method set the value of selected radio to true.
Hope this helps.

Related

JSF validate dialog form

I have a dialog form popup when I click one button, this form is used to create a new school record with just one field.
I have add required validation to this only input field, and everything works fine, but the only thing I don't know how to do is when I click submit, whatever form validate or not, the dialog will dismiss by following code:
initDataTable();
// Dismiss the dialog
$('#dialogNewSchool').dialog('close');
before the dialog close, I should put the form validation check (something like the return from validation class), how I can do this in javascript? I'm using JSF 2.1 implementation.
Btw, I don't want to use client side validation, because not only required validation needed for this field.
Thanks. ;)
If I got you right you want to keep dialog open in case of validation errors?
Than you can add the following code somewhere in your page
<h:panelGroup id="global_flag_validation_failed_render">
<h:outputText id="global_flag_validation_failed" value="true" rendered="#{facesContext.validationFailed}"/>
</h:panelGroup>
And upon clicking your submit button render the above block like this:
<f:ajax onevent="closeMyDialogIfAllOk" render="#form global_flag_validation_failed_render"></f:ajax>
and in your js code
function closeMyDialogIfAllOk(data){
if(data.status === 'success') {
if($("#global_flag_validation_failed").length === 0){
$("#dialog_id").dialog("close");
}
}
}
For more info take a look over here: How to find indication of a Validation error (required=“true”) while doing ajax command

Passing of values of selected radio buttons which are added dynamically by a servlet to a jsp

I have added dynamically some radio buttons to a jsp page.
Now i need to use the unique id of the selected radio button,pass it to some other servlet to process it?
How can it be done?
Place all of your radio buttons within a form that submits to your servlet. Make sure that each of your radio buttons name attributes is set to the same value. Also set the value attribute of each radio button to its respective id. When your form submits, it will pass the value of the selected radio button to the servlet. You can then retrieve the value using request.getParameter().
For more information review this tutorial. http://www.roseindia.net/jsp/radio-button-jsp.shtml

How to disable data annotation required field validator in MVC

I am trying to design a page that has two radio button options and two text boxes with each radio button. I am validating these text boxes using data annotation validation attribute.
I am using jquery slider.toggle() to display each text boxes according to the radio button clicked. When i submit the page, required field validators of both text boxes are triggered. What I want to do is to disable the first text box validation when the second radio button is clicked.
Is there any method in MVC to disable the validation of text boxes when the radio button associated to it is not selected?
This can be done rather simply front end. The validation which occurs is done based on html5's data attribute. Remove the data attributes from an input element and the validation will cease to function.

How can I make h:inputText appear only after button clicked in JSF2.0?

In jSF2.0 How can I make an <h:inputText> appear only after a specific button is clicked? I want the <h:inputText> be hidden, and only appear after I click a button
Could you simply use CSS "display: none" attribute on inputText and, in button onclick attribute, to change this for "display: block". This is the more simple solution.

Richfaces combobox on selection changed event

I have this code:
<richfaces:comboBox
value="#{ChoixContratBean.selectedFormule"}
suggestionValues="#{ChoixContratBean.formules}">
<a4j:support event="onmouseover"
action="#{ChoixContratBean.getDescriptionFormule}"
reRender="reponse" />
</richfaces:comboBox>
I would like that when the user hovers with the mouse the different values in the combo, a new description of the product appears in :
<jsf:outputText
id="reponse"
value="#{ChoixContratBean.descriptionFormuleSelected}" />
No event is triggered when the mouse hovers the richfaces combo values; instead, the event that is triggered is the simple mouseover on the combo itself.
What must I to do have the values receive the event trigger?

Resources