我有一个由 Service Builder 创建的 Liferay 实体,其字段“名称”描述required
如下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 和 Edit 由同一个 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>
问题:添加新人时,没有进行验证,我可以不输入名称并推送提交,实体以空名称保存:
尽管在编辑该人时,会强制执行名称要求:
这发生在 Firefox 上,但不在 Chrome 上。