Announcement Announcement Module
No announcement yet.
Display a list of objects and add new object to it (for example 'user comments') Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Display a list of objects and add new object to it (for example 'user comments')

    Does anyone know if there's common way of displaying a list of objects and allowing the user to add new entry to the list via a form, for example something like adding comments to a page? Is there a standard way of doing this?

    I've got an object that has a list of 'Note' objects. I display the object and the notes on the page no problem, but I want to allow the user to add a new note on that page and save it, and then return the page with the new note. I also need to validate the note and the way it's looking at the moment I've ended up adding two properties to my backing form:

    class MyObject {
    List<Note> notes;
    String name;
    class Note {
    String username;
    Date insertionDate;
    String note;
    Note newNote;
    List<Note> noteList;
    newNote is used to bind to an input field
    noteList is simplY looped through and displayed on the page as text, it's not bound to any inputs

    Is there a standard way of displaying the current notes as text on the page when I view 'MyObject', but also provide an input field for a new note to be added without having to add two properties?

    Thanks in advance

  • #2
    All the data you display on the page doesn't need to be in your form-backing bean. To display the list of notes, just use the list that's on the MyObject instance--add that instance to the modelMap and it becomes a request attribute. To create a new note, just use Note as the form-backing bean and add myObjectId to it so you can link the two. So do this:

    1. Use form that binds to Note instance (just create an empty instance of Note in your detail controller method so it's available in the JSP).
    2 Post to controller method that binds to Note
    3. Create note associated with MyObject instance
    4. Redirect back to the detail page that shows MyObject instance with the notes. The redirect will invoke your detail controller method.

    This is assuming you are adding one note at a time and refreshing the entire page everytime a new note is added.