PDA

View Full Version : SimpleFormController and formView problem


mah01
Aug 14th, 2007, 06:13 PM
Hi

I have a jsp page named Reminders.jsp. That page is responsible for displaying a form for editing a reminder, and a list of all reminders. It also displays the header and footer.
I want the list of reminders to be filled when the page is first rendered so I import both the form and the list. This way their respective controllers will be called and their views displayed to the user.

Reminders.jsp

<%@ include file="IncludeTop.jsp" %>

<table align="center">
<tr><td>
<c:import url="/editReminder.htm" />
</td></tr>
<tr><td>
<c:import url="/listReminders.htm" />
</td></tr>
</table>

<%@ include file="IncludeBottom.jsp" %>


My configuration of the three controllers involved: /reminders.htm, /editReminder.htm and /listReminders.htm:

...
<bean name="/reminders.htm" class="com.tika.reminder.reminders.RemindersController" />

<bean name="/editReminder.htm" class="com.tika.reminder.reminders.EditReminderController">
constructor-arg><ref bean="reminderService"/></constructor-arg>
property name="sessionForm"><value>true</value></property>
property name="commandName"><value>reminder</value></property>
property name="commandClass"><value>com.tika.reminder.dao.Reminder</value></property>
property name="validator"><ref bean="reminderValidator"/></property>
property name="formView"><value>EditReminderForm</value></property>
property name="successView"><value>redirect:/reminders.htm</value></property>
property name="dateEditor"><ref bean="customDateEditor"/></property>
</bean>

<bean name="/listReminders.htm" class="com.tika.reminder.reminders.ListRemindersControlle r">
constructor-arg><ref bean="reminderService"/></constructor-arg>
</bean>
...


After logging on, the user is redirected to /reminders.htm (which just forward to Reminders.jsp). This will cause the page with the form and list to be rendered. This far all is well. But now I want to add a validator to the form.
As you can see in the config for "/editReminder.htm" the formView is a jsp page named EditReminderForm.jsp. When the validation fails, this page is displayed. The problem is that this is only halv of the page (the form). The list is not displayed. I would need Reminders.jsp to be displayed again with the command object bound. This way both the form and the list would be redisplayed to the user with suitable error messages.

Is there a way to solve this problem?

I don't want to have to split the page in two, having the form in one page and the list in another, even though that would solve the problem. Because then I could let both EditReminder.jsp and ListReminders.jsp include the header and footer. After logon I would redirect the user to the page with the list of reminders. Selecting one of the reminders would take him to the page with the form where he can modify it and save it (which would take him back to the page with the list again).

But as I said, I hope you guys can help me find another solution to my problem so that I don't have to do it that way.

Best regards,
Mattias

jstehler
Aug 15th, 2007, 10:04 AM
First of all, I strongly recommend something like SiteMesh to eliminate the need for importing the page header and footer in each of your JSPs.

http://www.opensymphony.org/sitemesh/
http://today.java.net/pub/a/today/2004/03/11/sitemesh.html

It is simple to implement, and allows you to define a template page which can be used to 'decorate' some or all of the pages in your site transparent to each individual JSP.

As for the second problem, what if you were to merge the functionality of the list and edit reminder controllers into one controller? That way, you could put the edit and list controls into one JSP, simplifying everything.

mah01
Aug 15th, 2007, 10:33 AM
Thanks, I will definitely have a look at that.

Maby having only one controller is the way to go. I thought that separating them, having one controller for the form and one for the list would be smart. But maby I just complicated things.

Thanks for your input!

// Mattias

sgoldenberg
Sep 25th, 2007, 10:07 AM
Although it seems like this thread has long been resolved, I'm trying to solve pretty much the exact same problem. Refactoring the controllers is absolutely out of the question.

My form posts to a page called editQuestion, but the onSubmit in this controller redirects to a page that includes editQuestion. When I add a validator bean, the redirection is ignored and I'm left with a small part of the page I'm trying to work with. Any way around this?

Thanks,
Seth

mah01
Sep 26th, 2007, 06:44 AM
I'm sorry to say that I didn't find any solution to this problem other than to merge my two controllers.

sgoldenberg
Sep 26th, 2007, 10:31 AM
Thanks for the response. I chickened out and implemented client-side validation with JavaScript. Not the optimal solution but I didn't see a reasonable one on the server side.