Reputation: 10208
I have a dropdown that holds an account number and two date fields. I want to reset the date fields if I change the value of the dropdown. I also have a search button that make a query using these fields (account #, from date, to date).
<fieldset>
<p:selectOneMenu id="account_search" value="#{accountHistoryBean.account}" converter="accountConverter">
<f:attribute name="itemsList" value="#{accountHistoryBean.userAccounts}"/>
<f:selectItems value="#{accountHistoryBean.userAccounts}" var="account" itemLabel="#{account.number}" itemValue="#{account}"/>
<p:ajax update="start_date_search, end_date_search" event="change" actionListener="#{accountHistoryBean.resetDates}" process="account_search"/>
</p:selectOneMenu>
<fieldset>
<fieldset>
<p:calendar value="#{accountHistoryBean.fromDate}" id="start_date_search" pattern="dd/MM/yyyy"/>
</fieldset>
<fieldset>
<p:calendar value="#{accountHistoryBean.toDate}" id="end_date_search" pattern="dd/MM/yyyy"/>
</fieldset>
<fieldset>
<p:commandLink styleClass="regular_button" action="#{accountHistoryBean.search}" update=":search :accountHistoryList :accountHistoryList:accountHistTable" >
<span>#{msj.search}</span>
</p:commandLink>
</fieldset>
If I do the following:
Then the dates are resetted to their default value.
But if I do the following:
Then it changes the Date field to DATEX and DATEY (not the default values).
The methods in the Bean are the following:
public void resetDates()
{
Calendar calendar = GregorianCalendar.getInstance();
//By default set toDate as 3/3
calendar.set(Calendar.MONTH, 2);
calendar.set(Calendar.DAY_OF_MONTH, 3);
toDate = calendar.getTime();
//By default fromDate is one month earlier
calendar.setTime(toDate);
calendar.add(Calendar.MONTH, -1);
fromDate = calendar.getTime();
}
public String search(){
//Just update the filters
lazyDataEntityModel.setUpdateData(true);
return null;
}
Any help?
Upvotes: 2
Views: 31427
Reputation: 10208
I changed
<p:ajax update="start_date_search, end_date_search"
event="change"
actionListener="#{accountHistoryBean.resetDates}"
process="account_search"/>
For
<p:ajax update="start_date_search, end_date_search"
event="change"
listener="#{accountHistoryBean.resetDates}"
process="account_search"/>
and it worked.
Thanks
Upvotes: 6
Reputation: 11
The right answer is about the Converter. Check the value property in the h:selectOneMenu!! Is not mapped properly. If you still have doubts set immediate="true" so no converter or validator will do their job. That´s what I did, and worked.....after 4 - 6 hours....:|
Thanks you about the converter idea, that was the tip that provided me the right answer.
Upvotes: 1