On Sat, Sep 19, 2009 at 6:08 PM, Alistair Bush <[email protected]>wrote:
> Anyone?
>
> > Before I even start on my questions, lets describe a little bit about
> what
> > i'm doing.
> >
> > Basically my model has a Region and a School. A School _must_ belong to
> > one (and only one) Region. What I am trying to do is create a
> > RegionPickList. So that on the School form, you can click a link/image,
> > have a window pop up, select/search/etc a Region, Click ok and have the
> > correct information populated on the School form. I want to do this on
> > many entities, against many entities e.g. a Region has parent Region (
> in
> > fact I want to do something similar with "multi-valued" associations ).
> >
> > Now what this looks like at the moment on the form is pretty much
> >
> > <li>
> > <appfuse:label styleClass="desc" key="school.region"/>
> > <form:errors path="region" cssClass="fieldError"/>
> > <input type="hidden" id="regionId" name="regionId"
> > value="${school.region.id}">
> > <input type="text" id="regionName" class="text medium"
> > disabled="disabled" value="${school.region.name}">
> > <a
> > href="/regionsPickList.html?valueField=regionId&displayField=regionName"
> > target="_blank">Pick</a>
> > </li>
> >
> > ugly, but it works so far.
> >
> > Now, in the controller
> >
> > String regionId = request.getParameter("regionId");
> > if (regionId != null) {
> > try {
> > long id = Long.parseLong(regionId);
> >
> > Region r = regionManager.get(id);
> > if (r == null) {
> > // really should be returning a error here.
> > return new ModelAndView();
> > }
> > catch (Exception e) {
> > //and here
> > }
> > } else { /* and here */ }
> >
> > Now what I really want to do ( and hopefully this is obvious by now ) is
> > return validation errors.
> >
> > So far I believe there are actually 2 ways I might possibly do this. One
> > is call errors.rejectValues which I have played with and failed, the
> other
> > is to override initBinder and register a binder.
> >
> > In this case, which would be better to do?
> >
> > In the first case I have been trying to do
> >
> > errors.rejectValue("region", getText("errors.required", "school.region",
> > request.getLocale()));
> > return new ModelAndView().addObject(school);
> >
> > but this never seems to actually work. Any ideas?
>
If you reset the ModelAndView, the errors get erased. Here's an example from
SignupController:
} catch (UserExistsException e) {
errors.rejectValue("username", "errors.existing.user",
new Object[]{user.getUsername(), user.getEmail()},
"duplicate user");
// redisplay the unencrypted passwords
user.setPassword(user.getConfirmPassword());
return showForm(request, response, errors);
}
I believe showForm() is what you're looking for.
Matt
> >
> > Also it would be nice if I could add the required part of the validation
> to
> > validation.xml. Is that possible? Im not really sure when (or what) the
> > validation is run against yet.
> >
> > Does anyone have a nice overall solution to a issue like this.
> >
> > Thanks, I look forward to your thoughts and ideas.
> >
> > Alistair.
> >
> > ps. Thanks to Matt Raible and everyone else who has created AppFuse.
> very
> > cool, very well done.
> > pss. This is my first semi-serious attempt to learn
> > Servlets/Jsp/Java/Spring MVC/etc/etc. Please keep that in mind.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>