How can I reset PrimeFaces tabs [duplicate] - jsf

This question already has answers here:
Reset input fields in primefaces
(5 answers)
Clear JSF form input values after submitting
(5 answers)
Closed 6 years ago.
I have A PrimeFaces wizard each tab contains InputText fields or SelectOneMenu menus ... how could I reset all fields and menus in all tabs on submit button ??
I'm using primefaces 5.3
thank you

PrimeFaces has a component for clientside resets
<p:commandButton value="Reset Tag" update="#form" process="#form" style="margin-right:20px;" >
<p:resetInput target="***idFromYourTag***" />
</p:commandButton>
If you need reset the backing bean values, you need to write a method.
See also ResetInput

Related

p:selectBooleanCheckBox does not work inside a p:dialog [duplicate]

This question already has answers here:
Can you nest html forms?
(21 answers)
How to use <h:form> in JSF page? Single form? Multiple forms? Nested forms?
(2 answers)
Closed 6 years ago.
I'm using PrimeFaces 5.3 with the following code:
<p:dialog id="dlg1" appendTo="#(body)" header="Confirm Dialog" widgetVar="dlg1" modal="true">
<h:form id="dialogform">
<h:outputText id="confirmlabel" value="Are you Sure you want to #{reportRunnerNamedBean.currentCommand} ?" />
<br/>
<center>
Check to send only missed emails:<p:selectBooleanCheckbox id="sendOnlyMissedBox" value="#{reportRunnerNamedBean.sendMissedOnly}"></p:selectBooleanCheckbox><br/>
<p:commandButton id="yesButton" value="Yes" action="#{reportRunnerNamedBean.runCurrentCommand()}" onstart="startWait();PF('waitDialog').show();" oncomplete="PF('waitDialog').hide();stopWait();" onclick="PF('dlg1').hide();" process="#form"/>
<p:commandButton id="noButton" process="#this" value="No" onclick="PF('dlg1').hide();"/>
</center>
</h:form>
</p:dialog>
No matter what, the backing bean value for the sendMissedOnly is set to false. I have confirmed this by attaching a debugger. I have even tried adding ajax to the box, it is still false every time, no matter if it is checked or not. Does p:selectBooleanCheckbox just not work in a dialog?
I figured this out. It was because the dialog was in an form. It seems that when a dialog is in a form , and you have a form within the dialog itself, the component will not be processed. It seems JSF/primefaces does not like multiple layers of forms or dialogs defined within forms. If you are having a similar issue, makes sure your dialog is defined outside any form. Moving a dialog can cause paths to components to change. the easiest way to resolve that is to use the primefaces handy p:component tag like this update=":#{p:component('compoment_name')}" > that will make it find it no matter where in the tree the component occurs.

Primefaces commandLink works but not commandButton [duplicate]

This question already has answers here:
Differences between action and actionListener
(4 answers)
Closed 6 years ago.
I have identical actions for commandLink and commandButton. However, commandLink works as expected. But with commandButton no action occurs. Am I missing syntax?
<p:commandLink value="Submit" action="#{beanController.getStr(strSearch)}" ajax="false"/>
<p:commandButton value="Submit" actionListener="#{beanController.getStr(strSearch)}" ajax="false"/>
If you intend for navigation to occur you should use action not actionListener in your commandButton, so:
<p:commandButton value="Submit" action="#{beanController.getStr(strSearch)}" ajax="false"/>
commandButton button generates a HTML <input type="submit"> element and the commandLink generates a HTML <a> and comandButton is using to submit the form whereas commandlink is used to submit a link,so your form is not submitting i'll suggest you to check if there is any nested form is present or not or if there is multiple forms in your code or any other issue which is causing in form submit, if you can then post your code.

p:commandButton can't to update p:panel [duplicate]

