提问人:shamik 提问时间:10/14/2021 更新时间:10/14/2021 访问量:265
如何从事件属性访问 url 并在 spring webflow 中执行外部重定向
How to access url from event attributes and perform external redirect in spring webflow
问:
我有一个用例,我需要通过 spring webflow 重定向到外部 URL,每次用户单击链接时,URL 都可能更改。我正在尝试在 flow.xml 中使用 externalRedirect,并在 localAttributeMap 中传入 url 并将其与事件一起返回。
summary.xhtml 代码如下所示。
<h:commandLink action="redirect">
Redirect to new page
</h:commandLink>
flow.xml 如下所示:
<view-state id="summary" view="/flows/forms/summary.xhtml">
<transition on="redirect" to="retrieveUri" />
</view-state>
<action-state id="retrieveUri">
<evaluate expression="redirectAction.execute(requestContext, formContext)" />
<transition on="successRedirect" to="externalView" />
</action-state>
<view-state id="externalView" view="externalRedirect:#{currentEvent.attributes.redirectUrl}">
</view-state>
在我使用的代码库上,我被迫只使用扩展 MultiAction 的 Actions,而我不能使用任何其他具有 String 等返回类型的服务。我的操作类带有返回 Event 的 execute 方法如下所示:
public Event execute(RequestContext context, FormContext formContext) {
LocalAttributeMap lam = new LocalAttributeMap() ;
lam.put("redirectUrl", "https://google.com") ;
//Above would of course be replaced with some service layer call but I need to redirect to this url and that too via classes extending MultiAction.
return new Event(this, " successRedirect", lam) ;
}
但是,这似乎对我不起作用,我收到以下错误:
Caused by: org.springframework.binding.expression.EvaluationExpression : An ElException occured getting the value for expression 'currentEvent.attributes.redirectUrl' on context [class org.springftamework.webflow.engine.impl.RequestControlContextImpl]
at org.springframework.binding.expression.spel.SpringElExpression.getValue(SpringElExpression.java:92)
at org.springframework.webflow.action.ExternalRedirectAction.doExecute(ExternalRedirectAction.java:42)
Caused by: org.springframework.expression.spel.SpelEvaluationExpression : EL1007E:(pos 13): Property or field 'attributes' cannot be found on null
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:208)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:78)
作为spring webflow的新手,我不确定这个问题,并希望在理解这个问题以及是否是使用它的正确方法方面得到一些帮助。 项目中spring-webflow的版本为2.3.0.RELEASE
答: 暂无答案
评论
<set name="currentEvent.attributes.redirectUrl" value="action.returnUrlValue()">