How <a4j:commandButton> works on RichFaces 4 - jsf-2

People,
I have an application with RichFaces 3 that works perfectly and i'm trying change to RichFaces 4.
The problem that could not solve involves the use of the .
On RichFaces 3, the below code works:
<a4j:commandButton value="button test" action="#{bean.executeAction()}" reRender="myForm"/>
I try change to
<a4j:commanButton value="button teste" action="#{bean.executeAction()}" render="myForm"/>
or
<a4j:commanButton value="button teste" actionListener="#{bean.executeAction()}" render="myForm"/>
or n others possibilities, however, nothing work.
Help please.

You could try to add the 'execute'.
<a4j:commandButton value="Button" type="submit"
id="button_1" render="myForm"
execute="#form"
action="#{bean.executeAction()}" />
This button works for me at least

Related

Change input based on combo value

I know this question exists somewhere else in SO but either the solutions are old (and JSF seems to have improved a lot) or I cannot make the solution work.
As simple as it sounds, I would like to replace the text of an input element based on the value of a combo box. I would like to use Ajax, and would like this to work even if there is only one element in the combo (it doesn't matter if by default the selection of the combo is empty).
<h:selectOneMenu id="fnamecombo" valueChangeListener="#{namesController.setForename(fnamecombo)}">
<c:forEach items="#{namesController.myForenames}" var="myforename">
<f:selectItem itemValue="#{myforename}" itemLabel="#{myforename}" />
</c:forEach>
<f:ajax render="fnameinput" />
</h:selectOneMenu>
<h:inputText value="#{namesController.forename}" id="fnameinput" />
This doesn't work. So first of all, I have no idea how to call the setForename method. If I use valueChangeListener="#{namesController.setForename('xxxxx')}" it works, but only the 1st time and iff there are more than one element in the combo, since otherwise the event does not seem to be fired.
What is the easy fix?
EDIT
Ok, so I have made progress. It was easier than I expected:
<h:selectOneMenu id="fnamecombo" value="#{namesController.forename}">
<c:forEach items="#{namesController.myForenames}" var="myforename">
<f:selectItem itemValue="#{myforename}" itemLabel="#{myforename}" />
</c:forEach>
<f:ajax render="fnameinput" />
</h:selectOneMenu>
<h:inputText value="#{namesController.forename}" id="fnameinput" />
This seems to work on a selectItem that I create by hand, but not on the one that is printing with the foreach loop. So this is the rendered code, where I obtained 'john' from the loop and I manually created 'example':
<select id="myForm:fnamecombo" name="myForm:fnamecombo" size="1" onchange="mojarra.ab(this,event,'valueChange',0,'myForm:fnameinput')">
<option value="example">example</option>
<option value="john">john</option>
</select>
It works with 'example' but not with 'john'.
Finally I got the answer.
<h:selectOneMenu id="fnamecombo" value="#{namesController.forename}">
<f:selectItems value="#{namesController.myForenames}" />
<f:ajax render="fnameinput" />
</h:selectOneMenu>
<h:inputText value="#{namesController.forename}" id="fnameinput" />
No need for forEach as mentioned by Alexandre Lavoie.
This answer by Luiggi Mendoza gave me the hint to find it out. The reason my input was not updated by the values in the f:selectItems and it was in the ones that I introduced manually is the scope of the managed bean. I realised that the input was actually being updated in any case, but when coming from the f:selectItems the input was updated with null. Why? Because the scope of namesController was #RequestScoped and not #ViewScoped. Changing this solves the problem.

<p:commandbutton> not working

i am new to JSF and primefaces.. i wrote a small code... i am getting what i want to do with "h:commandbutton" but samething is not working with "p:commandbutton". is there any difference between the functionality of these two things.
<h:commandButton value= "enter" actionListener= "#{newJSFManagedBean.show()}"/><br/>
<p:commandButton value= "enter" actionListener= "#{newJSFManagedBean.show()}"/><br/>
i have tried alot of things, but newjsfmanagedbean.show() havenot been called from p:commandbutton but h:commandbutton is working fine. what is the reason :-( ?
*hey it worked :-) *
thanxmates
<p:commandButton process="#this" value= "enter" ajax="false" actionListener= "#{newJSFManagedBean.show}" /><br/>
You didn't share your show() function but I can guess that it looks like below :
public void show(ActionEvent event) {
// some stuff here
}
Well, just delete your brackets in your EL language if you want to use it with primefaces :
<p:commandButton value= "enter" actionListener= "#{newJSFManagedBean.show}"/>
Otherwise it looks for a show method which does not have any parameters.
You should add process="#this" to p:commandButton to get its action invoked. If you want to process any other components add process="#this,id1,id2" like this.
Hope this helps

Richfaces tooltip not working with h:selectOneRadio

I would like to "bind" a tooltip to a h:selectOneRadio.
Following the example found here, I tried with
<td>
<h:selectOneRadio id="subscriptionType" value="#bean.subscriptionType}">
<f:selectItems value="#{beanModel.subscriptionTypeValues}" />
<rich:tooltip id="tt1" for="subscriptionType" layout="block" >
<span style="white-space: nowrap">
Data is for laptop, modem, ...<br />
Voice is for smartphone, ...
</span>
</rich:tooltip>
</h:selectOneRadio>
<h:messages for="subscriptionType" style="color:red; font-size:12px;" />
</td>
but the tooltip doesn't appear...
Do I miss something or it is not possible to use tooltips with radio buttons?
Problem solved.
I didn't see an error message at the bottom of the page saying
One or more resources have the target of 'body', but no 'body'
component has been defined within the view
So, after having googled for the error message I came to the solution posted here:
use h:body tag, instead of body
and now it works!

Issue with displaying Error message in a page having two forms

I am developing one JSF page, in that i am having two forms. And I am using rich:messages in both the forms.
Suppose, in the first form, if I don't enter any required fields and I click Save, then error messages are displaying twice in the page(as i am using rich:messages in two forms).
Is there any way so that error messages display with respect to the form?
Thanks in advance.
If you are using RichFaces 3.3.3.Final you can do it like so:
<a4j:form id="tmpfrm1">
<rich:messages />
<h:inputText value="#{mybean.intmp1}" required="true"/>
<a4j:commandButton value="save" action="#{mybean.test1}" reRender="tmpfrm1" limitToList="true" />
</a4j:form>
<a4j:form id="tmpfrm2">
<rich:messages />
<h:inputText value="#{mybean.intmp2}" required="true"/>
<a4j:commandButton value="save" action="#{mybean.test2}" reRender="tmpfrm2" limitToList="true" />
</a4j:form>
If you are uisng RichFaces 4 you need to replace the limitToList with limitRender and the reRender with render

grails calendar reset

I installed calendar Version 1.2.0-SNAPSHOT in grails and working good .
But facing one Issue :
When click on cancel button i was doing form reset .but the calendar field is becoming clear and not reseting to default date .
<g:form url="${response}" id="program" name="program" method="post">
<calendar:datePicker name="startDate" id="startDate" defaultValue="${program.startDate}" dateFormat="%Y-%m-%d"/>
<input type="button" id="cancel" name="cancel" value="Cancel" onclick = 'reset_form(this)' />
</g:form>
function reset_form(this_)
{
document.getElementById('program').reset();
}
any one have idea please ?
thanks.
Two ways to solve this issue as far as I can see. Either correct the typo inside your JavaScript and refer to the correct id of your form (program not new_program) or use the standard reset button for forms <input type="reset" .../> instead of your javascript solution.

Resources