This question already has an answer here:
How to update panel from datatable [duplicate]
(1 answer)
Closed 7 years ago.
I'm using PF 5.3, with JSF 2.2
I have a p:commandButton which exists in one of p:column of a p:dataTable. I have a panel outside the dataTable and I want it to be updated once the commandButton is clicked, but this didn't work.
xhtml sample:
<h:form id="register_edit_student" enctype="multipart/form-data" >
<p:dataTable var="students" value="#{generalPresentation.students}">
<p:column headerText="Edit">
<p:commandButton update="updateStudent" value="Edit" action="#{teacherPresentation.assignEditableStudent(students)}" />
</p:column>
</p:dataTable>
<p:panel id="updateStudent">
</p:panel>
</h:form>
My requirement is to update the "updateStudent" p:panel.
Once I ask the p:commandButton to update the panel (update="updateStudent") the page design crashed and all controls disappeared.
I was reading in the internet the commandButton of a column in a dataTable cannot update anything outside the dataTable, so the question, is there a solution or work around?
Thanks
You have three options to solve this:
add prependId="false" to your form,
Prepend the form id in your reference: update=":register_edit_student:updateStudent" or
move your panel outside of the form element.
Note: The first option should be used rarely and is known to cause issues with plain JSF.

Execution order of Javascript Events in JSF Managed Bean [duplicate]

This question already has answers here:
Execution order of events when pressing PrimeFaces p:commandButton
(2 answers)
Closed 7 years ago.
I have a primefaces datatable with a <p:rowEditor />. The Logic of my process is when i click on a button it's suppose to:
Jump to the last page of the Datatable
Refresh the table
Click on the edit button of the last row
in the footer i implemement a commandButton and remoteCommand looking like:
<f:facet name="footer">
<p:remoteCommand name="rctype" update="typeDT"
actionListener="#{myView.onNewType}" />
<p:commandButton id="btnNewType" ajax="true" onclick="rctype()"
update="typeDT" icon="ui-icon-plus" title="New Type"
value="New Type" >
</p:commandButton>
</f:facet>
my Bean looks like :
public void onNewType() {
try {
...
RequestContext.getCurrentInstance().execute("PF('widgettypeDT')
.paginator.setPage(PF('widgetinitiatorDT').paginator.cfg.pageCount - 1)");
RequestContext.getCurrentInstance()
.execute("jQuery('.typeClass')
.find('span.ui-icon-pencil').last().click();");
} catch() {}
}
But unfortunatly the Click Event always occur before the Jump Event.
How can i control the Execution order of my Javascript Events in my Managed Bean?
The solution is simple. Call one javascript function on the client and do both in there. Or do both in one RequestContext.getCurrentInstance().execute(...)

p:dialog closed regardless to condition in oncomplete [duplicate]

This question already has answers here:
Keep p:dialog open when a validation error occurs after submit
(6 answers)
Closed 3 years ago.
I use JSF 2.0 and Primefaces 3.5
I have a dialog and in case if data not passed my validation rules not closed dialog
<p:commandButton id="seasonSave" actionListener="#{adminSeasonController.add()}"
action="#{adminManageTournamentController.generateTournamentNames()}"
value="#{msg.save}" ajax="true"
onmousedown="return validateSubmit('createSeasonForm', ['name_season'], 'lang')"
oncomplete="if (#{not adminSeasonController.validationFailed}) addSeasonDialog.hide()"
update=":manageTournament:name_season, :manageTournament:title ,:menuForm:growl, #form">
I see in controller validationField = true, but dialog closed.
how I can resolve my problem?
You can look primefaces showcase for this problem.
http://www.primefaces.org/showcase/ui/dialogLogin.jsf
Update of the link: https://www.primefaces.org/showcase/ui/overlay/dialog/loginDemo.xhtml
<p:commandButton id="seasonSave" actionListener="#{adminSeasonController.add()}"
action="#{adminManageTournamentController.generateTournamentNames()}"
value="#{msg.save}" ajax="true"
onmousedown="return validateSubmit('createSeasonForm', ['name_season'], 'lang')"
oncomplete="if (!args.validationFailed) addSeasonDialog.hide()"
update=":manageTournament:name_season, :manageTournament:title ,:menuForm:growl, #form"/>

Resources