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:
- Change "from Date" and "to Date" fields
- Change account field (dropdown with ajax).
Then the dates are resetted to their default value.
But if I do the following:
- Change "from Date" and "to Date" fields to DATEX AND DATEY
- Press search
- Change "from Date" and "to Date" fields to DATEX2 AND DATEY2
- Change account field (dropdown with ajax).
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?
Best Solution
I changed
For
and it worked.
Thanks