ajax event not working - primefaces

I have a form that should appear when the checkbox is true. This won't work. weird thing is : I did exactly the same on another page and there it works. Also when using another boolean property in the backing bean itself it works.
<div class="field">
<p:outputLabel for="company" value="Company" />
<p:selectBooleanCheckbox id="company" value="#{participantDetailBean.participant.isCompany}">
<p:ajax event="change" update="companyFields"/>
</p:selectBooleanCheckbox>
</div>
<p:outputPanel id="companyFields">
<div class="field">
<p:outputLabel for="companyname" value="Company name" rendered="#{participantDetailBean.participant.isCompany}" />
<p:inputText id="companyname" value="#{participantDetailBean.participant.companyName}" rendered="#{participantDetailBean.participant.isCompany}" />
</div>
<div class="field">
<p:outputLabel for="companyform" value="Company form" rendered="#{participantDetailBean.participant.isCompany}" />
<p:inputText id="companyform" value="#{participantDetailBean.participant.companyForm}" rendered="#{participantDetailBean.participant.isCompany}" />
</div>
<div class="field">
<p:outputLabel for="companynumber" value="Company number" rendered="#{participantDetailBean.participant.isCompany}" />
<p:inputMask id="companynumber" value="#{participantDetailBean.participant.companyNumber}" mask="aa 9999.999.999" rendered="#{participantDetailBean.participant.isCompany}" />
</div>
</p:outputPanel>

Sometimes Primefaces has its moments when components that works on one page, simply refuses to work on another page. The code you've posted in your example is correct and most likely if you place a break point on the company getter, when the ajax event change is triggered, the value will update correctly. What's happening is that your component is not refreshing correctly via the ajax (or is not recognized).
A workaround solution that I found is to this scenario is to include JSF's PanelGroup inside the OutputPanel. I used the base of your code and made the below example (obviously replacing tags I have in my project with the objects as per your example.
<div class="field">
<p:selectBooleanCheckbox id="company"
value="# {participantDetailBean.participant.isCompany}">
<p:ajax event="change" update=":companyFields"/>
</p:selectBooleanCheckbox>
</div>
<p:outputPanel id="companyFields">
<h:panelGroup id="companyFields2" rendered="#{participantDetailBean.participant.isCompany}">
<div class="field">
<p:outputLabel value="DISPLAY THIS FIELD"/>
</div>
</h:panelGroup>
</p:outputPanel>
Whilst this is not the cleanest solution, it might help you get out of the rut you're currently stuck in, or guide you in obtaining the correct answer. Oh, and don't forget to include the JSF include tag when using PanelGroup
xmlns:h="http://xmlns.jcp.org/jsf/html"

Try to use the itemSelect event.

Related

How to make all dataTable columns inputs readOnly

i have a <p:datable> with <p:column> , inside each column i have a <p:inputTex>..
i'm wondering if there is a way to make all these <p:inputTex> readOnly without doing that manually (readOnly="true" for each <p:inputTex>) because i have a lot of columns..
thanks in advance
The OnmiFaces massAttribute is designed specifically for this.
From their showcase (slightly adapted for this case):
<o:massAttribute name="readonly" value="#{formBean.shouldBeReadonly}" target="javax.faces.component.UIInput">
<h:outputLabel for="input1" />
<h:inputText id="input1" />
<h:outputLabel for="input2" />
<h:inputText id="input2" />
<h:outputLabel for="input3" />
<h:inputText id="input3" />
</o:massAttribute>
The target attribute is to make sure only input components are, well... targeted and not the outputs or other components. You can also use a static value of 'true' instead of referencing a getter in a bean.

PrimeFaces: selectOneButton is cleared on validation error

