I have simple dialog in which there are on datePicker component and two button to confirm the chosen date.
But when I click OK button, the date value always returns null. I'm using Primefaces V10.
.xhtml
Code: Select all
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<p:dialog header="Posted Date" widgetVar="accountingDate" width="550" height="380" showEffect="fade" hideEffect="fade" modal="true" resizable="false" appendTo="@(body)">
<p:panelGrid class="ui-noborder">
<p:row>
<p:column class="pad-bottom-10">
<h:outputLabel value="Date"/>
</p:column>
<p:column class="pad-bottom-10">
<p:datePicker value="#{accountingDateBean.postedDate}" pattern="dd/MM/yyyy" timeZone="GMT+7">
<f:convertDateTime pattern="dd/MM/yyyy" type="localDate"/>
</p:datePicker>
</p:column>
</p:row>
</p:panelGrid>
<div style="float: right">
<p:commandButton action="#{accountingDateBean.save()}" value="OK" icon="fa fa-check" style="width: 100px; margin-top: 10px; " process="@this"/>
<p:commandButton value="Cancel" icon="fa fa-close" style="width: 100px; margin-left: 10px; margin-top: 10px" oncomplete="PF('accountingDate').hide();"/>
</div>
</p:dialog>
</ui:composition>
Code: Select all
@Named("accountingDateBean")
@RequestScoped
public class AccountingDateBean implements Serializable {
private static final long serialVersionUID = 1L;
@Getter
@Setter
private LocalDate postedDate;
@Inject
private DbOptionController dbOptionController;
@Inject
private SessionInfoBean sessionInfoBean;
@Getter
private String currentDb;
@PostConstruct
public void init() {
currentDb = sessionInfoBean.getCurrentDatabase();
}
public void save() {
System.out.println("CALLED = " + postedDate); //always returns null !!!
Dboption postedDateObj = dbOptionController.findByOptionID("DBPostedDate", currentDb);
postedDateObj.setOptionValue(postedDate.toString());
dbOptionController.update(postedDateObj, currentDb);
}
}