PDA

View Full Version : Problems with success view and forms


JohnG
Feb 9th, 2006, 12:02 PM
Howdy,

Any help would be much appreciated....on two related problems.

I'm working the the Portlet MVC although I think someone with general Web MVC experience will be able to help!

I'm using a SimpleFormController backed by a form backing object. The form view and the success views are one and the same.

I've not encountered anyproblems with this set up....until now.

I've just started to override the referenceData() method to provide a coupld of collection which I use within my jsp to populate some drop downs.

When I submit the form and directed to the success view (the same form) the drop down are no longer populated...I'm guessing this occurs because I am just being dispatched to the form jsp rather than submitting a new render request to the controller which would call amongst other things the referenceData() method.

A colleague is having a similar problem when using a different form backed by a different object as his success view.....the portlet app gets very confused as it attempts to bind the backing object from Form A onto the success view form....

Basically need to know how to get around this issue.

Instead of just hitting the success view as a regular jsp, we really need the submit to be treated as a regular render request dispatched to the controller.

Thanks

cmgharris
Feb 10th, 2006, 03:11 AM
When an initial request is received (GET or as specified by isFormSubmission()), the referenceData Map is automatically added to the Model returned to the view.

However, when handling a form submission (POST or whatever) this does not happen automatically. You have to manually add it e.g. model.putAll(referenceData(request));
before returning your model to the view.

HTH

JohnG
Feb 10th, 2006, 04:38 AM
Thanks...thats my problem sorted out...

Was wondering if you had any thoughts on the second issues that I detailed above:

Form A backed by object of class A having a success view Form B back by object of class B.

I've seen a few posts on the web MVC side of things which talks about RedirectViews. However not sure if this is applicable given that we are not mapping controllers to urls.

Thanks again...

cmgharris
Feb 10th, 2006, 05:11 AM
Not sure I understand the issues well enough to answer this, but here's my understanding, hope someone will correct me if I'm wrong. And I know nothing of portlets.

The formBackingObject, of class commandClass, relates to the controller; you can only have one per controller. So if the formView and successView you refer to relate to the same controller, they can't have different formBackingObjects (by which I assume you mean objects of a different class).
Having said that, you can create any object you like and put it in the model; at the end of the day, if everything the view needs is in the model, you should be ok. A view doesn't have to have an 'official' formBackingObject.

Another thought occurrs . . . you can override formBackingObject, and I guess you could test in there to see if this is a form request or form submission, and return objects of different classes . . . I don't know if Spring would cope with that or complain.

Don't know if that helps . . .

JohnG
Feb 10th, 2006, 06:26 AM
I should have made it clear that the two forms I refer to are not on the same jsp and requests to them are handled by different controllers...

Perhaps the following configuration will help:


<bean id="wbConfigFormController" class="com.jpmam.portlet.welcomeboard.controller.WelcomeB oardConfigFormController">
<property name="commandName" value="configBean"/>
<property name="commandClass" value="com.jpmam.portlet.welcomeboard.model.beans.Welcome BoardConfig"/>
<!-- The name of the jsp that will be resolved using the view resolver -->
<property name="formView" value="wb-config-view"/>
<property name="successView" value="wb-config-view"/>
<property name="validator"><ref bean="wbConfigBeanValidator"/></property>
<property name="persistenceService"><ref bean="persistenceService"/></property>
</bean>

<bean id="xsltConfigFormController" class="com.jpmam.portlet.welcomeboard.controller.XsltConf igFormController">
<property name="commandName" value="configBean"/>
<property name="commandClass" value="com.jpmam.portlet.common.model.beans.XsltConfig"/>
<!-- The name of the jsp that will be resolved using the view resolver -->
<property name="formView" value="xslt-view"/>
<property name="successView" value="wb-config-view"/>
<property name="persistenceService"><ref bean="persistenceService"/></property>
<!-- This name must match your xslt user view name -->
<property name="xsltViewBeanName"><value>welcomeBoardUserView</value></property>
</bean>


You see in the case of the xsltConfigFormController the success view is the bean name wb-config-view.

Problems arise as wb-config-view is backed by a WelcomeBoardConfig object and xsltConfigFormController is backed by an XsltConfig object.

Basically on hitting submit on xslt-view we've done the processing and want to be sent to the wb-config-view as if a new render request handled by the wb-config-view had been made.

Thanks....