1

I implement a <h:form> to edit Employee data which gets preloaded from the database. The preload works fine - all fields get filled with data. The <h:form id="editEmployeeForm"> is surrounded by a <h:form> which contains a <p:dataTable>.

When I do an edit on Employee data and click the "Speichern"-button nothing happens. <p:messages> says all my fields are empty what is obviously a wrong validation because all fields are prefilled. Then I deleted all <p:message> tags from my <h:inputText> tags to check whether the doSaveEmployeeEdit() gets called at all. But nothing happens - no error in console, etc. Even a simple System.out.println() doesn't get printed from the doSaveEmployeeEdit() at all.

Below the <p:dialog> what I have at the time:

<h:form id="editEmployeeForm">


  <p:dialog header="Angestellten ändern" id="employeeEditDialog" widgetVar="employeeEditDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false" closeOnEscape="true">

    <p:outputPanel id="employeeDataEdit" rendered="#{not empty employeeEditController.employee}">
      <h:panelGrid columns="2">
        <p:outputLabel for="usernameEdit" value="Benutzername: " />
        <p:inputText id="usernameEdit" value="#{employeeEditController.employee.username}" disabled="true" />
      </h:panelGrid>
      <p:separator/>
      <h:panelGrid columns="6">
        <p:outputLabel for="firstnameEdit" value="Vorname: " />
        <p:inputText id="firstnameEdit" value="#{employeeEditController.employee.firstName}" />
        <p:outputLabel for="lastnameEdit" value="Nachname: " />
        <p:inputText id="lastnameEdit" value="#{employeeEditController.employee.lastName}" />
        <p:outputLabel for="birthdayEdit" value="Geburtsdatum: " />
        <p:inputMask mask="99/99/9999" id="birthdayEdit" value="#{employeeEditController.employee.birthday}" />
        <p:outputLabel for="locationEdit" value="Wohnort: " />
        <p:inputText id="locationEdit" value="#{employeeEditController.employee.location}" />
        <p:outputLabel for="streetEdit" value="Straße: " />
        <p:inputText id="streetEdit" value="#{employeeEditController.employee.streetName}" />
        <p:outputLabel for="postcodeEdit" value="Postleitzahl: " />
        <p:inputMask id="postcodeEdit" mask="9999?9" slotChar=" " value="#{employeeEditController.employee.postcode}" />
        <p:outputLabel for="phonenumberEdit" value="Telefonnummer: " />
        <p:inputMask id="phonenumberEdit" mask="9?99999999999" slotChar=" " maxlength="12" value="#{employeeEditController.employee.phoneNumber}" />
        <p:outputLabel for="emailEdit" value="Email: " />
        <p:inputText id="emailEdit" validatorMessage="Ungültiges Email-Format!" value="#{employeeEditController.employee.email}">
          <f:validateRegex pattern="^$|^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
        </p:inputText>
      </h:panelGrid>
      <p:separator/>
      <h:panelGrid columns="6">
        <p:outputLabel for="familyStatus" value="Familienstatus: " />
        <p:selectOneMenu id="familyStatus" value="#{employeeEditController.employee.familyStatus}" style="width:150px">
          <f:selectItem itemLabel="Wähle Familienstatus" itemValue="#{employeeEditController.employee.familyStatus}" />
          <f:selectItems value="#{enumController.familyStatus}" />
        </p:selectOneMenu>
        <p:outputLabel for="Religion" value="Religion: " />
        <p:selectOneMenu id="Religion" value="#{employeeEditController.employee.religion}" style="width:150px">
          <f:selectItem itemLabel="Wähle Religion" itemValue="#{employeeEditController.employee.religion}" />
          <f:selectItems value="#{enumController.religions}" />
        </p:selectOneMenu>
        <p:outputLabel for="Role" value="Rolle: " />
        <p:selectOneMenu id="Role" value="#{employeeEditController.employee.workRole}" style="width:150px">
          <f:selectItem itemLabel="Wähle Arbeitsrolle" itemValue="#{employeeEditController.employee.workRole}" />
          <f:selectItems value="#{enumController.workRoles}" />
        </p:selectOneMenu>
      </h:panelGrid>
      <p:separator/>
      <h:panelGrid columns="3">
        <p:commandButton value="Speichern" action="#{employeeEditController.doSaveEmployeeEdit()}" />
        <p:commandButton value="Neu laden" action="#{employeeEditController.doReloadEmployee()}" />
        <p:commandButton value="Abbruch" onclick="PF('employeeEditDialog').hide()" />
      </h:panelGrid>
    </p:outputPanel>
  </p:dialog>
</h:form>

What can be the reason that html or whatever still do the validation and don't call the doSaveEmployeeEdit()?

UPDATE:

I made a new xhtml-file with same outputs - no validation anymore. But my controller method doesn't get called.

My children.xhtml:

