datePicker doesn't set the chosen date

UI Components for JSF
Post Reply
charlietran1986
Posts: 29
Joined: 02 Aug 2020, 20:00

08 Dec 2021, 11:06

Hi guys!
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>

Bean

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);
    }
}


tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

08 Dec 2021, 11:42

Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

charlietran1986
Posts: 29
Joined: 02 Aug 2020, 20:00

08 Dec 2021, 19:24

@tandraschko
Now I nest a <h:form> inside <p:dialog>, but when the button is clicked, the action method is not called anymore. It is very strange.

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)">
    <h:form>
        <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>
        </h:form>
    </p:dialog>
</ui:composition>


charlietran1986
Posts: 29
Joined: 02 Aug 2020, 20:00

14 Dec 2021, 11:33

@tandraschko
I have accidentally included this xhtml file inside another file which has its own form.
This results to nested forms around commandbutton, so that the action is never called.
Thanks for suggestion!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 24 guests