jQuery and default struts 2 submit buttons in one

2019-02-28 10:20发布

I have a problem with submitting form, which contains normal and jQuery submit button.

This is code snippet of my JSP:

<sj:head loadAtOnce="true"/>

<s:form id="createModReadProjectForm" action="createProject" cssClass="internalForm" autocomplete="off">
    <s:token/>

    <s:textfield name="collName" cssClass="textField internal" cssErrorClass="textFieldError internal" />
    <div id="assignCollaborators">

    </div>

    <s:url action="assignCollabolator" id="assignCollaboratorUrl"/>
    <sj:submit key="labels.button.addColl" targets="assignCollaborators" 
            id="assignCollButton" formIds="createModReadProjectForm" cssClass="button small"
            href="%{assignCollaboratorUrl}"/>

    <s:submit />
</s:form>

jQuery submit button only adds typed into textfield user name to ArrayList and list all saved users in div with id="assignCollaborators" and this works fine.

Rendered jQuery submit :

jQuery(document).ready(function () {
     var options_assignCollButton = {};
     options_assignCollButton.jqueryaction = "button";
     options_assignCollButton.id = "assignCollButton";
     options_assignCollButton.name = "labels.button.addColl";
     options_assignCollButton.targets = "assignCollaborators";
     options_assignCollButton.href = "/CloudUML/assignCollabolator.action";
     options_assignCollButton.formids = "createModReadProjectForm";

     jQuery.struts2_jquery.bind(jQuery('#assignCollButton'),options_assignCollButton);
});

Now when I want to submit form, using last submit button, nothing happens. No Java or JavaScript errors. What can cause such strange behavior? Why jQuery submit works fine, when normal Struts2 s:submit not?

I assure that all needed actions and property fields are defined.

EDIT:

When I've created simple submit JavaScriptfunction and assign its toonclick` event to the last submit, it works properly.

function submitFunc() {
        document.forms['createModReadProjectForm'].submit();
    }

2条回答
干净又极端
2楼-- · 2019-02-28 10:23

Seems like a bug in struts2-jquery-plugin: http://code.google.com/p/struts2-jquery/issues/detail?id=931.

It should work with version 3.3.3 of that plugin.

查看更多
Deceive 欺骗
3楼-- · 2019-02-28 10:23

Problem here is the e.PreventDefault() to prevent a normal submit on press enter inside of an form textfield.

See: http://code.google.com/p/struts2-jquery/source/browse/trunk/struts2-jquery-plugin/src/main/resources/template/js/struts2/jquery.struts2.js#947

What about using an normal Link instead of an button?

查看更多
登录 后发表回答