Reset DropDown,check box in primefaces not working? - jsf

DropDown Box code:
<p:selectOneMenu id="user" value="#{daywise_Count.selectuserId}" style="width:120px">
<f:selectItem itemLabel="All" itemValue="0" />
<f:selectItems value="#{daywise_Count.getAllLoginIds()}" var="uif" itemLabel="#{uif.loginId}" itemValue="#{uif.userId} " />
</p:selectOneMenu>
CheckBox code:
<p:selectBooleanCheckbox id="checkbox" value="#{deptBean.checkboxvalue}" /> With All Details
reset function:
function resetter()
{
document.getElementById('myForm:myMenu_label').innerHTML = 'All';
}
Calling Reset Function
<h:commandButton id="btnReset" value="Reset" update="myForm" onclick="resetter();"
styleClass="button" type="submit">
</h:commandButton>
I am using reset button in myForm that functionality is not working properly in primefaces.please suggest any solution...

you should try this <p:commandButton id="btnReset" value="Reset" update="myForm" process="#this" /> this is working for me, I hope it will help you too. and no need to java script.
update="myForm" attribute means it will update your panel because here you will use panel id and process="#this" means it will execute same content after click on reset button for further details you can search on google or refer this link What is the function of #this exactly?

Related

Ajax event change doesn't work

I've a form, and i want it to show some inputs only if the user mark yes on a selectOneRadio.
Here is the code:
<p:selectOneRadio id="someSelectRadio" value="#{someBean.someClass.someSelectRadio}" >
<f:selectItem itemLabel="Sim" itemValue="Sim" />
<f:selectItem itemLabel="Não" itemValue="Não" />
//Here i use event=change to reconize if the user mark a option on selectOneRadio
<p:ajax event="change" process="someSelectRadio" update="panelGeral" />
</p:selectOneRadio>
//Here is the panel that i want to appear if the user mark selectOneRadio
<p:outputPanel id="panelGeral">
<p:panel id="panel" autoUpdate="true" rendered="#{someBean.someClass.someMethod}" />
</p:outputPanel>
I already have tryied to change event do click, on click, both doesn't work for me.
This may be due to the problem with event .
Change to
<p:ajax event="valueChange" process="someSelectRadio" update="panelGeral" />
More info

disable two controls using one radio box in JSF Primefaces

I have to disable two controls on the page using one pair of radio buttons
I have the following code:
<p:selectOneRadio id="console" binding="#{yesOrNo}" required="true">}">
<f:selectItem itemValue="Yes" itemLabel="UPLOAD CLR" />
<f:selectItem itemValue="No" itemLabel="ORDER NUMBER" />
<p:ajax update="yesdata" />
</p:selectOneRadio>
<p:fileUpload id="yesdata" fileUploadListener="#cBean.handleFileUpload}"
label="Upload NC CLR" mode="advanced" multiple="false"
update="createConfigPanel" auto="true" sizeLimit="100000" allowTypes="/(\.|\/)(xls|xlsx)$/" disabled="#yesOrNo.value != 'Yes'}" />
The problem with the above code is I cannot use the same ID for another control. Code continued:
<h:panelGrid columns="2" cellpadding="8">
<p:outputLabel for="serviceType" value="Service Type" />
<p:inputText id="serviceType"
value="#{cBean.serviceType}" required="true"></p:inputText>
...
I want to disable this input box when UPLOAD CLR is clicked in the above case.
Please suggest
You can define multiple components to update in update attribute. Just add another id like:
update="id1 id2"

PrimeFaces ajax resets all p:inputText

