Announcement Announcement Module
Collapse
No announcement yet.
Binding a command with a list of somewhat complex objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding a command with a list of somewhat complex objects

    Our project is using Spring, Hibernate and Velocity. I've read many things this afternoon that all seem to broach this subject, but I can't seem to find a clear explanation of how it should look.

    As an example, take this command:

    Code:
    public class EssayQuestionsCommand {
    	private String firstName;
    	private String lastName;
    	private String emailAddress;
    	
    	private List<Response> responses;
    
    	/*  getters, setters */
    }
    These POJOs:

    Code:
    public class Response {
    	private Long id;
    	private String responseText;
    	private Question question;
    	private int index;
    
    	/*  getters, setters */
    }
    
    public class Question {
    	private Long id;
    	private String Text;
    
    	/*  getters, setters */
    }
    And the code in the template:

    Code:
    <div id="EssayQuestions">
    	#foreach($question in $questions)
    		<div class="question">$question.text</div>
    		<textarea name="responses" cols="70" rows="6"></textarea>
    	#end
    </div>
    I would, of course, like to get in my command a list of Responses with their associated question. I realize I'm going to need a custom editor and I have a basic one for the Response type (CustomResponseEditor), I just can't get Spring to try to use it on each "responses" in the webpage. I've tried a few different things, like binding the type List instead of the type Response, but tht didn't seem to be getting anywhere.

    Also, I have no idea how I'm going to indicate to the CustomResponseEditor which Question it should be associated with. My plan was to get the binder wired up, then debug to see what information I have available.

    So, my 2 questions are:

    Is there a typical paradigm for binding a series of html elements to a List/Collection object in a command and if so, can I get a pointer to some documentation?

    Is there a way to get information to that binder to make that object more complex? (e.g. a Question id in this case)

    I hope this question isn't so newb its just forum noise, thanks!
    Najati

  • #2
    I have yet to find a convenient and apparent way to find to a list of even simple objects in a command. Do PetStore/PetClinic have an example of this?

    Comment

    Working...
    X