我有一个Ajax表单验证问题。我使用的是struts-core 2.3.1.2,struts-jquery-plugin 3.3.0和struts-json-plugin。Struts Ajax表单验证
如果ajax表单将由ajax请求提交并且验证失败,则会出现问题。因此,整个表单将被放置在结果元素上。因此,您可以在ajax sumbit按钮上激活ajax验证。 http://code.google.com/p/struts2-jquery/wiki/Validation
这里也是过时的信息: http://struts.apache.org/2.2.3.1/docs/ajax-validation.html
但拦截 “jsonValidationWorkflowStack” 在struts-default.xml中缺少像写在帖子:jsonValidationWorkflowStack seems to be removed in Struts 2.3.1
据源出到struts- json插件在struts-plugin.xml中。我不知道我怎么可以直接使用,但我建立我自己的堆栈中的struts.xml:
<!-- Sample JSON validation stack -->
<interceptor-stack name="jsonValidationWorkflowStack">
<interceptor-ref name="basicStack"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
<interceptor-ref name="jsonValidation"/>
<interceptor-ref name="workflow"/>
</interceptor-stack>
</interceptors>
<action name="updateMySettings" method="execute" class="de.ra.daod.actions.MyAppSettingAction">
<interceptor-ref name="jsonValidationWorkflowStack"/>
<!-- This is not beauty within ajax -->
<result name="input">/WEB-INF/jsp/mysetting_ajax.jsp</result>
<result name="success" type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
</action>
我的形式看起来像:
<s:head />
<sj:head />
<!-- This files are needed for AJAX Validation of XHTML Forms -->
<script src="${pageContext.request.contextPath}/struts/xhtml/validation.js" type="text/javascript"></script>
<s:form id="form" action="private/updateMySettings" theme="xhtml">
<s:textfield id="screenRes" key="appSetting.screenResolution" label="Screen resolution" required="true" />
<s:select key="appSetting.screenDepth" label="Color depth" list="#{'8':'8','16':'16','24':'24'}" required="true" />
<sj:submit value="Update Settings" targets="status" validate="true"/>
</s:form>
不幸的是,我得到一个javascript错误如果验证失败,或不:
Uncaught TypeError: Object #<Object> has no method 'indexOf'
f.extend.ajax jquery-1.7.1.min.js:4
b.fn.ajaxSubmit
a.struts2_jquery.validateForm jquery.struts2-3.3.0.min.js:18
a.subscribeHandler.h.beforeSubmit jquery.struts2-3.3.0.min.js:18
b.fn.ajaxSubmit
a.subscribeHandler.e jquery.struts2-3.3.0.min.js:18
e.extend.each jquery-1.7.1.min.js:2
a.subscribeHandler.e jquery.struts2-3.3.0.min.js:18
f.event.dispatch jquery-1.7.1.min.js:3
f.event.add.h.handle.i jquery-1.7.1.min.js:3
f.event.trigger jquery-1.7.1.min.js:3
f.fn.extend.trigger jquery-1.7.1.min.js:3
e.extend.each jquery-1.7.1.min.js:2
e.fn.e.each jquery-1.7.1.min.js:2
f.fn.extend.trigger jquery-1.7.1.min.js:3
d.fn.extend.publish jquery.subscribe.min.js:16
e.extend.each jquery-1.7.1.min.js:2
d.fn.extend.publish jquery.subscribe.min.js:16
(anonymous function) jquery.struts2-3.3.0.min.js:18
f.event.dispatch jquery-1.7.1.min.js:3
f.event.add.h.handle.i jquery-1.7.1.min.js:3
看来,从响应JSON对象无法处理,我不知道为什么因为我遵循旧的指示。我假设原因是struts/utils.js中的StrutsUtils.getValidationErrors函数,如果该函数与json对象一起使用,但我不确定。谁能帮忙?
没有人有想法吗?必须有可能在struts 2.3.1.2中验证ajax请求吗?由于最新的struts版本不支持jsonValidationWorkflowStack,我添加了插件struts-json-plugin 2.3.1.2,其中jsonValidationWorkflowStack可用,但它只存在具有上述结果的旧指导。谁能帮忙? – Caphalor40k