Using Primefaces 3.1.1.
I am trying to perform two actions on submit of 1 commandButton:
The original form elements are as follows:
<p:calendar ... value="#{bean.date1}" />
<p:calendar ... value="#{bean.date2}" />
<h:commandButton value="submit" onchange="TASK" action="#{Bean.saveOrUpdateItem()}" >
</h:commandButton>
But now, I would also like to achieve the following with the press of that same button:
<h:commandButton value="submit" action="#{bean.submit}">
<f:ajax execute="#form" render="result" />
</h:commandButton>
<h:outputText id="result" value="#{bean.date3}" />
Any pointers on how to deal with that?
I do not want to modify the first Bean.saveOrUpdateItem() and have to create the second bean.
Thank you in advance.
-V
Try to use f:actionListener
<h:commandButton value="Submit" id="submit" action="#{myBean0.action}" >
<f:actionListener binding="#{myBean1.actionListener}"/>
<f:actionListener binding="#{myBean2.actionListener}"/>
</h:commandButton>
Related
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.");
}
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"/>
I am using Primefaces 3.1.1. and very new to JSf in general.
I have two Calendar input fields on my form as such:
<p:calendar widgetVar="widgetFromDate" id="ID1" value="#{Bean.selected.From}" pattern="dd.MM.yyyy" mode="popup" showOn="button"> </p:calendar>
<p:calendar widgetVar="widgetFromTime" id="ID2" value="#{Bean.selected.Till}" pattern="HH:mm" timeOnly="true" mode="popup" showOn="button"> </p:calendar>
I have a third field which concatenates and shows the above two values on the click of h:commandButton.
For example:
The button:
<h:commandButton value="Speichern" onclick="????"></h:commandButton>
I am not really sure how one accomplishes that. Could there be a possibility to use some ajax events?
Any pointers would be greatly appreciated.
-BR
Just basically so:
<p:calendar ... value="#{bean.date1}" />
<p:calendar ... value="#{bean.date2}" />
<p:commandButton value="submit" action="#{bean.submit}" update="result" />
<h:outputText id="result" value="#{bean.date3}" />
with
public void submit() {
date3 = mergeSomehow(date1, date2);
}
Or if you insist in using standard JSF command button, this has the same effect:
<h:commandButton value="submit" action="#{bean.submit}">
<f:ajax execute="#form" render="result" />
</h:commandButton>
Implementation detail of merging is up to you and not in any way related to JSF/PrimeFaces. Just ask a basic java question if you stucks.
The onclick attribtue is at least insuitable for this as it provides in this particular case merely a hook to execute some JavaScript function before the form is being submitted. You're not interested in this hook.
I have this form:
<h:form id="form">
<h:panelGrid columns="3" >
<h:outputLabel for="name" value="Name:" />
<h:inputText id="name" value="#{register.person.name}" >
<f:ajax event="blur" listener="#{register.validateName}" render="m_name" />
</h:inputText>
<rich:message id="m_name" for="name" ajaxRendered="false"/>
<!-- other fields -->
<h:commandButton value="Register" action="#{register.registerPerson}" >
<f:ajax execute="#form" render="out" />
</h:commandButton>
<h:outputText value="#{register.recordStatus}" id="out" />
</h:panelGrid>
If I try to register some person without a name and no error message is displayed. Instead, an error message appears when removing a person : <f:ajax execute="#form" render="out" />.
Why is this happening ?
You need to include the ID of the message in the render as well.
<f:ajax execute="#form" render="m_name out" />
You can also just render the entire form if you have more than one message.
<f:ajax execute="#form" render="#form" />
See also:
Communication in JSF 2.0 - Ajax Validation
Might be a bit late, but...
The attribute ajaxRendered of <rich:message> has a default value of true, which forces it to appear in AJAX responses.
You set it to false in Your form, and so You have to specify, which AJAX calls should re-render it.
There are a list with 100 "Favs" on it. It only shows 10 when the page loads. When I click on "Show More Favs" it shows 10 more Favs.
What's weird about it, it's after I click on Show More Favs, clicking on Remove from list, it's not calling the method in the backBean.
My backBean is ViewScoped.
<ui:repeat value="#{bean.list}" var="fav">
<h:form>
<h:commandLink styleClass="someStyle" title="Remove from list" action="#{bean.remove(fav.id)}"/>
</h:form>
</ui:repeat>
<h:form>
<h:commandButton value="Show More Favs" action="#{bean.showMore}" >
<f:param name="moreFav" value="10" />
<f:ajax event="action" render="#all" />
</h:commandButton>
</h:form>
The culprit is the usage of multiple forms and the render="#all". If you re-render another form from inside an ajax form, the viewstate of the another form will get lost.
You need to change the code so that only the content of another form is re-rendered:
<h:form id="otherform">
<h:panelGroup id="list">
<ui:repeat value="#{bean.list}" var="fav">
<h:commandLink styleClass="someStyle" title="Remove from list" action="#{bean.remove(fav.id)}"/>
</ui:repeat>
</h:panelGroup>
</h:form>
<h:form>
<h:commandButton value="Show More Favs" action="#{bean.showMore}" >
<f:param name="moreFav" value="10" />
<f:ajax event="action" render=":otherform:list" />
</h:commandButton>
</h:form>