<h:body>

  <body class="theme-blue sidebar-mini sidebar-collapse">
    <div class="wrapper">
      <div class="content-wrapper" style="min-height: 1126px;">
        <section class="content">
          <div class="box">
            <div class="box-body">

              <h:form id="childForm">
                <p:dataTable id="childTable" var="child" value="#{childController.children}">
                  <p:column headerText="Vorname">
                    <h:outputText value="#{child.firstName}" />
                  </p:column>
                  <p:column headerText="Nachname">
                    <h:outputText value="#{child.lastName}" />
                  </p:column>
                  <p:column headerText="Geburtsdatum">
                    <h:outputText value="#{child.birthday}" />
                  </p:column>
                  <p:column style="width:32px;text-align: center">
                    <p:commandButton update=":childForm:childEdit" oncomplete="PF('childEditDialog').show()" icon="ui-icon-note" title="Bearbeiten">
                      <f:setPropertyActionListener value="#{child}" target="#{childEditController.childEdit}" />
                    </p:commandButton>
                  </p:column>
                </p:dataTable>

                <p:dialog header="Kind bearbeiten" widgetVar="childEditDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
                  <p:messages autoUpdate="true" />
                  <p:outputPanel id="childEdit" style="text-align:center;">
                    <p:panelGrid columns="2" rendered="#{not empty childEditController.childEdit}" columnClasses="label,value">
                      <p:outputLabel id="primParent" value="primäres Elternteil:" />
                      <p:inputText for="primParent" value="#{childEditController.childEdit.primaryParent.id}" disabled="true" />
                      <p:outputLabel id="firstName" value="Vorname:" />
                      <p:inputText for="firstName" value="#{childEditController.childEdit.firstName}" />
                      <p:outputLabel id="lastName" value="Nachname:" />
                      <p:inputText for="lastName" value="#{childEditController.childEdit.lastName}" />
                      <p:outputLabel id="birthDay" value="Geburtsdatum:" />
                      <p:inputText for="birthDay" value="#{childEditController.childEdit.birthday}" />
                      <p:outputLabel id="emgNum" value="Notfallkontakt:" />
                      <p:inputText for="emgNum" value="#{childEditController.childEdit.emergencyNumber}" />
                      <p:outputLabel id="imgName" value="Bildname:" />
                      <p:inputText for="imgName" value="#{childEditController.childEdit.imgName}" />
                      <p:outputLabel for="gender" value="Geschlecht: " />
                      <p:inputText id="gender" value="#{childEditController.childEdit.gender}" disabled="true" />
                      <p:separator />
                      <h:panelGrid columns="3">
                        <p:commandButton value="Speichern" action="#{childEditController.doSaveChild}" update=":childForm:childTable" />
                        <p:commandButton value="Abbruch" onclick="PF('childEditDialog').hide()" immediate="true" />
                      </h:panelGrid>
                    </p:panelGrid>
                  </p:outputPanel>
                </p:dialog>
              </h:form>
            </div>
          </div>
        </section>
      </div>
    </div>
  </body>
</h:body>

My childEditController:

@Component
@Scope("request")
public class ChildEditController {

@Autowired
private ChildService childService;
private Child childEdit;

public Child getChildEdit() {
    return childEdit;
}

public void setChildEdit(Child childEdit) {
    this.childEdit = childEdit;
}

public void doSaveChild(){
    childEdit = childService.saveChild(childEdit);
    childEdit = null;
}
}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
SteveOhio
  • 569
  • 2
  • 8
  • 20
  • Because there **is** a validation... Maybe on the `Employee` entity... and the values **are** empty because of a wrong scoping or something. Please state the **explicit, full** warning/error message that `p:messages` shows and please make a [mcve] – Kukeltje Jun 13 '17 at 11:36
  • @Kukeltje there is no validation on the entity. the annotations in my controller are `@Component @Scope("request")`. the output of `p:messages` is customized. So it shows me the `p:message` what I declared like "Postcode has to be a number". `p:messages` shows me all `p:message` even if I put some data to the `h:inputText` by hand. The main problem is that I deleted all `p:message` and the browser still does the validation. I would be happy when I get some errors in my console but I get nothing. – SteveOhio Jun 13 '17 at 11:59
  • The method is not called because the validation failed. The validation fails (most likely) because no value is send to the server and the server expects one. That part should be debugged I think. So you are using Spring as well? What if you remove the PrimeFaces components and use the plain jsf counterparts? Same 'error then'? Then it is not PrimeFaces related – Kukeltje Jun 13 '17 at 12:17
  • @Kukeltje The thing is the validation cannot fail because I deleted all the validations - there is no validation. The output of the ghost-validations are the same as I've declared before the deletion. The messages are in german and not in english (what would make sense if the server does the validation). It seems like the messages got saved anywhere in html-related space. I already tried to delete the cache from browser and so on. But nothing works. – SteveOhio Jun 13 '17 at 12:23
  • Then are you sure you have the latest page deployed to the server? And `` is a validation. Again (like in my first comment), [mcve] please, und ich rede überraschend gut Deutsch ;-) – Kukeltje Jun 13 '17 at 16:08
  • @Kukeltje i updated my question ... why doesn't get the method called? not even an error or anything else but the `update` gets done .... when I do a dialog to ADD a child everything works fine – SteveOhio Jun 13 '17 at 17:43
  • https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value/2120183#2120183 – Kukeltje Jun 13 '17 at 21:58
  • @Kukultje.. thanks – SteveOhio Jun 14 '17 at 04:24

0 Answers0