Issue with Springs Web Flow. Form Submit Values ar

2019-07-31 09:14发布

I am having a issue with Springs Web Flow. If the user clicks on the form submit button I will have the RIGHT values in my bean.

Example the sex field will be MALE or FEMALE. But I then added a AjaxEventDecoration to do a submit on change of the sex dropdown box which is really a form:select and in the bean I will get the value "sex" which is the elementId. Below is my code can you please review it and let me know what you think... I need to fix this value ASAP...

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>



<style type="text/css" media="screen">
 @import url("<c:url value="/resources/dojo/resources/dojo.css"/>");
 @import url("<c:url value="/resources/dijit/themes/claro/claro.css"/>");
</style>     

<script djconfig="parseOnLoad: true"
 src="<c:url value="/resources/dojo/dojo.js"/>" type="text/javascript"></script>
<script type="text/javascript"
 src="<c:url value="/resources/spring/Spring.js" />"> </script>
<script type="text/javascript"
 src="<c:url value="/resources/spring/Spring-Dojo.js" />"></script>
<script type="text/javascript">dojo.require("dojo.parser");</script>

<html>
<head>
<title>Spring 3.0 MVC - Web Flow Example</title>
</head>
<body class="claro">
    <h2>Dropdown Test</h2>

    <form:form commandName="customer" id="customer">
        <input type="hidden" name="_flowExecutionKey"
            value="${flowExecutionKey}" />
        <div id="container">
            <table>
                <tr>
                    <td><font color=red><form:errors path="sex" /></font><b>Sex:</b></td>
                    <td><form:select path="sex" id="sex">
                            <form:option value="MALE" label="MALE" />
                            <form:option value="FEMALE" label="FEMALE" />
                        </form:select> 

                        <script type="text/javascript">
                        Spring.addDecoration(new Spring.ElementDecoration({
                            elementId : "sex",
                            widgetType : "dijit.form.Select",
                            widgetAttrs : {
                            promptMessage : "Enter Sex",
                            required : true }}));
                         </script></td></tr>
                </table>
        </div>

        <input type="submit" name="_eventId_submit" id="submit" value="Submit" />
        <input type="submit" name="_eventId_cancel" value="Cancel" />
        <p>
        <script type="text/javascript">
            Spring.addDecoration(new Spring.ValidateAllDecoration({
                elementId : 'submit',
                event : 'onclick'
            }));

            Spring.addDecoration(new Spring.AjaxEventDecoration({
                 elementId: "sex",
                 event: "onChange",
                 formId:"customer",
                 params: {fragments:"body", _eventId: "loadSchools"}}));
        </script>
    </form:form>
</body>
</html>

2条回答
Emotional °昔
2楼-- · 2019-07-31 09:45

you don't have any closing </b> after "Active" but </n>.
these things some times can lead up to weird issues like the one you are having

fix it and try again

[EDIT] I found a solution to you pb: basically remove the decoration and ajax event on your select and do it this way:

<tr>
    <td><font color=red><form:errors path="sex" /></font><b>Sex:</b></td>
    <td><form:select path="sex" id="sex" required="true" data-dojo-type="dijit/form/Select" onchange="Spring.remoting.submitForm('sex', 'customer', {fragments:'body', _eventId: 'loadSchools'}); return false;">
            <form:option value="MALE" label="MALE" />
            <form:option value="FEMALE" label="FEMALE" />
        </form:select>
   </td>
</tr>

it seems like there are some issues with select decoration... I will try to see if I can find another way, but I tested this and it works

查看更多
叛逆
3楼-- · 2019-07-31 09:55

I fixed the issue. I removed the Spring.AjaxEventDecoration call and changed the Spring.ElementDecoration to the following:

<script type="text/javascript">
                        Spring.addDecoration(new Spring.ElementDecoration({
                            elementId : "sex",
                            widgetType : "dijit.form.Select",
                            widgetAttrs : {
                            promptMessage : "Enter Sex",
                            required : true, 
                            onChange : function() {
                                Spring.remoting.submitForm(
                                    'submit', 
                                    'customer', 
                                    {_eventId: 'sexchange', fragments:'contents'}
                                 ); 
                                 return false;
                            } }}));


                    </script>

I am not 100% clear on why the Ajax call did not work but I have my project working with this code now!

查看更多
登录 后发表回答