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