【问题标题】:Spring Web Flow ExternalRedirect using Expression使用表达式的 Spring Web Flow ExternalRedirect
【发布时间】:2015-04-22 15:47:32
【问题描述】:

背景

用户必须向服务器提交报告参数。服务器将用户重定向到一个 URL。该 URL 运行 Oracle Reports 以生成 PDF(或网页)。

系统使用相对较慢的身份验证机制。但我不打算重新启动 Web 流程,因此身份验证不应使用重定向 otherwise interfere

JSP

“运行报告”按钮编码如下:

<button type="submit" id="run" name="_eventId_run">
    <fmt:message key="form.button.report.run" />
</button>

页面的其余部分将参数绑定到DAO中的一个映射,例如:

<form:radiobutton path="parameters['service']" class="service" value="..." />

提交表单表明绑定变量在 DAO 映射中设置正确。此外,该报告能够生成用于重定向的 URL。

表单本身类似于:

<form:form modelAttribute="report" action="${flowExecutionUrl}"
    method="post">
    <fieldset>
        <%-- secret tokens --%>
        <tiles:insertAttribute name="hidden" />

        <%-- includes the requested report form parameters --%>
        <jsp:include page="${reportKey}.jsp" />

        <%-- includes the aforementioned submit button %-->
        <tiles:insertAttribute name="reportButtons" />
    </fieldset>
</form:form>

流程

流程具有三种视图状态:列出报告、输入参数和运行报告。最后两个是相关的:

<view-state id="parameters" model="report" view="flow/reports/parameters">
    <transition on="run" to="redirect">
        <evaluate expression="reportService.run(report)" result="flowScope.url" />
    </transition>
</view-state>

<view-state id="redirect" view="externalRedirect:#{flowScope.url}"/>

正在调用reportService.run(report) 方法。正在绑定报表参数。返回结果确实是正确的 URL。

Java

报告服务本身相当简单:

public String run(Report report) {
    Map<String, String> parameters = report.getParameters();

    String url = getConfigurationValue("ReportUrl");

    for (String key : parameters.keySet()) {
        info("Report Parameter: {} = {}", key, parameters.get(key));
    }

    return url;
}

再次返回正确的 url。没有控制器类。 Report DAO 再简单不过了:

public class Report extends DAOBase implements Serializable {
    /** Values to pass into the report. */
    private Map<String, String> parameters;

    public Report() {
        setParameters(createParameters());
    }

    // standard accessors and serial version not shown
}

问题

应用程序似乎正在执行POST-Redirect-GET (PRG)。 GET 不会将浏览器定向到由flowScope.url 设置的 URL。 (我还没有验证flowScope.url 是否包含有效数据。)当POST 操作完成时,应用程序被重定向到参数流,而不是运行按钮重定向到redirect 流。

来自schema definition,一切似乎都是正确的。

问题

使用 Spring 4.1.2,需要进行哪些更改以使 externalRedirect 将浏览器发送到 reportService.run(...) 返回的 URL?

表单是否需要为flowExecutionUrl 提供不同的值?

尝试

以下是一些无效的更改:

  • 在 EL 中使用$,而不是#(即externalRedirect:${flowScope.url}
  • 使用&lt;end-state id="redirect" view="externalRedirect:#{flowScope.url}"/&gt;
  • 使用&lt;view-state id="redirect" view="externalRedirect:http://google.com"/&gt;
  • 使用form:button 而不是button

更改重定向视图状态并删除表达式评估会导致重定向触发。例如:

<transition on="run" to="redirect">
    <!-- <evaluate expression="reportService.run(report)" result="flowScope.url" />  -->
</transition>
...
<view-state id="redirect" view="externalRedirect:http://google.com"/>

当然,这意味着报表参数永远不会被使用,这是行不通的。

【问题讨论】:

    标签: java spring jsp redirect spring-webflow


    【解决方案1】:

    从过渡中删除评估:

    <transition on="run" to="redirect"/>
    

    在 EL 语句中调用 run 方法生成 URL:

    <view-state id="redirect" view="externalRedirect:#{reportService.run(report)}"/>
    

    【讨论】:

      猜你喜欢
      • 2016-06-17
      • 1970-01-01
      • 2012-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多