View Full Version : AbstractWizardFormController in Spring MVC Portlet Framework
donkc
Mar 23rd, 2006, 11:12 AM
I want to do sample spring mvc portlet application(JSR168) with AbstractWizardFormController . I have chosen this as my controller because I have got 3 screens
1.Data Entry Page with 'Cancel' and 'Next' button.
2.Confirmation Page with 'Back' and 'Finish' button.
3.An acknowledgement screen with the 'ok' button.
can any body tell me what are methods i need to override and what is the bean defintion for AbstractWizardFormController in the WEB-INF/context/portlet/samplePortlet.xml for the controller.
I am not clear how the flow happens.
johnalewis
Mar 23rd, 2006, 02:55 PM
Take a look at the BookAddController in the sample application on the wiki site. It is a good example of a portlet AbstractWizardFormController.
http://opensource2.atlassian.com/confluence/spring/display/JSR168/Home
Specifically, look at:
spring-portlet-sample/WEB-INF/src/org/springframework/web/portlet/sample/BookAddController.java
spring-portlet-sample/WEB-INF/context/portlet/books.xml
spring-portlet-sample/WEB-INF/jsp/bookAdd.jsp
The JSP uses some tricks to use the same file for all of the pages in the wizard. You can of course create separate JSP pages for each page in the wizard.
Also read through the javadocs for AbstractWizardFormController -- they are pretty descriptive of how to use this class.
If you still have questions, post them here.
donkc
Mar 23rd, 2006, 11:11 PM
I have gone through that example , but In that example in the processFinish method the render parameter are set with a key value pair of 'action' and 'books' which is routed to the 'BooksController' and then it displays the booksview.jsp. What I wanted to know is Can I override the 'renderFinish' method to return an ModelView object directly rather than routing through the controller.
Also i wanted to know that if 'renderFinish' is implemented than will it be invoked automatically after 'processFinish' method is invoked .
After the first screen is displayed to the User ,how are the subsequent screens are displayed.By just mentioning the pages in the bean defintion of the controller is sufficient for the controller to identify the next page to displayed to the user.
Let me put my understanding how the AbstractWizardFormController works.
1. I will define the bean defintion as follows in the context/portlet/sampleportlet.xml
<bean id="createCustomController"
class="com.portlet.custom.controller.CreateCustomUserIdCo ntroller">
<property name="commandName" value="createCustomForm" />
<property name="commandClass" value="com.portlet.customuserid.form.CreateCustomForm" />
<property name="validator" ref="customValidator" />
<property name="pageAttribute" value="page"/>
<property name="pages" value="createUserId,confirmCreateUserId,acknowledgeCreate UserId"/>
</bean>
2. Then I will have to write a AbstractWizardFormController which will have following methods.
initBinder(if required)
-processFinish
-renderFinish
-processCancel
-renderCancel
-ValidatePage
What I understand is from the first screen to the screen before final screen in the submit button name is given as "_targetNextPageNumber" i.e for the first screen it will be "_target1" since pages are indexed from 0 and ValidatePage is called and the page is validated and the if the errors object is not having an value then next page is displayed to the User and the 'sessionPageAttribute' is incremented by 1. The 'processFinish' is called when in the final screen submit button will have a name as '_finish' for and the 'processCancel' is called when '_cancel' is present as name for the button.
Correct if i am wrong.
johnalewis
Mar 27th, 2006, 10:24 AM
You are correct that you can implement the renderFinish method instead of changing the mapping parameter to go to a different controller for the render phase. The renderFinish method will automatically be called for the render phase as long as the mapping goes to the same controller and the _finish request parameter is present.
Your understanding of the workflow of the controller sounds correct. Realize that you can do the cancel operation, finish operation, or go to any page in the wizard by using the appropriate request parameters. Again, the same app is a good example of this.
Let me know if you encounter problems during your implementation.
As an aside, you may also want to take a look at Spring WebFlow for wizard-style interaction. It has portlet support that uses Spring Portlet MVC as well.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.