How to make all dataTable columns inputs readOnly - primefaces

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.

Related

ajax event not working

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.

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.

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.

margin offset from left begining output text via css style

i have only litle overview with css so i ask, i have this form
<h:form>
<h:outputLabel1 value="some text1"/>
<h:outputText1 value="someOutputtext1 />
.
.
<h:outputLabelN value="some textN"/>
<h:outputTextN value="someOutputtextN/>
<h:form/>
result is some like this :
some text1 someOutputtext2
some textN someOutputtextN
how set offset margin via style="" attributte from beginning of "some text1" to beginning to "someOutputtext2" i want reach than each output text will have same starting position, Thanks for much any advice.
Use a h:panelGrid to create the form.
Like this:
<h:form>
<h:panelGrid id="panel" columns="2">
<h:outputLabel value="some text1"/>
<h:outputText value="someOutputtext1 />
<h:outputLabel value="some textN"/>
<h:outputText value="someOutputtextN/>
</h:panelGrid>
<h:form/>
I recomend you to add a new column of messages to handle validation errors, the tag <h:outputLabel1> doesn't exist, use <h:outputLabel >and ad a id attribute to mark a field with a unique name.
Sorry for my bad english