Reputation: 97
In my code i have two date values stored in my bean, one (recallDate) is selected from calendar component by user. For the other one (recallFinishDate) i am trying to calculate the finish date which is two weeks after of the selected recallDate.
I want to show the updated finish date by rerendering it, when a user selects a recall date.
The problem is, when i select a value from calendar, i can see that my calculateRecallFinish method runs correctly and makes the correct calculation but after my method finishes, it keeps setting the todays date value on recallDate and recallFinishDate by default.
I want to see the selected and calculated recall dates on frontend.
I'm currently using primefaces version 6.0
Here is my code
@Named("updatePlanning")
@ViewScoped
public class UpdatePlanningView extends BaseView implements Serializable {
private static final long serialVersionUID = -7354105373870032645L;
private Date recallDate = new Date();
private Date recallFinishDate = new Date();
/**
Initialize methods and getter setters are here
**/
public void calculateRecallFinish(SelectEvent e) {
recallDate = (Date) e.getObject();
Calendar calendar = Calendar.getInstance();
calendar.setTime(recallDate);
calendar.add(Calendar.DAY_OF_YEAR, (14));
recallFinishDate = calendar.getTime();
}
}
And my frontend xhtml code is like this;
<p:calendar id="recallDate" value="#{updatePlanning.recallDate}" showOn="button" navigator="true" styleClass="form-calendar">
<p:ajax event="dateSelect"
listener="#{updatePlanning.calculateRecallFinish}" global=true update="@form"> </p:ajax>
</p:calendar>
<p:inputText disabled="true" id="recallFinishDate" value="#{updatePlanning.recallFinishDate}">
</p:inputText>
Upvotes: 1
Views: 153
Reputation: 97
I've found the answer. The problem was the ViewScoped import.
I've changed the import from javax.faces.bean.ViewScoped to javax.faces.view.ViewScoped and now it works
Upvotes: 1