Results 1 to 2 of 2

Thread: How to manage selection...

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    Italy
    Posts
    6

    Default How to manage selection...

    I'm a newbie and I have the following problem:

    I have three classes:

    Class1 {
    String id;
    Class2 c2;
    Class3 c3;
    ... getters and setters...
    }

    Class2 {
    String id;
    String description;
    }

    Class3 {
    String id;
    String description;
    }


    and I have to use a form to create/modify Class1 instances, using as input a List of Class2 instances and a list of Class3 instances.

    That is, I want the user choose a Class2 instance from a select, and a Class32 instance from another select, to create a Class1 instance and save it to the database. I want to do validation on these choices.

    I'm using a SimpleFormController as controller, but don't know what are the best methods to override to put the lists into the model (referenceData or formBackingObject or ???).

    I suppose I have to use <spring:transform>, but I really haven't understood it.

    Any help would be really appreciated (I'd like to have snippets of the controller, the jsp page, etc...)

    Thanks,
    Luigi

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    The instance of Class1 should be put in the model by the formBackingObject method (just return it there). The two lists (Class2 and Class3 instances) need to be put in the referenceData map.

    Then, suppose you have a setter on Class1

    Code:
    setClass2Instance&#40;Class2 object&#41;;
    You'd have to bind a property editor in initBinder capable of transforming Class2 instances to and from Strings and bind on the class2Instance path in your JSP. The spring:transform tag will now use the property editor found by the spring:bind tag to transform whatever you give it.

    Code:
    <spring&#58;bind path="command.class2Instance">
      <c&#58;forEach items="$&#123;class2List&#125;" var="class2">
      <option value="<spring&#58;transform value="$&#123;class2&#125;"/>">
    </spring&#58;bind>
    One thing however, if you're using identifiers in your property editors, but also want to output the name of the class2, you still have to do a manual c:out:

    Code:
    <option value="<spring&#58;transform value="$&#123;class2&#125;"/>"><c&#58;out value="$&#123;class2.name&#125;"/></option>
    Hope this clarifies things a bit.

    Alef

Similar Threads

  1. Replies: 3
    Last Post: Oct 12th, 2005, 04:35 PM
  2. Manage Servlet Filter
    By desmax in forum Management
    Replies: 2
    Last Post: Aug 25th, 2005, 02:22 AM
  3. Replies: 1
    Last Post: Mar 9th, 2005, 03:52 PM
  4. Replies: 6
    Last Post: Jan 20th, 2005, 05:22 PM
  5. Unable to initialize a combobox selection
    By rstearns01 in forum Swing
    Replies: 1
    Last Post: Dec 10th, 2004, 01:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •