on a form : i have one page include two tab.
Tab rendered some boolean values.
e)
after first page i have command buton . Yes or no( its reset booelan value)
if ı click yes second page rendered true and page show but all values reset. All data reset ? What is problem ? How can i solve this.
All code is here :http://pastebin.com/Ffi33hdw
Uptade buton line 287 .
<h:selectOneRadio id="fikirorProje" required="true" value="#{ideaBean.newIdea.fikirProje}"
enabledClass="labelNormalRadio" disabled="#{ideaBean.createdIdea}"
requiredMessage="Bu alan boş bırakılamaz.">
<f:selectItem itemValue="#{false}"
itemLabel="Hayır" uptade="butonThree"/>
<f:selectItem itemValue="#{true}" itemLabel="Evet"/>
<p:ajax event="change" update="addIdeaForm" />
<p:ajaxStatus onstart="PF('status').show()" onsuccess="PF('status').hide()"/>
</h:selectOneRadio>
thans for answering
Theprocess attribute of p:ajax defaults to #this, so in the change event of your h:selectOneRadio your form is not being fully process which means that the ideaBean's properties will not be updated, (check more info about how update/process work here). Add process="#form" to your ajax event <p:ajax event="change" update="addIdeaForm process="#form" /> and it should work
Related
I'm using JSF 2 and Primefaces 4 and have the following issue:
I've got the following code in my XHTML:
<h:form id="form">
<table>
<tr id="formats">
<td>Formats</td>
<td>
<p:selectBooleanCheckbox value="#{bean.entity.formatted}">
<p:ajax event="change" update="formatsSelect" />
</p:selectBooleanCheckbox>
<p:selectOneMenu id="formatsSelect" rendered="#{bean.entity.formatted}">
<f:selectItems value="#{bean.formats}" />
</p:selectOneMenu>
</td>
</tr>
</table>
</h:form>
It outputs a checkbox and a select menu and what I expect is that when I check the checkbox the select menu should appear and should disappear when I uncheck it.... but nothing happens, I check and uncheck it and the select menu is unaffected.
In theory this should work since the selectBooleanCheckbox value is bound to the entity.formatted boolean value and the rendered value in the selectOneMenu is bound to the entity.formatted value and the p:ajax points to the correct id in the update attribute and the event is correct. This last bit I know since I created a listener in my bean that printed the value of formatted:
public void changeListener(){
System.out.println(this.entity.isFormatted());
}
And changed the p:ajax to:
<p:ajax event="change" update="formatsSelect" listener="#{bean.changeListener}" />
And it printed the value of formatted in the console.
What am I doing wrong?
Since you used rendered on the component (p:selectOneMenu id="formatsSelect") and updating the same component, it wont work.
Because that component might not have been added to/present in component tree by the time you are updating.
So use a h:panelGroup around it and update it and use rendered on p:selectOneMenu.
<p:selectBooleanCheckbox value="#{bean.entity.formatted}">
<p:ajax event="change" update="formatsSelectPG" />
</p:selectBooleanCheckbox>
<h:panelGroup id="formatsSelectPG">
<p:selectOneMenu id="formatsSelect" rendered="#{bean.entity.formatted}">
<f:selectItems value="#{bean.formats}" />
</p:selectOneMenu>
</h:panelGroup>
I'm using an p:selectOneRadio with p:ajax and the value of another component (p:inputText), not binding its value in my bean.
If I use p:selectBooleanCheckbox instead the behavior is exactly what I need, update the bean before calling the method in ajax. Is this a bug in p:selectOneRadio or is this its default behavior?
I'm using JSF2, PrimeFaces 4
The xhtml code:
<p:selectOneRadio id="enumId" value="#{xyzController.entity.enumValor}"
disabled="#{disabled}" required="true" plain="true">
<f:selectItems value="#{xyzController.enum}" var="item"
itemLabel="#{messages[ELUtils.evaluateExpression(itemLabelEL)]}"
itemValue="#{item}" />
<p:ajax event="change" listener="#{xyzController.aoTrocar}"
update="panelDominioFields" process="#form" />
</p:selectOneRadio>
<p:outputPanel layout="inline" id="panelDominioFields">
<p:inputText id="valorId"
value="#{xyzController.entity.valorNumericoValido}"
rendered="#{xyzController.mostrarCampoDominioNumerico}"
required="true">
<f:convertNumber type="number" locale="#{localeController.locale}"
currencyCode="#{localeController.currencyCode}" />
</p:inputText>
</p:outputPanel>
Get rid of event="change", it's the wrong event. It defaults to click and is the right one already.
<p:ajax listener="#{xyzController.aoTrocar}"
update="panelDominioFields" process="#form" />
Radio button values never change. They're only selected by click. In turn, selected values are submitted, but unselected values not.
I have a jsf page that adds an order from a client.
All works fine except when I click the commandLink to show the p:dialog to add a new client the update on the "reste" inputtext stop working (even if I close the p:dialog without adding the new client) :
Clients List :
<strong>Client :</strong><
<p:autoComplete
id="client"
value="#{venteSolaireBean.client}"
completeMethod="#{venteSolaireBean.autocompleteClient}"
var="item"
itemLabel="#{item.nom} #{item.prenom}"
itemValue="#{item}"
converter="#{venteSolaireBean.clientConverter}"
dropdown="true"
scrollHeight="200" >
</p:autoComplete>
Link to a p:dialog to add a new Cleint :
<p:commandLink onclick="dlgClient.show()" immediate="true">
<img src="images-main/add-icon.gif" border="0" alt="Add Client" class="img-action"/>
</p:commandLink>
Three p:inputtext items with ajax behavior :
<strong>Montant :</strong>
<p:inputText value="#{venteSolaireBean.venteSolaire.montant}">
<p:ajax event="keyup" update="reste" listener="#{venteSolaireBean.calcul}" />
</p:inputText>
<strong>Avance :</strong></td>
<p:inputText value="#{venteSolaireBean.venteSolaire.avance}">
<p:ajax event="keyup" update="reste" listener="#{venteSolaireBean.calcul}" />
</p:inputText>
<strong>Reste :</strong></td>
<p:inputText id="reste" value="#{venteSolaireBean.venteSolaire.reste}">
</p:inputText>
The venteSolaireBean.calcul function to execute with the listener :
public void calcul() {
venteSolaire.setReste(venteSolaire.getMontant() - venteSolaire.getAvance());
}
I checked by logging the calcul() function and I'm sure it was invoked and the value giving to setReste() is correct.
I don't see why inputtext didn't update.
please help.
I think that there are some problems with the validation. As immediate=true often leads to such problems and you are not using any primefaces-functionality on the button to show the dialog, you should replace the p:commandButton with a plain HTML button to show the "add client"-dialog.
I have a small (but vital) problem with JSF and ajax. The form is here:
<h:form>
<h:panelGrid id="pg1" columns="2">
<h:outputText value="Type: "/>
<h:selectOneMenu id="selectOne" value="#{personBean.type}">
<f:selectItems value="#{listBean.personTypes}"/>
<f:ajax event="valueChange" render="pg2"/>
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid id="pg2" columns="2">
<h:outputText value="Really bad?" rendered="#{personBean.type=='BAD'}"/>
<h:selectBooleanCheckbox id="checkbox" value="#{personBean.reallyBad}" rendered="#{personBean.type=='BAD'}">
<f:ajax event="click"/>
</h:selectBooleanCheckbox>
</h:panelGrid>
<h:commandButton value="Ajax Submit" action="#{personBean.printValues}">
<f:ajax execute="#form"/>
</h:commandButton>
</h:form>
The PersonBean is a simple bean with an enum PersonType that has two values: NICE, BAD and a Boolean called reallyBad. The ListBean returns the enum values in a list to populate the selectOneMenu.
Basically when I select BAD the panel for the boolean checkbox is rendered where I can tick it to say a person is reallyBad. I can then submit the form if I wish. The problem is when I tick the checkbox and then select NICE again, the checkbox is still ticked even though it is not rendered. So when I submit my form the person can be NICE and reallyBad, which doesn't make sense.
Rather than having to select BAD again to uncheck the box, is their a way that I can reset the checkbox and its input value to false when NICE is selected? I'm a bit of a noob to ajax with JSF! Thanks.
ps. I am printing the values of the two inputs on submit with the commandButtons action to verify the results...
You need to manually clear the checkbox when you change the menu.
<f:ajax listener="#{personBean.setReallyBad(false)}" render="pg2" />
By the way, the both <f:ajax event> values as you've in your code are the default values already. Just omit them.
I'm using RichFaces' a4j:support to toggle the visibility of some controls on the page. However, when the h:selectOneRadio button rdoRequestType is changed, it clears the values of the txtLibraryServerNumber and other controls in the a4j:outputPanel with ID "media". Why would one AJAX call on a page interfere with a different AJAX panel?
I've tried using the "process" attribute on the a4j:support tag on the selectOneRadio so it writes the values of the text boxes in the other panel to the Seam bean, but that has no effect. What the heck am I doing wrong? Help! I'm losing my mind!!
<h:selectOneRadio value="#{webencode.requestType}"
id="rdoRequestType" styleClass="radio" style="width:295px" layout="pageDirection" >
<f:selectItem itemValue="program" itemLabel="Series or Individual Program"/>
<f:selectItem itemValue="promo" itemLabel="Promo" />
<f:selectItem itemValue="specific" itemLabel="Specific Format Encoding Request"/>
<a4j:support ajaxSingle="true" event="onclick" reRender="program" process="txtLibraryServerNumber,txtDigitalMediaFileName"/>
</h:selectOneRadio>
<a4j:outputPanel id="program" ajaxRendered="true">
<s:span rendered="#{('program' == webencode.requestType || 'promo' == webencode.requestType) ? true : false}">
<h:selectOneMenu value="#{webencode.seriesId}" id="lstSeriesName">
<f:selectItems value="#{webencode.programItems}"/>
</h:selectOneMenu>
</s:span>
<s:span rendered="#{'specific' == webencode.requestType ? true : false}">
<h:selectOneMenu value="#{webencode.arrVideoEncodings.get(0).videoEncoding}"
id="lstSpecificVideoEncoding1" style="width:295px;">
<f:selectItems value="#{webencode.videoEncodingItems}"/>
</h:selectOneMenu>
</s:span>
</a4j:outputPanel>
<h:selectOneMenu value="#{webencode.inputMediaType}"
id="lstInputMediaType">
<f:selectItems value="#{webencode.inputMediaTypeItems}"/>
<a4j:support ajaxSingle="true" event="onchange" reRender="media" process="lstSeriesName,lstSpecificVideoEncoding1"/>
</h:selectOneMenu>
<a4j:outputPanel id="media" ajaxRendered="true">
<s:span rendered="#{'Tape Library # or Server ID #' == webencode.inputMediaType ? true : false}">
<h:inputText id="txtLibraryServerNumber"
value="#{webencode.libraryServerNumber}" maxlength="50" />
</s:span>
<s:span rendered="#{'Digital Media File Name' == webencode.inputMediaType ? true : false}">
<h:inputText id="txtDigitalMediaFileName"
value="#{webencode.digitalMediaFileName}" maxlength="195" /><br />
</s:span>
</a4j:outputPanel>
If you have the UpdateMode property of the panel set to "always" it will update with any postback occurs. If you set it to "conditional" it will only update when one of it's own triggers causes a postback.
I don't know if this would clear your controls, but it is a possible answer to why one panel is effecting another.
What is the scope of your Webencode bean? It will have to be Page or longer or your values will be lost with each call. Remember that if you don't specify a scope it defaults to Request and each Ajax call is a Request.
Your media panel is always being refreshed as you've specified it with the ajaxRendered attribute which is like saying "even if I'm not asked to be reRendered, reRender me always anyway." Unless you have a good reason to use ajaxRendered (eg. something that is always rendered like status messages), then you are better off starting with explicity specifying what to reRender.
The process attribute isn't necessary here - get rid of it.
Cheers,
D
Found the solution: Very strange, but on the server, which is running Apache with JBoss, it needs to have the limitToList attribute set to true:
<a4j:support ajaxSingle="true" event="onchange" reRender="media"
limitToList="true"/>
This ensures only the control indicated (in this case "media") is re-rendered. Still don't know why it's required on the server but not on the localhost. Gotta be something with Apache and how it communicates with JBoss, but not sure.