我是否使用动作状态?根据单选按钮加载下拉列表值

时间:2012-09-04 18:52:18

标签: java spring spring-mvc spring-webflow

我是否使用动作状态?根据单选按钮

加载下拉值

我正在尝试根据用户单击单选按钮加载下拉列表的值,但我不知道是否可以使用动作状态来完成此操作。

这就是我的想法。

我的流程有:

<view-state id="SchoolVisitReport" view="SchoolVisitReport.jsp" model="visit">
            <transition on="submit" to="addVisit">
                <evaluate expression="flowActions.validateVisit(visit, messageContext)"/>
            </transition>
            <transition on="cancel" to="endState" bind="false"/>
            <transition on="loadSchools" to="loadSchools" bind="false"/>
</view-state>

<action-state id="loadSchools">
        <evaluate expression="flowActions.initializeSelectableStates()"  result="flowScope.selectableStates" />
</action-state>

我的控制器有这样的东西

public Map<String, String> initializeSelectableStates(Visit visit) {
        LOGGER.debug("inside initializeSelectableStats");

        LinkedHashMap<String, String> selectableStates = new LinkedHashMap<String, String>();

        selectableStates.put("NY", "NY");
        selectableStates.put("Nj", "Nj");
        return selectableStates;
    }

但这不起作用..有人可以帮帮我吗

2 个答案:

答案 0 :(得分:1)

执行以下JSP代码......它可以工作..

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<title>Spring 3.0 MVC - Web Flow Example</title>

<script type="text/javascript"
    src="<c:url value="/resources/dojo/dojo.js" />">

</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>

<link type="text/css" rel="stylesheet"
    href="<c:url value="/resources/dijit/themes/tundra/tundra.css" />" />
</head>
<body>
    <h2>Customer Registration</h2>

    <form:form commandName="customer" id="customer">
        <input type="hidden" name="_flowExecutionKey"
            value="${flowExecutionKey}" />
        <table>
            <tr>
                <td><font color=red><form:errors path="name" /></font><b>Name:
                </b></td>
                <td><form:input path="name" id="name" /> <script
                        type="text/javascript">
                    Spring
                            .addDecoration(new Spring.ElementDecoration(
                                    {
                                        elementId : "name",
                                        widgetType : "dijit.form.ValidationTextBox",
                                        widgetAttrs : {
                                            promptMessage : "This is the name you would like entered into the system."
                                        }
                                    }));
                </script> <br />
                    <p></td>
            </tr>
            <tr>
                <td><font color=red><form:errors path="phoneNumber" /></font>

                    <b>Phone number: </b></td>
                <td><form:input path="phoneNumber" id="phoneNumber" /><br />
                    <script type="text/javascript">
                        Spring
                                .addDecoration(new Spring.ElementDecoration(
                                        {
                                            elementId : "phoneNumber",
                                            widgetType : "dijit.form.ValidationTextBox",
                                            widgetAttrs : {
                                                promptMessage : "This is the phone number for the above name"
                                            }
                                        }));
                    </script></td>
            </tr>
            <tr>
                <td></td>
            </tr>
            <tr>
                <td><b>Row:</b></td>
                <td><form:radiobutton value="B" path="row" id="rowBtnA" />Row: B<BR>
                    <form:radiobutton value="A" path="row" id="rowBtnB" />Row: A<BR>
                    <script type="text/javascript">
            Spring.addDecoration(new Spring.AjaxEventDecoration({
                elementId: "rowBtnA",
                event: "onchange",
                formId:"customer",
                params: {fragments:"body", _eventId: "proceed"}
            }));
        </script>

        <script type="text/javascript">
            Spring.addDecoration(new Spring.AjaxEventDecoration({
                elementId: "rowBtnB",
                event: "onchange",
                formId:"customer",
                params: {fragments:"body", _eventId: "proceed"}
            }));
        </script>

        </td>
            </tr>
            <tr>
            <td>Year of Birth:</td>
            <td>
            <form:select path="byear">
            <form:option value="2012" label="2012" />
            <form:option value="2011" label="2011" />
            <form:option value="2010" label="2010" />
            </form:select>

        <script type="text/javascript">
            Spring.addDecoration(new Spring.AjaxEventDecoration({
                elementId: "byear",
                event: "onchange",
                formId:"customer",
                params: {fragments:"body", _eventId: "proceed"}
            }));
        </script>
        </td></tr>

        </table>
        <input type="submit" name="_eventId_proceed" value="proceed"
            id="proceed" />
            <input type="submit" name="_eventId_cancel" value="Cancel" />
    </form:form>

</body>
</html>

答案 1 :(得分:0)

这是怎么回事?它将使用更新的信息重新加载您的页面

<view-state id="SchoolVisitReport" view="SchoolVisitReport.jsp" model="visit">
                <transition on="submit" to="addVisit">
                    <evaluate expression="flowActions.validateVisit(visit, messageContext)"/>
                </transition>
                <transition on="cancel" to="endState" bind="false"/>
                <transition on="loadSchools" to="SchoolVisitReport" validate="false" bind="false">
                     <evaluate expression="flowActions.initializeSelectableStates()"  result="flowScope.selectableStates" />
                </transition>
    </view-state>