1

所以我创建了一个自定义搜索页面,允许我按任何字段搜索客户,并且所有字段都是可选的。为此,我必须创建一个自定义<form:find>标签并注释掉这一行:

<!-- <script type="text/javascript">Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'proceed', event:'onclick'}));</script> -->

这允许我提交表格。但问题是:如果我在字段内部单击并在其外部单击,而不输入任何文本,则会弹出“此字段为必填项”验证错误。

我仍然可以提交表单,并且搜索页面可以正常工作,但我想修复这个烦人的不正确错误。

这是.jspx

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <form:find_without_validation finderName="ByOutputFormatAndStorageDeviceAndWorkOrderAndServiceOffering" id="ff_com_eg_egmedia_bizapp_model_ServiceItem" path="/serviceitems" z="b0NZUow+hQ11Ruy9n/4oyBOWOBs=">
        <field:select_optional disableFormBinding="true" field="outputFormat" id="f_com_eg_egmedia_bizapp_model_ServiceItem_outputFormat" items="${outputformatenums}" path="/outputformatenums" required="false" z="user-managed"/>
        <field:select_optional disableFormBinding="true" field="storageDevice" id="f_com_eg_egmedia_bizapp_model_ServiceItem_storageDevice" items="${storagedeviceenums}" path="/storagedeviceenums" required="false" z="user-managed"/>
        <field:select_optional disableFormBinding="true" field="workOrder" id="f_com_eg_egmedia_bizapp_model_ServiceItem_workOrder" itemValue="id" items="${workorders}" path="/workorders" required="false" z="user-managed"/>
        <field:select_optional disableFormBinding="true" field="serviceOffering" id="f_com_eg_egmedia_bizapp_model_ServiceItem_serviceOffering" itemValue="id" items="${serviceofferings}" path="/serviceofferings" required="false" z="user-managed"/>
    </form:find_without_validation>
</div>

我的<field:select_optional>标签只是<field:select>带有额外标签的默认标签<option value="" />

4

1 回答 1

1

在您的项目中找到select.tagx并在此文件中找到以下行:

<script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : '_${sec_field}_id', widgetType: 'dijit.form.FilteringSelect', widgetAttrs : {hasDownArrow : true}})); </script>

内部装饰器widgetAttrs添加了一个新选项:

required: ${required}

So that the edited line looks like:

<script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : '_${sec_field}_id', widgetType: 'dijit.form.FilteringSelect', widgetAttrs : {hasDownArrow : true, required: ${required}}})); </script>

After this modification the required attribute in field:select tag will work well.

于 2012-09-25T11:47:17.907 回答