我正在尝试使用jquery submit()从javascript函数提交操作。 动作方法不会被调用,但会调用控制器的render方法。 当我在浏览器窗口中复制url字符串(来自firebug调试器"<%= deleteURL%>")时,将调用action方法。
从jquery
调用action方法需要什么代码
>>>>>>jsp>>>>>>>>>
<pre><code>
<portlet:actionURL name="deleteObject" var="deleteURL" >
<portlet:param name="action" value="deleteObject" />
</portlet:actionURL>
<script type="text/javascript">
function <portlet:namespace />deleteObject(id) {
if (confirm('<%= UnicodeLanguageUtil.get(pageContext, "are-you-sure-you-want-to-delete-the-Object") %>')) {
debugger;
jQuery('<form />').attr('action', "<%=deleteURL%>").
append(jQuery('<input>', {
'name': 'objectId',
'value': id,
'type': 'hidden'
})).appendTo('body').submit().remove();
}
}
</script>
</code></pre>
>>>>>>java controller>>>>>>>>>
/**
* Simply selects the home view to render by returning its name.
*/
@RenderMapping
public String render(Locale locale, Model model, RenderRequest req, RenderResponse res) {
_log.info("Starting render: " + locale.toString());
...
return "listObjects";
}
@ActionMapping(params = "action=deleteObject")
public void deleteObject(Locale locale, Model model, PortletRequest req, PortletResponse res) throws PortalException, SystemException {
_log.info("Starting deleteObject: " + locale.toString() + ":" + model);
....
}