This question already has an answer here:
Temporarily disable JSF validations
(1 answer)
Closed 6 years ago.
I have two panelgrids in my page.
In the first panel grid I have two input text with a button. This
button should valid only this input text.
In the second panelgrid i have 3 input text with a button which
should validate these 3 text only.
How can I ensure that on button click in thr first panelgrid , the
required=true gets ignored for all elements in the second panel grid.
Any help would be appreciated.
If you are using Primefaces you can use partial submit.
For your example:
<h:form>
<p:panelGrid id="grid1">
<p:inputText required="true" id="inp1" value="#{test.value1}"/>
<p:inputText required="true" id="inp2" value="#{test.value2}"/>
<p:commandButton partialSubmit="true" process="#this inp1 inp2" action="#{test.someAction()}" value="validation" update="grid1"/>
</p:panelGrid>
<p:panelGrid id="grid2">
<p:inputText required="true" id="inp3" value="#{test.value3}"/>
<p:inputText required="true" id="inp4" value="#{test.value4}"/>
<p:inputText required="true" id="inp5" value="#{test.value5}"/>
<p:commandButton partialSubmit="true" process="#this inp3 inp4 inp5" action="#{test.someAction()}" value="validation" update="grid2"/>
</p:panelGrid>
</h:form>
Or you can palce grids with buttons in separate forms. Beacuse by default ajax request posts (and validates) values only from current form.
<h:form>
<p:panelGrid id="grid1">
<p:inputText required="true" id="inp1" value="#{test.value1}"/>
<p:inputText required="true" id="inp2" value="#{test.value2}"/>
<p:commandButton action="#{test.someAction()}" value="validation" update="#form"/>
</p:panelGrid>
</h:form>
<h:form>
<p:panelGrid>
<p:inputText required="true" id="inp3" value="#{test.value3}"/>
<p:inputText required="true" id="inp4" value="#{test.value4}"/>
<p:inputText required="true" id="inp5" value="#{test.value5}"/>
<p:commandButton action="#{test.someAction()}" value="validation" update="#form"/>
</p:panelGrid>
</h:form>
Related
I am using this dialog to display a Create form
<p:dialog id="dialogoGestion" header="Asignar nueva gestión" widgetVar="dlg1" >
<p:ajax event="close" update="dialogoGestion"/>
<h:form>
<h:panelGrid columns="2">
<h:outputText value="Cliente: "/>
<h:outputText value="#{miscMB.factura.cliente.nombre}"/>
<h:outputText value="Factura: "/>
<h:outputText value="#{miscMB.factura}"/>
<h:outputLabel value="#{bundle.CreateGestionLabel_descripcion}" for="descripcion" />
<p:inputText id="descripcion" value="#{miscMB.nuevaGestion.descripcion}" title="#{bundle.CreateGestionTitle_descripcion}" />
<h:outputLabel value="#{bundle.CreateGestionLabel_fechaLimiteGestion}" for="fechaLimiteGestion" />
<p:calendar locale="es" pattern="dd/MM/yyyy" id="fechaLimiteGestion" value="#{miscMB.nuevaGestion.fechaLimiteGestion}" title="#{bundle.CreateGestionTitle_fechaLimiteGestion}" required="true" requiredMessage="#{bundle.CreateGestionRequiredMessage_fechaLimiteGestion}">
</p:calendar>
<h:outputLabel value="#{bundle.CreateGestionLabel_usuario}" for="usuario" />
<p:selectOneMenu id="usuario" value="#{miscMB.nuevaGestion.usuario}" required="true" requiredMessage="#{bundle.CreateGestionRequiredMessage_usuario}">
<f:selectItems value="#{usuarioController.itemsAvailableSelectOne}"/>
</p:selectOneMenu>
</h:panelGrid>
<br />
<p:commandButton onsuccess="micalendario.update();PF('dlg1').hide();" action="#{gestionController.crearGestion()}" value="#{bundle.CreateGestionSaveLink}" >
<f:setPropertyActionListener target="#{gestionController.selected}" value="#{miscMB.nuevaGestion}"/>
<f:setPropertyActionListener target="#{gestionController.factura}" value="#{miscMB.factura}"/>
<f:setPropertyActionListener value="#{null}" target="#{miscMB.nuevaGestion}"/>
<f:actionListener binding="#{miscMB.anularNuevaGestion()}"/>
<f:actionListener binding="#{miscMB.agregarGestion(gestionController.selected)}"/>
</p:commandButton>
</h:form>
</p:dialog>
This is where I call the dialog to display
<p:commandLink value="Asignar gestión" onclick="PF('dlg1').show();return false;" action="#{gestionController.preparar()}" rendered="#{miscMB.factura!=null}">
<f:setPropertyActionListener target="#{gestionController.factura}" value="#{miscMB.factura}"/>
</p:commandLink>
What happens is that both <h:outputText value="#{miscMB.factura.cliente.nombre}"/> and <h:outputText value="#{miscMB.factura}"/> values display the properties' last state.
For example, the first time an item selected and you call the dialog, the output is none, because the state is not set. Then, when you select another item and call the dialog, the output is the state last set, which is the previous item value.
Apparently, the setPropertyActionListener in the commandLink is called after the dialog is closed or it executes an action, but not when the commandLink is clicked.
So, how can I set the properties before the dialog frame is displayed?
'
<cc:implementation>
<p:outputLabel value="#{cc}"/>
<p> <p:commandButton value="Vedi lista file" actionListener="#{cc.researchFileInDirectory}" update="panelFileLog"/></p>
<h:panelGrid id="panelFileLog">
<p:dataTable var="file" rendered="#{cc.viewFileList}" binding="#{cc.listaFile}">
<p:column headerText="File" style="width:100px">
<h:outputText value="#{file.toString()}" />
</p:column>
<p:column headerText="Link" style="width:100px">
<p:commandLink id="downloadLink" value="download" ajax="false" actionListener="cc.downloadFile">
<p:fileDownload value="#{cc.file}" />
</p:commandLink>
</p:column>
</p:dataTable>
</h:panelGrid>
</cc:implementation>'
This component is called in this page
<l:logFile />
It loads the list of files but when I click on commandLink, it does not call the actionListener method but redirects me to the same page.
Every component that uses StreamedContent does not work in a composite component. For more detailed explained, please read http://jsfcorner.blogspot.be/2012/11/advanced-primefaces-graphic-image.html . Since <p:fileDownload/> is one of them you can't use it.
On my page I have a line that displays this line from my database table called timelogging.
<h:outputText value="#{timeLoggingController.selected.id}" title="#bundle.ViewTimeLoggingTitle_id}"/>
Then i have underneath it some input fields etc, then i require my timelogging id to be submitted with the form.
How would i assign the value i get from
timeLoggingController.selected.id
to my
timeLoggingDetailController.selected.logId ?
example of my code:
<h:form>
<h:panelGrid columns="2">
<h:outputText value="#{bundle.ViewTimeLoggingLabel_id}"/>
<h:outputText value="#{timeLoggingController.selected.id}" title="#{bundle.ViewTimeLoggingTitle_id}"/>
</h:panelGrid>
<h:panelGrid columns="2">
<h:outputLabel value="#{bundle.CreateTimeLoggingDetailLabel_timeLoggingDetail_logId}" for="timeLoggingDetail_logId" />
<h:inputText id="timeLoggingDetail_logId" value="#{timeLoggingDetailController.selected.logId}" title="#{bundle.CreateTimeLoggingDetailTitle_logId}" required="true" requiredMessage="#{bundle.CreateTimeLoggingDetailRequiredMessage_logId}"/>
</h:panelGrid>
So what i want to do is to remove the inputText and automatically assign
timeLogging.selected.id
to
timeLoggingDetail.selected.id
at the end of my page:
<h:commandLink action="#{timeLoggingDetailController.create}" value="#{bundle.CreateTimeLoggingDetailSaveLink}" />
</h:form>
I have a dialog that is shown for user input.
This dialog has some validations and when the validation fails the blockui goes away.
This works well on my laptop with everything on it.
But when I deploy the war file onto the remote server and test it my blockui does not "unblock" after validation error. I get my growl message stating which field is wrong and the growl goes away but the blockui keeps blocking my dialog. Not allowing the user to correct the input.
<p:commandButton id="bttAddUser" value="Submit" update=":contentView:lstUsers :growl" oncomplete="handleSubmitRequest(xhr, status, args, 'newUserDialog','newUserForm');" actionListener="#{userController.create}">
<p:blockUI id="addBlockUI" trigger="bttAddUser" block="newUserGrid"></p:blockUI>
</p:commandButton>
Both systems, my laptop and remote server have glassfish 3.1.2.2. I was trying to figure out if there is a way of doing this and force the unblock of the ui.
Any ideas?
EDIT:
So it seems that is not a network problem but something else:
I'm actually getting an error:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data
My dialog:
<h:form id="newUserForm">
<p:panelGrid id="newUserGrid" columns="2">
<h:outputText value="Email : " ></h:outputText>
<p:inputText value="#{userController.newUser.email}" required="true" requiredMessage="Please the email of the user" validatorMessage="Email is invalid" >
<f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]#[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
</p:inputText>
<h:outputText value="Name : " ></h:outputText>
<p:inputText value="#{userController.newUser.name}" required="true" requiredMessage="Please the name of the user" ></p:inputText>
<h:outputText value="Role"></h:outputText>
<p:selectOneMenu id="newUserRole" required="true" value="#{userController.newUser.roleid}" requiredMessage="A role must be chosen">
<f:selectItems value="#{userController.listRoles}" var="_role" itemValue="#{_role}" itemLabel="#{_role.roleid}"></f:selectItems>
<f:converter converterId="misc.util.RoleConverter"></f:converter>
</p:selectOneMenu>
<h:outputText value="TimeZone"></h:outputText>
<p:selectOneMenu id="newUserTz" required="true" value="#{userController.newUser.tzone}" requiredMessage="TimeZone must be specified">
<f:selectItems value="#{userController.listTimeZone}" var="_tz" itemValue="#{_tz}" itemLabel="#{_tz}"> </f:selectItems>
</p:selectOneMenu>
<h:outputText value="Password"></h:outputText>
<p:password value="#{userController.newUser.password}" required="true" requiredMessage="Define a password"></p:password>
<f:facet name="footer">
<p:commandButton id="bttAddUser" value="Submit" update=":contentView:lstUsers :growl" oncomplete="handleSubmitRequest(xhr, status, args, 'newUserDialog','newUserForm');" actionListener="#{userController.create}">
</p:commandButton>
<p:commandButton type="reset" value="Reset"></p:commandButton>
</f:facet>
<p:blockUI id="addBlockUI" trigger="bttAddUser" block="newUserGrid" widgetVar="blockUI"></p:blockUI>
</p:panelGrid>
</h:form>
I get the error on Solaris but not in Windows. Both have glassfish 3.1.2.2 build 5.
Finally fixed this.
I had two primefaces jars in my WebApp:
One in domain/lib and the other one under WEB-INF/lib.
It seems that when using some functions of primefaces, it would return more than it should.
Post in Primefaces Forums
I'm trying to set a panelgrid inside a dialog. Everything seems to be working except the colspan. I've check this post PrimeFaces panelGrid but its year and half old. From the primefaces manual and showcase, colspan should be accepted by datatable and panelGrid.
<h:form id="idFormAddDialog">
<p:panelGrid id="idPanelAddUsers" columns="2">
<h:outputLabel for="dAddOutUser" value="Username:"></h:outputLabel>
<h:inputText id="dAddOutUser" value="#{userController.username}"></h:inputText>
<h:outputLabel for="dSelRole" value="Role:"></h:outputLabel>
<h:selectOneMenu id="dSelRole" value="#{userController.role}">
<f:selectItem itemLabel="Admin" itemValue="1"></f:selectItem>
<f:selectItem itemLabel="Researcher" itemValue="2"></f:selectItem>
<f:selectItem itemLabel="User" itemValue="3"></f:selectItem>
</h:selectOneMenu>
<h:outputLabel for="dAddINPassword1" value="Password: "></h:outputLabel>
<p:password id="dAddINPassword1" value="#{userController.password}" feedback="true"></p:password>
<p:row>
<p:column colspan="2">
<p:separator></p:separator>
<!-- <p:separator></p:separator>-->
</p:column>
</p:row>
<p:commandButton value="OK" actionListener="#{userController.addUser()}" ></p:commandButton>
<p:button value="Cancel"></p:button>
</p:panelGrid>
</h:form>
But I'm not able to find what I'm doing wrong.
First, if you want to use p:row and p:column in p:panelGrid remove columns attribute, and manage rows and column manually with p:row and p:column tags. Everything inside p:panelGrid must be inside p:row tags. Example:
<p:panelGrid id="idPanelAddUsers">
<p:row>
<p:column></p:column>
<p:column></p:column>
<p:column></p:column>
</p:row>
<p:row>
<p:column colspan="2"></p:column>
<p:column></p:column>
</p:row>
</p:panelGrid>