PDA

View Full Version : Which controller to use??


sriara
Jun 15th, 2007, 10:02 AM
Hi All,

I am new to Spring.
I am trying it out in a simple web application.
The application consists of:

1) Page one captures user inputs (configure page) (A Calendar + other input elements)
2) Page two displays the captured values and asks for user confirmation (confirm page). User has an option of going back to the page one from this page.
3) Page three displays the final status after the actions are completed.

What kind of Controller is suitable for this application.

Thanks in advance for your inputs

S.

sami25
Jun 15th, 2007, 10:50 AM
Hi,

use a AbstractWizardController since you want the user to navigate between pages.

SimpleFormController doesnt support more than two pages,
CancellableFormController adds additional support in the form of cancelling the form.

sriara
Jun 18th, 2007, 02:27 AM
Thank a lot Sami for the quick reply.

While heard that there could be some issues w.r.t refresh handling and session management when using wizard form controller. Is this valid?

If so are there any specific points that need to be taken care of while using wizard form controllers?

Cheers,
S.

martynhiemstra
Jun 18th, 2007, 06:14 AM
You can use a SimpleFormController for each page. When a user posts values on the first page and these are validated you can put these values in the session. This has a few advantages, for example allowing the user to stop half way and continuing later on. It allows easy and clear configuration. Any other controller can post/redirect to either step of the process (Step 1 2 or 3).

It can be down with 1 controller but you'll need a custom controller and by the way with 1 controller your code becomes very messy and very unclear really fast.

nllarson
Jun 18th, 2007, 03:05 PM
I would go with the Wizard controller. A lot less work than using 3 SFCs.

I haven't had issues with Refresh Handling and Session management using the wizard controllers. I think their only drawback is when going through complex wizard. (In that case you should check out Spring Web Flow.) I guess that isn't really a drawback, use the right tool for the job.

You do have to have one Command Object, which is filled in over the multiple screens. If you are filling in more than one object on your screens, you might need to build a "wrapper" object to hold all the different pieces.

Each step of the wizard can validate the command object and store it into session. And with the getTargetPage() method, you can jump to any step along the way from any other contoller. (With SWF, this is a bit tougher, but still can be done).

martynhiemstra
Jun 19th, 2007, 02:58 AM
I once installed a web app that used webflow. That is a really bad designed framework. Everything is posted so even redirecting causes F5 to popup that annonying message (That browser repost message). This feature alone is so bad that I hated it from the start. The configuration is very unclear so my advice dont use webflow.

Why use webflow when spring has it's own MVC. The configuration is pretty staight forward and easy to understand and you can prevent that annoying repost message.

Marten Deinum
Jun 19th, 2007, 03:50 AM
We use SWF quite heavily and we don't see the issues you mention. Probably some (mis)configuration on your part. A lot of things become easier and more maintainable with SWF instead of using about 12 to 14 controllers for a complex flow or create one huge AbstractWizardFormController with a lot of logic. We reduced the complexity of our application a lot with the introduction of SWF.

sriara
Jun 19th, 2007, 08:31 AM
Hi All,

Thanks for the replies.

I have developed a simple application using AbstractWizardFormController & FreemarkerViewResolver. I need some inputs on the wizard pagination implementation.

My page flow is like this:
Configure Page <-> Confirm page -> Complete
* The arrows indicate the direction of flows possible

I am planning to use the default pagination logic provided by spring. So I was intending to use the _targetN or _finish parameters to control page flow.

This works fine for the first page (via a hidden field with the name _target1. But in the second page (Confirm page) i have two possible flows (to Configure & Complete pages).

How can I pass the _targetN / _finish values to my controller? I am using images to trigger the Previous / Next action.

(One possible implementation that I could think of is to call a JavaScript that dynamically adds a hidden field with the specified values before submitting the page. But there should be a straightforward way for this)

Cheers
S.

nllarson
Jun 19th, 2007, 09:56 AM
I once installed a web app that used webflow. That is a really bad designed framework. Everything is posted so even redirecting causes F5 to popup that annonying message (That browser repost message). This feature alone is so bad that I hated it from the start. The configuration is very unclear so my advice dont use webflow.

Why use webflow when spring has it's own MVC. The configuration is pretty staight forward and easy to understand and you can prevent that annoying repost message.

I too am lost at some of your problems. I think the big thing is to use the right tool. I was not saying you HAVE to use Webflow, but for the right situation (a complex flow with multiple backing objects or the need for decision steps i.e. sub-flows), it is your best bet. It stores everything into session easily, all your data is available on every page. You never have to mess with the session data.

I am wondering why you need to reload in the middle of a flow so often that it is so annoying to you. We refresh pages all the time. You just have to set your transitions up to direct to the correct view state (itself). So you do have to do a post instead of hitting F5, but it works just fine.

And I don't think my post detracted any from Spring MVC. I believe I even recommended to use the wizard controller in this case.

nllarson
Jun 19th, 2007, 10:11 AM
How can I pass the _targetN / _finish values to my controller? I am using images to trigger the Previous / Next action.

(One possible implementation that I could think of is to call a JavaScript that dynamically adds a hidden field with the specified values before submitting the page. But there should be a straightforward way for this)


It has been a while since I have used the Wizard controllers. I don't believe you need to use the javascript. But looking back at our code. We do seem to use it. I think this is just so we could bind the page to our command object. (For some reason we did this, although I am not sure why)

I do believe this is all you have to do....

Page 2 buttons:


<input value="Previous" alt="Previous" name="_target0" type="submit">
<input value="Next" alt="Next" name="_target1" type="submit">


Page 3 buttons:


<input value="Save" alt="Save" name="_finish" type="submit">

sriara
Jun 20th, 2007, 12:44 AM
It has been a while since I have used the Wizard controllers. I don't believe you need to use the javascript. But looking back at our code. We do seem to use it. I think this is just so we could bind the page to our command object. (For some reason we did this, although I am not sure why)

I do believe this is all you have to do....

Page 2 buttons:


<input value="Previous" alt="Previous" name="_target0" type="submit">
<input value="Next" alt="Next" name="_target1" type="submit">


Page 3 buttons:


<input value="Save" alt="Save" name="_finish" type="submit">


Thanks nllarson,

I saw the code. It is using a submit button with the _targetN as name. So onclick of the submit button, the name of the button gets passed to the controller as request parameter. But in my application, we are using images (not buttons) for page navigation. In this scenario, is there any means by which i could dynamically pass the required target page.

P.S: I am not planning to override the getTargetpage method in my controller.

Cheers,
S.

nllarson
Jun 20th, 2007, 08:41 AM
sriara..

Sorry about that. I totally missed that part of your explanation. Sorry.

I think I have seen something like this done with images before.

Page 2:


<input type="image" alt="Previous" name="_target0" src="/my/image/location_Back.gif">
<input type="image" alt="Next" name="_target1" src="/my/image/location_Next.gif">



Page 3:


<input type="image" alt="Save" name="_finish" src="/my/image/location_Save.gif">