I have a wizard tab and a few fields in it. Some of them are required.
There is also a selectOneButton. The problem is when I have some required fields empty and some value selected in selectOneButton - when the validation fails on form submit, it gets "unclicked", i.e. nothing is selected. I suspect that the whole form gets updated but other components still hold the visible value.
What am I doing wrong or maybe someone have had the same problem?
I use PrimeFaces-5.0.RC2
Here is the code:
<p:tab title="Service params" id="firstTab">
<h:panelGrid columns="2">
Name *
<p:inputText value="#{serviceMB.service.name}" label="Name" required="true" maxlength="150"/>
Unit
<p:selectOneButton value="#{serviceMB.service.unit}" converter="serviceUnitConverter"
filter="true" filterMatchMode="contains" label="Unit"
id="unitMenu"
required="true">
<f:selectItems value="#{serviceMB.allServiceUnits}" var="unit"
itemLabel="#{unit.name}"
itemValue="#{unit.code}"/>
<p:ajax event="change"
update=":addServiceForm:priceListPanel"
process="#this"/>
</p:selectOneButton>
</h:panelGrid>
<p:commandButton value="Next" icon="ui-icon-triangle-1-e" iconPos="right" type="button" onclick="PF('serviceWizard').next();"/>
So Unit is the component which value is cleared. I really have no idea why, so I moved to selectOneMenu instead which is less preferable in my case.

Primefaces Tabview resetting inputs

I use primeface 3.5. I have a tabview and each tabview has got inputMasks with a form. I want to reset inputMask when i change the tab. I listen ontabchange event and reset value to="" but bean reset values but View doesn't reset.
<p:tabView id="tabViewOS" binding="#{docData.tabView}" dynamic="true" cache="true" rendered="#{userData.opRendered}">
<p:ajax event="tabChange" listener="#{docData.onTabChange}" immediate="true"/>
<p:tab id="tab1" title="AB">
<h:form id="ABForm">
<h:panelGrid id="abgrid" columns="3" cellpadding="5">
<h:outputText value="AB NO: " />
<p:inputMask value="#{docData.abNo}" mask="999-99999999"
id="ABinput" required="true"
</p:inputMask>
<p:message id="msgAB" for="ABinput" showDetail="true" autoUpdate="true" />
<h:outputText value="" />
<p:commandButton value="GETİR" style="float:right;" ajax="false"
action="#{docData.getDoc}" />
</h:panelGrid>
</h:form>
</p:tab>
public void onTabChange(TabChangeEvent event) {
this.activeTabIndex = tabView.getChildren().indexOf(event.getTab());
FacesContext.getCurrentInstance().renderResponse();
System.out.println(this.activeTabIndex);
this.abNo="";
documents.clear();
}
Try changing the way the event is called. Instead of immediate=true use process="#this".
Change this:
<p:ajax event="tabChange" listener="#{docData.onTabChange}" immediate="true"/>
To this:
<p:ajax event="tabChange" listener="#{docData.onTabChange}" process="#this" update="ABinput"/>
i guess as you said -dynamic="true" cache="false">- is solve my problem. Actually I tested program faulty, my problem has already solved. I think in my case cause of this situation cache=false as documentation said. Thank you.
Have a look at the primefaces documentation on p:tabView. On the one hand you have the property dynamic which specifies if the content of a tab is loaded with AJAX when you select some tag. On the other hand there is the property cache which specifies wheter or not the content of a tab is only dynamically loaded the first time you select a tab.
So regarding this informations setting dynamic="true" cache="false" on the p:tabView should do the trick for you.
Another interesting property for you would be activeIndex. As I see you are setting the index of the active tab manually on tab change. If you can submit tabview on tabchange and you have set activeIndex="#{docData.activeTabIndex}" the active tabindex is tracked automatically. Have a look at the documentation if this fits your requirements.

ui:repeat and c:foreach dont return the same organisation

I have a loop that contains a list of properties
I would like to display this list on 2 columns, but I can not.
  they are displayed by unordered, against if I use c: For Each place of ui: repeat
