views:

260

answers:

1

I am new to Spring and have been reading about it the last few days. I haven't found an open source example like this so far and didn't see a clear way for it to be done.

Many sites have a login or search box that is on every page. If this is the case, how can you avoid setting an attribute in a model on every page for that form? Similarly, if you have a form on page FooBar that should have little knowledge of the processing of the form, which is done in SearchFooBar, how can it create the form without adding the model attribute?

Right now I have been using <form:form modelAttribute="classname"...> with

   @RequestMapping(method=RequestMethod.GET)
    public String setupForm(Model model) {
        model.addAttribute("classnamehere", new ClassNameHere());
        return "pagename";
    }

Thanks

PS: On a related note, can you automatically include header and footer jsp files throughout a site without doing an <% include on every page?

A: 

I believe you do need to use the modelAttribute tag, In situations where I have multiple forms I usually go with Spring Webflow as it handles the scenario better.

If you're just trying to repeat yourself then use a jsp tag to render the form.

And the 2 forms you mention are very simple, search box or login. So don't use the spring binding/form stuff and just handle the form yourself, perhaps in a tag or something.

ballmw