How to access url from event attributes and perform external redirect in spring webflow

314 Views Asked by At

I have a use case where I need to redirect to an external URL via spring webflow, the url might change every time the user clicks on the link. I am trying to use externalRedirect within the flow.xml and passing in the url in a localAttributeMap and returning it with the event.

The summary.xhtml code looks something like this.

<h:commandLink action="redirect" target="_blank">
Redirect to new page
</h:commandLink>

The flow.xml is something like this:

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

On the code base I am using I am forced to only use Actions which extend MultiAction and I can't use any other service have return types like String. My action class with the execute method which returns an Event looks something like below:

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) ;
}

However this does not seem to work for me and I am getting the below errors:

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)

Being new to spring webflow, I am not sure of the issue and would appreciate some help in understanding the issue and whether is the correct way of using this. The version of spring-webflow is 2.3.0.RELEASE within the project

0

There are 0 best solutions below