0

I am facing a problem in the form submit, the first thing is without @this my <p:commandButton> is not calling my Managedbean.
And when I added @this it's calling my managed bean with empty form data.
I am not able to figure out exactly what I am missing here.the structure is
employee.xhtml:

   <ui:composition template="employee/employeeTemplate.xhtml"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:p="http://primefaces.org/ui"> 
        <ui:define name="mainContent">
            <ui:include src="employee/employeeEditForm.xhtml"></ui:include>
        </ui:define>
    </ui:composition>

And my employeeTemplate.xhtml is :

   <ui:composition template="../../templates/sidebarLayout.xhtml"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui" 
        xmlns:ui="http://java.sun.com/jsf/facelets">
        <ui:define name="sidebarContent">
            <p:panel styleClass="panelContainer">
                <p:panel styleClass="panelHeader"
                    header="#{o:translate('Employee List')}"></p:panel>
                <p:panel styleClass="panelSpacing">
                    <h:form id="employeeListForm">
                        <ui:include src="employeeList.xhtml">
                        </ui:include>
                        <ui:include src="addNewEmployee.xhtml">
                        </ui:include>
                    </h:form>
                </p:panel>
            </p:panel>
        </ui:define>
    </ui:composition>

And my Dialogbox is in addNewEmployee.xhtml

    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:fn="http://java.sun.com/jsp/jstl/functions"
        xmlns:ui="http://java.sun.com/jsf/facelets">
                <p:commandButton id="addEmployeeBtn" 
                             value="#{o:translate('Add New Employee')}"
                             styleClass="btnAction" 
                             style="float: right;" 
                             oncomplete="PF('dlgExample').show();">                 
                </p:commandButton>
        <p:dialog id="dlgExample"
                header="#{o:translate('Dlg Example')}"
                widgetVar="dlgExample" dynamic="true" width="750" height="600" appendTo="@(body)">
                <h:form id="dlgExampleForm">
                            <p:outputLabel for="val1"
                                value="#{o:translate('Employee Type')}:" />
                            <p:selectOneMenu value="#{myManagedBean.selectedEmp.type}" id="val1">
                                        <f:selectItems value="#{myManagedBean.employeeTypes}" />
                                    </p:selectOneMenu>
                            <p:commandButton id="cancelButton"
                                value="#{o:translate('Cancel')}" update=":mainContent,:msgs"
                                oncomplete="PF('dlgExample').hide();" />
                            <p:commandButton style="float: right;"
                                styleClass="pull_right btnAction"
                                actionListener="#{myManagedBean.saveEmployee}"
                                value="#{o:translate('Save')}" process="@this"
                                update=":mainPage,:msgs" >
                                <p:confirm header="Confirmation" message="Are you sure you want to Save?" 
                                icon="ui-icon-alert" /> 
                                </p:commandButton>
                </h:form>
            </p:dialog>
</ui:composition>

Any help will be grately apreciated.

  • Hi, thanks for omitting other inputs, but it would have been better too (for getting to a [mcve]) to also remove the templating, the divs, the dialog etc.. Then you most likely still would have gotten the error and maybe would have seen a certain 'duplication' that you would have tried removing too and it would have started working... Solution is indeed in the duplicate. – Kukeltje Jun 23 '20 at 09:49
  • @Kukeltje I am still not able to find the exact issue please can you guide me? –  Jun 23 '20 at 10:20
  • Did you create a [mcve], took all the steps that were mentioned in my previous comment? Did you read beyond the first bullit in the duplicate? Please do, but besides reading the bullits, investigate if they are applicable for you – Kukeltje Jun 23 '20 at 10:51
  • @BalusC Thank you! I made a few changes on the save button which is calling method using () like actionListener="#{myManagedBean.saveEmployee()}" and I changed process to form like process="@form". Now it's working. –  Jun 23 '20 at 11:32
  • You still have nested forms when the html is initially rendered (even though you use an appendTo on the dialog) and that might result in undefined behaviour (moving a form around in html is not a common thing browsers are tested on by Mozilla, Chrome et al. But great it works. – Kukeltje Jun 23 '20 at 11:58
  • @Kukeltje Thank you for your help, I removed nested forms. –  Jun 23 '20 at 12:27

0 Answers0