0

I am trying to submit the contents of a form to a method in a managed bean, storeAppointment(), however the action attribute of the commandButton is never fired. If i use the onclick attribute, then the method in the managed bean is called, however, the onclick attribute also fires when the page is loaded which is not what I want to happen. My form is as follows :

<h:form>
    <p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true">
        <p:autoUpdate />
    </p:growl>

    <h:panelGrid columns="2" cellpadding="5">
        <p:outputLabel for="start" value="Start Time" />
        <p:datePicker id="start" value="#{createAppCtrl.startTime}" showTime="true" stepMinute="5"/>

        <p:outputLabel for="finish" value="Finish Time" />
        <p:datePicker id="finish" value="#{createAppCtrl.finishTime}" showTime="true" stepMinute="5"/>

        <h:outputLabel for="multiple" value="Multiple:" />
        <p:selectCheckboxMenu id="multiple" value="#{createAppCtrl.selectedUsers}" label="Users" multiple="true"
                                      filter="true" filterMatchMode="startsWith" panelStyle="width:250px">
            <p:ajax event="itemUnselect" listener="#{createAppCtrl.onItemUnselect}" />
                <f:selectItems value="#{createAppCtrl.involvement}" />
            </p:selectCheckboxMenu>
    </h:panelGrid>

    <p:commandButton value="Submit" 
                     action="#{createAppCtrl.storeAppointment}" 
                     update="displayItems" 
                     oncomplete="PF('itemDialog').show()"/>

    <p:dialog header="Selected Items" modal="true" showEffect="fade" hideEffect="fade" widgetVar="itemDialog" width="250">
        <p:outputPanel id="displayItems">
            <h:outputText value="Time: " />
            <h:outputText value="#{createAppCtrl.startTime}" >
                <f:convertDateTime pattern="MM/dd/yyyy HH:mm" />
            </h:outputText>

            <h:outputText value="Time: " />
            <h:outputText value="#{createAppCtrl.finishTime}">
                <f:convertDateTime pattern="MM/dd/yyyy HH:mm" />
            </h:outputText>

            <p:dataList value="#{createAppCtrl.selectedUsers}" var="city" emptyMessage="No cities selected" style="margin-bottom: 10px;">
                <f:facet name="header">
                    Multiple
                </f:facet>
                #{city}
            </p:dataList>
        </p:outputPanel>
    </p:dialog>
</h:form> 

When the commandButton is clicked the update and oncomplete attributes work as expected, but the dialog that is shown by oncomplete displays only null values. And the method that is being called by action is #{createAppCtrl.storeAppointment}:

    public String storeAppointment() {
        try {
            System.out.print(startTime + "    " + finishTime + "    " + involvement);
            appointmentBean.createAppointment(startTime, finishTime, involvement);
            return "";
        } catch (Exception e) {
            System.out.print("Ctrl: " + e);
            return "";
        }
    }
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Sam
  • 11
  • 1
  • Hi, me again, the sometimes PITA... Tried copy/pasting your title in a searchengine and investigate? (See [ask]) Tried creating a [mcve]? – Kukeltje Apr 06 '20 at 13:10
  • Hi, thanks to the suggesting, pointing to other questions I was able to find the solution. It was due to the bean i am using to control my JSF template being request scoped and not view scoped. Thanks for your help! – Sam Apr 06 '20 at 14:32

0 Answers0