Announcement Announcement Module
Collapse
No announcement yet.
Lists of records(beans) with Active HTML components Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lists of records(beans) with Active HTML components

    Hi,

    I'm trying to write an application JSP which lists rows of records(beans) using Spring.
    When displayed; each record(row) must consist of multiple active HTML components (select, input, radiobuttons, etc)
    I will need to capture each component entry/update value made by the customer when the form is submitted.
    The backing form returns the list of records.
    I'm using the <c:forEach > JSP operator to list individual records.
    The problem is that the backing form doesn't have individual accessors/mutators for each field element of each record.
    (I can't know how many records will be returned until runtime)

    My development platform is Spring 2.1, SDK 1.4 (or 5) within Eclipse 3.3 with Tomcat 5.5.

    Does anyone know of example source which deals with this issue?

    Regards,
    Mark

  • #2
    Do the beans themselves have getters/setters? If so, you should be able to access them from the form. For instance, let's say that your class MyBean has a field called myField, with a getter method getMyField(). You should be able to access the field in your jsp by referring to myForm.myBean.myField.

    Are you using spring:form? If not, try it. You may find it makes things easier.

    I hope that helps. If I am misunderstanding you question, would you care to post some code?

    Comment


    • #3
      Yes, each of the records(beans) have setters and getters.
      The beans are called "DeliveryBean".
      The backingform will be called called "SubmissionBackingForm"
      The deliveriesList and deliveriesTypeSelect are provided by the backing form.

      The JSP code might look something like this:
      (if I post properly)

      Code:
      <form:form>
      <c:forEach items="${deliveriesList}" var="d">
            <tr>
      	<td><c:out value="${d.id}"/></td>					<td><c:out value="${d.deliveryDate}"/></td>
      	<td>
                   <form:select path="delivery">					             <form:option value="-" label="--Please Select"/>			<form:options items="${deliveriesTypeSelect}" />		</form:select>
      	</td>
                    <td>
       	<form:input path="d.info"/>
      	</td>
            </tr>
      </c:forEach>
      </form:form>
      The backing form code will be something like this:
      Code:
      ...
      	public List getDeliveriesList(){
      		return submitterEntryFormMgr.getDeliveriesService().getList(submitterEntryFormMgr.getTaskTicket(id));
      	}
      
      	public List getDeliveriesTypeSelect(){
      		ArrayList l = new ArrayList(6);
      		l.add("alpha");
      		l.add("bravo");
      		l.add("charlie");
      		l.add("delta");
      		l.add("echo");
      		l.add("foxtrot");
      		return l;
      	}
      ...

      Comment


      • #4
        In your form backing object, all you really need is a constructor and getter for DeliveryBean. Something like:
        Code:
        public class SubmissionBackingForm{
        	private final DeliveryBean deliveryBean= new DeliveryBean();
        	
        	public DeliveryBean getDeliveryBean (){
        		return deliveryBean;
        	}
        }

        The form backing code that you posted is best placed in the controller class, in referenceData(...). For example:
        Code:
        protected Map referenceData(HttpServletRequest request) throws Exception {
          Map model = new HashMap();
          ArrayList l = new ArrayList(6);
          l.add("alpha");
          ...
          l.add("foxtrot");
          model.put("deliveryTypes", l);
        That code would initialize the values that you would call in your jsp with something like:
        Code:
        <form:select path="submissionBackingForm.deliveryBean.deliveryType" items="${deliveryTypes}"/>
        If you want a full example, just about all of the samples included in the Spring distribution deal with this stuff. Download them, deploy them, and examine the code to find out how they tick.
        Last edited by uaine; Aug 22nd, 2008, 10:13 AM.

        Comment


        • #5
          Perhaps I'm missing something?
          Doesn't your SubmissionBackingForm code provide a reference to an individual deliveryBean?
          I have a list of deliveryBean(s) each of which has to be edited and stored from the JSP simultaneously.
          Code:
          	public List getDeliveriesList(){
          		return submitterEntryFormMgr.getDeliveriesService().getList(submitterEntryFormMgr.getTaskTicket(id));
          	}
          I suppose the workaround is to provide a link and a detail page for each deliveryBean record, something akin to what you've suggested.

          Mark

          Comment


          • #6
            Ah, alright. I didn't entirely understand what you were trying to do. You'd want something more like this then.
            Code:
            public class SubmissionBackingForm{
              private List<DeliveryBean> deliveryList;
              //somwhere, declare submitterEntryFormMgr, probably in the constructor.  It doesn't seem like you want it to be a field.
              public SubmissionBackingForm(int id){
                deliveryList = submitterEntryFormMgr.getDeliveriesService().getList(submitterEntryFormMgr.getTaskTicket(id));
              }
              public List<DeliveryBean> getDeliveryList(){
                return deliveryList;
              }
            }

            Comment

            Working...
            X