elfwyn
elfwyn

Reputation: 568

How to bind data from an external form to a spring webflow?

Im using Spring webflow 2 with a webflow.mvc.servlet.FlowController.

I want to bind form data submittet (POST) to a flow directly to the model of this flows view.

When navigating flows and submitting form data internally the data is correctly bound to the model, but when submitting data from an external website data is not bound automatically.

To check this I used a spring:form tag inside the view to bind the submittet values via their name/path.

Example: 
  - the views model is named "model"
  - the class used for the model object is has an attribute called "value1"
  -> the bind path for the form:input element is "model.value1"  
  -> the submitted form input field is named "model.value1" as well

update

I am able to access the request Parameters manually now using:

<action-state>
  <evaluate expression="myBinder.execute(flowRequestContext)"/>
</action-state>

where myBinder is a custom Java class implementing org.springframework.webflow.execution.Action

and flowRequestContext is an EL variable supplied by the framework.

Through requestContext.getExternalContext().getRequestParameterMap(); the Parameters of the request are exposed.

Now to bind those parameters to my model-bean, is there a convenient way to do so automatically, like with a "bindAndValidate" method wich is mentioned here and there. I do not know in wich class such a method is available.

I would expect there to be some class to superclass my model bean, but I cannot find it anywhere.

update

Instead of implementing the Action interface I have now subclassed FormAction wich has the bindAndValidate() method. However, this method needs the request as Parameter, and I do not know yet how to best retrieve a reference to the request in EL.

Furthermore I have yet to check if this will actually bind the request parameters to my model and solve my problem.

update

I have found an example showing the call to the bind method made without giving parameters - so I assume those (requestContext) are somehow found by the framework.

Using this approach the model name and class is set as a property on the FormAction bean.

The flow seems to run correctly, but the request parameters still remain unbound...

Maybe I have to go back to a manual approach reading each parameter from request and setting it on the model object...

Any Ideas are welcome...

Upvotes: 0

Views: 2609

Answers (1)

txedo
txedo

Reputation: 976

You can access the request parameters within the XML flow definition using EL. For example, if you want to access a parameter in request called "param1", use requestParameters.param1

Hope this helps.

Upvotes: 1

Related Questions