Announcement Announcement Module
Collapse
No announcement yet.
Need help understanding query args/data model mapping when using SimpleFormController Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help understanding query args/data model mapping when using SimpleFormController

    Hi folks. I'm tearing my hair out over this problem. I've spent
    countless hours trying to figure this out, but I can't get it to work
    the way I want it for the life of me.

    I'm writing a web app using Spring MVC and JSP. One part of the app is
    a simple form that gets loaded in an iframe by a wrapper service. The
    wrapper service provides a bunch of query string parameters to the
    form, most of which I don't need in the form per se, but when I submit the form
    data, the launching service uses those parameters for certain things.

    Here's the problem. I have a form field where the user is supposed to
    type in a name. This form field is bound to the corresponding property
    in my data model. I'm using the Spring form library for this:

    <form:form commandName="configFormModel" target="_top">
    <table border="0" cellpadding="0" cellspacing="0">
    <tbody>
    <tr valign="bottom">
    <td><b>Enter a name for this search</b><br/>
    <form:input path="name" maxlength="128" size="35" />
    </td>
    <td>
    <form:errors path="name" cssClass="errorBox" />
    </td>
    ....

    I'm using the SimpleFormController for this by the way. So when I
    first launch the form, it comes up empty as expected. I fill something
    out and hit submit, and in my onSubmit() method, I do a redirect back
    to the wrapper service like this:

    protected ModelAndView onSubmit(HttpServletRequest request,
    HttpServletResponse response,
    Object command, BindException errors)
    throws Exception
    {
    final ConfigFormModel model = (ConfigFormModel) command;
    Map<String, String[] params = request.getParameterMap();
    // Add the stuff from my model to the parameter map. Example:
    // params.put("searchName", model.getName());
    return new ModelAndView(new RedirectView(m_redirectUrl, false), params);
    }

    The first time, this works fine. But there are cases where the wrapper
    service will launch my form passing in the parameters for the form
    fields as query strings. The form fields get populated fine, but if I
    change the value of the name field for example, and hit submit, the
    wrapper service will receive a query string that contains the query
    argument "name" twice. It will contain both the new and the old setting.

    I'm not sure if I'm making myself clear. I'm tired and I've tried just
    about everything I can think of. I've read through the API docs and
    have tried to understand the flow, but it feels like I'm fighting the
    framework and not understanding where things go wrong. I've played
    around with overriding various methods but without much luck. What I
    think is the root of the problem is my lack of understanding how query
    string arguments map to my data model and vice versa. What I'd need to
    do (please correct me if I'm wrong) is to have fine grained control
    over the query string arguments in my redirect call back to the
    wrapper service. How do I achieve that? I'm grateful for any help on
    this subject. Thanks,

    Bluzcat
Working...
X