PrimeFaces UI SelectOneButton - jsf-2

I am using Primefaces 4.0 with JSF 2.0
my requirement is to do some specific task behind (ON / OFF) selection button, my code is like
<h:form>
<h:panelGrid>
<p:selectOneButton value="#{buttonBean.number}">
<f:selectItem itemLabel="ON" itemValue="1" />
<f:selectItem itemLabel="OFF" itemValue="0" />
</p:selectOneButton>
</h:panelGrid>
</h:form>
for now UI and all is fine but, value is not passed on click to the bean which is buttonBean.number unless i submit it using a submit button.
My aim is to pass and set number = 0 and number = 1 by only click not submit it, where "0" is for Off and "1" is for On,

Another solution without submit
<p:selectOneMenu id="listFilter" value="#{sess.selectedFileId}">
<p:ajax update="mytable" listener="#{beanBacking.fileChanged()}" partialSubmit="true" />
<f:selectItem itemLabel="-- ALL --" itemValue="#{null}" />
<f:selectItems value="#{beanBacking.fileList}" />
</p:selectOneMenu>
<p:ajax /> learn p:ajax more HERE, from this page will not even refersh.

Related

f:param works only first time when using the same name in multiple commandButtons

My requierement is to upload some data and generate different reports for download with one click. In the example below I show appropriate button witch has a parameter that is sent to the download bean to select the correct version of the report.
But the f:param is only set the first time a p:commandButton is executed and then stays the same also for other buttons. Why is that and how can I solve this issue?
<h:form id="mainForm" enctype="multipart/form-data">
<p:fileUpload ...../>
....
....
<p:selectBooleanCheckbox id="opt1"
<p:ajax event="change" update="hiddingPanel"/>
</p:selectBooleanCheckbox>
<p:selectBooleanCheckbox id="opt2"
<p:ajax event="change" update="hiddingPanel"/>
</p:selectBooleanCheckbox>
<h:panelGroup id="hiddingPanel">
<p:commandButton id="doOpt1" rendered="#{bean.opt1 and !bean.opt2}"
actionListener="#{bean.readFile}" ajax="false" />
<p:fileDownload value="#{downloadBean.content}" />
<f:param name="reportType" value="REPORT1"/>
</p:commandButton>
<p:commandButton id="doOpt1" rendered="#{!bean.opt1 and bean.opt2}"
actionListener="#{bean.readFile}" ajax="false" />
<p:fileDownload value="#{downloadBean.content}" />
<f:param name="reportType" value="REPORT2"/>
</p:commandButton>
</h:panelGroup>
</h:form>
Thanks for any suggestions!
Regards.

ValueCangeListener work on second try in JSF 2.0

I have two selectOneMenu elements which their id's make difference only.
valueChangeListener works on second try.
At first try, page is refreshing, but does not go the valueChangeCode, thefore no value changes. At second try it goes valueChangeCode and it gets new value and both of selectOneMenu show new value.
<h:selectOneMenu id="changeCurrency" value="#dataBean.showCurrency}" valueChangeListener="#myBean.changePaymentCurreny}"
valueChangeListener="#{myBean.changePaymentCurreny}"
immediate="true"
onchange="submit()">
<f:selectItems value="#{my.currencyList}" />
</h:selectOneMenu>
<h:selectOneMenu id="changeCurrency2"
value="#{dateBean.showCurrency}"
valueChangeListener="#{myBean.changePaymentCurreny}"
immediate="true"
onchange="submit()">
<f:selectItems value="#{myBean.currencyList}" />
</h:selectOneMenu>
In ValueChangeListener code.
dataBean.setShowCurrency(newCurrency);
FacesContext.getCurrentInstance().renderResponse();
FacesContext.getCurrentInstance().getViewRoot().getChildren().clear();
When i remove the line which ends with getChidren.clear, and i change value of one them, changeListener called and changes the value at first try.
On view, only one selectmenu which i changed, shows new value. Other selectOnemenu still show the old value.
dataBean and myBean are in sessionScope. When i myBean put on requestscope, ajax request which works on page load, does not cath the mybean cause of being null.
Could anyone make clear this station.
Thanks very much.
try change the valueChangeListener for an ajax event tag like this.
<h:selectOneMenu id="changeCurrency" value="#dataBean.showCurrency}" valueChangeListener="#myBean.changePaymentCurreny}" onchange="submit()">
<f:selectItems value="#{my.currencyList}" />
<f:ajax event="change" listener="#{myBean.changePaymentCurreny}" process="#this" partialSubmit="true" />
</h:selectOneMenu>
<h:selectOneMenu id="changeCurrency2" value="#{dateBean.showCurrency}" onchange="submit()">
<f:selectItems value="#{myBean.currencyList}" />
<f:ajax event="change" listener="#{myBean.changePaymentCurreny}" process="#this" partialSubmit="true" />
</h:selectOneMenu>

