Search code examples
validationjspliferay-auialloy-uiliferay-6.2

Liferay form does not check required fields at Add, despite checking them at Edit


I have a Liferay entity created by Service Builder, with the field "name" described as required in portlet-model-hints.xml:

<model-hints>
    <model name="com.example.model.Person">
        [...]
        <field name="name" type="String">
            <validator name="required" />
        </field>
        [...]
    </model>
</model-hints>

Add and Edit are powered by the same JSP edit_person.jsp:

<%@include file="/html/init.jsp"%>
<%
Person person = null;
long personId = ParamUtil.getLong(request, "personId");
if (personId > 0) person = PersonLocalServiceUtil.getPerson(personId);
%>
<aui:model-context bean="<%= person %>" model="<%= Person.class %>" />
<portlet:renderURL var="viewPersonURL" />
<portlet:actionURL name='<%= person == null ? "addPerson" : "updatePerson" %>'
   var="editPersonURL" windowState="normal" />

<aui:form action="<%= editPersonURL %>" method="POST" name="fm">
    <aui:fieldset>
        <aui:input type="hidden" name="personId"
          value='<%= person == null ? "" : person.getPersonId() %>'/>
        <aui:input name="name" />
    </aui:fieldset>

    <aui:button-row><aui:button type="submit" /></aui:button-row>
</aui:form>

PROBLEM: When adding a new person, no validation is done, I can enter no name and push submit and the entity is saved with an empty name:

enter image description here

Despite the fact that when editing that person, the name requirement is enforced:

enter image description here

This happens on Firefox but not on Chrome.


Solution

  • This is a bug in Liferay 6.2:

    https://issues.liferay.com/browse/LPS-48087

    This bug has been fixed in Liferay 7.0.0 M2