the problem is resolved
<p:panel id="panlecart2" header ="Caracteristique selon la categorie" toggleable="true" rendered="true" style="width=900px;">
<h:panelGrid id="panlecart" columns="2" cellpadding="5" rendered="true" style="width=900px;">
<ui:repeat var="var1" value="#{composantbean.categorie.proprietes.toArray()}">
<h:outputText value="#{var1.nomProp }(#{var1.unite} )" />
<h:inputText value="" />
</ui:repeat>
</h:panelGrid>
</p:panel>
Haw can I fixe the problem .helpe please :)
You could switch to using <h:dataTable> to iterate over the components:
<h:dataTable var="var1" value="#{composantbean.categorie.proprietes.toArray()}">
<h:column>
<h:outputText value="#{var1.nomProp }(#{var1.unite} )" />
</h:column>
<h:column>
<h:inputText value="" />
</h:column>
</h:dataTable>
Enclose it within a <p:panel> to make it work. Otherwise, make use of <c:forEach> as it's a good fit for your use case.
ui:repeat is rendered in a later phase than c:forEach. Here's an explanation.
c:forEach is the way to go here, since this is invoked in view build time.
ui:repeat is invoked during view render time, so p:panel would have no knowledge of the data being created by ui:repeat.

overlaypanel primefaces doesnt work fine inside dialog inside tabview

I use the dynamic overlayPanel of primefaces inside one p:tab inside one p:dialog like this :
<p:dialog id="dialog" modal="true" header="Nouveau Article"
widgetVar="dlg">
<h:form prependId="false" enctype="multipart/form-data">
<p:tabView id="monpanel">
<p:tab id="tab1" title="Informations">
....
</p:tab>
<p:tab id="tab2" title="Prix">
....
</p:tab>
<p:tab id="tab3" title="Stock et fournisseurs">
<h:outputLabel value="" /><h:outputLabel value="" /><h:outputLabel value="" />
<p:commandButton id="carBtn" value="Selectionner Fournisseurs" type="button" />
<p:overlayPanel appendToBody="true" my="left top" id="carPanel" for="carBtn" hideEffect="fade"
dynamic="true">
<p:dataTable id="table" var="car" rowKey="#{car.fournisseurId}"
value="#{articlesMB.listfournisseurs}" selection="#{articlesMB.selectedFournisseurs}"
rows="10" paginator="true" >
<p:column selectionMode="multiple" style="width:20px" />
<p:column headerText="Id">
<h:outputText value="#{car.fournisseurId}" />
</p:column>
<p:column headerText="Nom">
<h:outputText value="#{car.personne.nom}" />
</p:column>
</p:dataTable>
</p:overlayPanel>
</p:tab>
</p:tabView>
<p:commandButton id="article-ajouter"
update=":messages monpanel :articlesdata"
action="#{articlesMB.ajouter}" value="add" />
</h:form>
</p:dialog>
in the first time it works fine, but when I click on the add button and the validation failed (for any cause) and I click on dynamic button of overlaypanel, it appears but when I check or uncheck one of rows of datatable it disappear, I don't know the cause
do you have any idea how to resolve this problem
You cammandButton should use 'process' attribute, you specify component to submit info(not specify overlay).
For ex:
<p:inputText id="txttest" required="true" value="" />
<p:commandButton process="txttest" id="article-ajouter"
update=":messages monpanel :articlesdata"
action="#{articlesMB.ajouter}" value="add" />
The reason your overlay panel only works once is because you update the panel that holds the command button that overlayPanel is attached to.
It is a bug in overlayPanel emerged after PF 5. You can fix this without resorting process attribute, I think solutions like this reduces the readability of the code.
If you define a widgetVar to overlayPanel, say 'carPanelWDG', and call PF('carPanelWDG').loadContents() function in the onComplete event of the command button everything just works. And even if there is no comment explaining the reason why you did such a thing, anyone can interpret this easily.