rich:pickList Add/Remove Button not rendering a4j:outputpanel on first click

I am using richfaces 4.1 rich:picklist and need to render a4j:outputpanel on addition or removal of items in targetList. It renders outputpanel immediately on selecting Source/Target List elements but if directly click AddAll or RemoveAll button, output panel is not rendered on first click but renders onsecond click anywhere inside or outside screen.
Here is my code:
<rich:pickList value="#{myBean.selectedRegions}"
valueChangeListener="#{myBean.regionChangeListener}"
switchByClick="true" immediate="true">
<a4j:ajax event="additems" execute="#this" render="countryPanel" />
<a4j:ajax event="removeitems" execute="#this" render="countryPanel" />
<a4j:ajax event="sourceblur" execute="#this" render="countryPanel"/>
<a4j:ajax event="targetblur" execute="#this" render="countryPanel"/>
<a4j:ajax event="change" execute="#this" render="countryPanel" />
<f:selectItems value="#{myBean.regions}" var="region"
itemValue="#{region}" itemLabel="#{region.regionDesc}" />
<f:converter converterId="RegionConverter" />
</rich:pickList>
<a4j:outputPanel id="countryPanel" >
Upgrading to the latest RichFaces version should help. Also it would allow to simplify the code, you would need to specify only change event handler as the following issue has been fixed: https://issues.jboss.org/browse/RF-12360

update value: radio-button values togglig back and forth

I'm trying to update a a radio-componet, which is triggered by a onchange-event of a select-box. I see the radio-button toggling as desired after the onchange, but it automatically toggles back the next second.
<h:selectOneMenu id="selectId" value="#{someBean.someSelectValue}"
onchange="this.form.submit()" valueChangeListener="#{someBean.someChange}" immediate="true">
<p:ajax update="radioId"/>
<f:selectItems value="#{someBean.availableSraTitel}" />
</h:selectOneMenu>
<h:selectOneRadio id="radioId" value="#{someBean.someRadioValue}">
<f:selectItem itemLabel="Yes" itemValue="true" />
<f:selectItem itemLabel="No" itemValue="false" />
</h:selectOneRadio>
What am I missing here?
Jonny
Remove onchange="this.form.submit()" (the f:ajax will submit the value to the server)
Also remove immediate="true" (I don't think you really planning to skip any validations here)
Last thing, change <p:ajax update="radioId"/> into <f:ajax render="radioId"/>
p:ajax is from primefaces and you are using plain JSF components
As suggested by BalusC : You also better replace the valueChangeListener="#{someBean.someChange}" by adding listener="#{someBean.someChange}" to your f:ajax (you should change teh signature of the method too)

Cascade dynamic rendering selectOneMenu doesn't work

My problem I thougth is simple but I can't find a clear solution.
I have three selectOneMenu, and I want that the first one is always rendered, the second one is rendered if the first one has some value selected and the third one is rendered if the second has some value selected.
The relation between the first one and the second works well, but doesn't work between the second and the third.
When I change the value for the first selectOneMenu the second selectOneMenu is diplayed or hidden correctly.
But when I change the value for the second nothing happened to the third selectOneMenu, like if the f:ajax render isn't fired.
Bellow the jsf code:
<h:panelGrid columns="2">
<h:outputText value="Type Paiement" />
<h:selectOneMenu
value="#{employeurBean.idTypePaiement}">
<f:selectItem itemValue="" itemLabel="Choix typePaiement" />
<f:selectItems value="#{typePaiementBean.typesPaiement}" var="vtp"
itemLabel="#{vtp.libelle}" itemValue="#{vtp.idTypePaiement}" />
<f:ajax event="change" render="gmodp" />
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid id="gmodp">
<h:panelGroup rendered="#{employeurBean.idTypePaiement == 2}">
<h:outputText value="Mode Paiement" />
<h:selectOneMenu
value="#{employeurBean.idModePaiement}">
<f:selectItem itemValue="" itemLabel="Choix mode Paiement" />
<f:selectItems value="#{modePaiementBean.modesPaiement}" var="vmp"
itemLabel="#{vmp.libelle}" itemValue="#{vmp.idModePaiement}" />
<f:ajax event="change" render="grib"/>
</h:selectOneMenu>
</h:panelGroup>
</h:panelGrid>
<h:panelGrid id="grib">
<h:panelGroup rendered="#{employeurBean.idModePaiement == 1}">
<h:outputText value="Compte" />
<h:inputText value="#{employeurBean.compte}">
</h:inputText>
</h:panelGroup>
</h:panelGrid>
Is there any idea to achieve that.
Many thanks for your help
This construct will fail if the bean is request scoped and/or you're doing business actions (such as preloading the list) in getter methods instead of action listener methods. Ensure that the bean is been placed in the view scope and that you're doing business actions in action listener methods.
If that doesn't solve the problem, then you really have to post the backing bean code along the view code in your question.

Resources