I'm trying to use PrimeFace ajax for enable/disable the submit button and it works fine except it also resets all my p:inputText .
Here is my code:
<p:inputText value="#{loginTo.emailAddress}"
id="emailAdd"
tabindex="1"
required="true"
maxlength="50"
requiredMessage="#{appLoginParameter['AppLoginEmailRequiredMsg']}"
validatorMessage="#appLoginParameter['AppLoginEmailIncorrect']}">
</p:inputText>
<p:selectBooleanCheckbox id="eSignatureCheckBox"
value="#{loginTo.userLoginDetailTO.resetEsignFlag}"
rendered="true"
styleClass="acc-lable-name-check1">
<p:ajax event="change" update="submitButton"></p:ajax>
</p:selectBooleanCheckbox>
You are missing a opening { in:
validatorMessage="#appLoginParameter['AppLoginEmailIncorrect']}"
Should be:
validatorMessage="#{appLoginParameter['AppLoginEmailIncorrect']}"
Try that and see if that helps.

How to reset dropdown on primefaces commandButton without java script?

I want to reset <p:selectOneMenu> in primeface. I used type="reset" this can reset the text fields only not a selectonemenu. My code
<p:panel id="Applyleave_panel" >
<p:selectOneMenu id="leavetype" value="#{requestbean.leavetype}" required="true" style="width:50%;">
<f:selectItem itemLabel="Select type" itemValue="" />
<f:selectItems value="#{requestbean.leave_type}" />
</p:selectOneMenu>
</panel>
<p:commandButton value="Reset" type="reset"/>
You can use p:resetInput given that your component is inside a form.
<p:commandButton value="Reset" update=":form" immediate="true">
<p:resetInput target=":form" />
</p:commandButton>
EDIT: You can also target the p:panel component as well.
<p:commandButton value="Reset" update=":Applyleave_panel" immediate="true">
<p:resetInput target=":Applyleave_panel" />
</p:commandButton>
I use the below
<p:commandButton id="resetSearchCir" type="reset"
value="#{button.reset}" immediate="true">
<f:ajax event="click"
listener="#{searchBean.resetActionListener}" render="#form" />
</p:commandButton>
public void resetActionListener(AjaxBehaviorEvent event) {
LOG.info("Reset button clicked...");
setResetClicked(true);
// re-initialise your form field objects which you want to reset
logWarn("All values have been reset. Please enter the new values to search again.");
}

Validator is called but error message is not displayed

when i click on the command button. validate method is getting called but the error message is not getting displayed..
here is my code..
<h:form id="form">
<h:body>
<p:panel style="width:500px">
<h:outputLabel for="year" value="Select Year: *" style="font-weight:bold" />
<p:selectOneMenu id="year" value="#{leaveBean.year}">
<f:selectItem itemLabel="Select One" itemValue="null" />
<f:selectItems value="#{leaveBean.yearDTO}" var="currentUser" itemValue="#{currentUser.name}" itemLabel="#{currentUser.name}" />
<f:validator validatorId="LeaveCardValidator" />
</p:selectOneMenu>
</p:panel>
<p:commandButton value="Submit" action="#{leaveController.leaveCard}" update="updateList,updateDetails" id="button"/>
<h:message for="year" style="color:red"/>
You seem to expect that JSF auto-updates the <h:message> on every ajax request. This is untrue. Perhaps you're confusing with PrimeFaces <p:messages> or <p:growl> which have each an autoUpdate attribute which enables you to tell them to auto-update themselves on every ajax request.
You really need to make sure that the <h:message> is covered by the ajax update. Just give it an ID
<h:message id="yearMessage" ... />
and include it in the client ID collection of the ajax update
<p:commandButton ... update="updateList updateDetails yearMessage" />
An alternative would be to replace <h:message> by <p:messages autoUpdate="true">.
Not sure where are the updateList and updateDetails are located but in the example give above you should use update="#form" instead or in addtion like this:
update="updateList updateDetails #form"
so that the form will be rendered again...
just use one of these :
update the whole form in order to update the content of
<h:message />
<p:commandButton value="Submit" action="#{leaveController.leaveCard}" update="#form" id="button"/>
or give the <h:message /> an id and id this id to the <p:commandButton/>
<h:message id="msg" for="year" style="color:red"/>
<p:commandButton value="Submit" action="#{leaveController.leaveCard}" update="updateList,updateDetails,msg" id="button"/>

Resources