Announcement Announcement Module
Collapse
No announcement yet.
Iteration through bean property type ArrayList Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Iteration through bean property type ArrayList

    I have a bit of a problem with performing actions on bean properties. Here is the problem:

    I have a class looking like this:

    Code:
    public class EducationBean implements Serializable {
    
    	private ArrayList<DiplomaBean> diplomas;
    
    	public void setDiplomas(ArrayList<DiplomaBean> diplomas) {
    		this.diplomas = diplomas;
    	}
    
    	public ArrayList<DiplomaBean> getDiplomas() {
    		return diplomas;
    	}
    }
    It is supposed to contain ArrayList of members of class DiplomaBean:

    Code:
    public class DiplomaBean implements Serializable {
    
    	private String diplomaIssuerRank;
    
    	private String diplomaIssuerName;
    
    	private String diplomaNumber;
    
    	private String diplomaIssueDate;
    
    	public void setDiplomaIssuerRank(String diplomaIssuerRank) {
    		this.diplomaIssuerRank = diplomaIssuerRank;
    	}
    
    	public String getDiplomaIssuerRank() {
    		return diplomaIssuerRank;
    	}
    
    	public void setDiplomaIssuerName(String diplomaIssuerName) {
    		this.diplomaIssuerName = diplomaIssuerName;
    	}
    
    	public String getDiplomaIssuerName() {
    		return diplomaIssuerName;
    	}
    
    	public void setDiplomaNumber(String diplomaNumber) {
    		this.diplomaNumber = diplomaNumber;
    	}
    
    	public String getDiplomaNumber() {
    		return diplomaNumber;
    	}
    
    	public void setDiplomaIssueDate(String diplomaIssueDate) {
    		this.diplomaIssueDate = diplomaIssueDate;
    	}
    
    	public String getDiplomaIssueDate() {
    		return diplomaIssueDate;
    	}
    
    	@Override
    	public String toString() {
    		return "Diploma [diplomaIssuerRank=" + diplomaIssuerRank
    				+ ", diplomaIssuerName=" + diplomaIssuerName
    				+ ", diplomaNumber=" + diplomaNumber + ", diplomaIssueDate="
    				+ diplomaIssueDate + "]";
    	}
    	
    	public String webCast() {
    		return "<div class=\"diploma-data\">" + this.toString() + "</div>";
    	}
    
    }
    What I want to do Is to create the JSP that will list the teasers of each item in the ArrayList and give the possibility to edit each of the list nodes or delete it (main idea is that you can add new diplomas to your education histrory, edit them or remove). I got stuck on the following:

    Code:
    <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ page import="java.util.ArrayList, put.ksantypa.candidate.beans.EducationBean, put.ksantypa.candidate.beans.DiplomaBean;" %>
    <h1>Educational background</h1>
    
    <form:form>
    	<jsp:useBean id="educationBean" class="put.ksantypa.candidate.beans.EducationBean"/>
    	<!-- <% out.println(educationBean.webCast()); %> -->
    	
    	
    	<c:forEach var="diploma" items="educationBean.diplomas">
    		<c:out value="${diploma.webCast()}"/>
    	</c:forEach>
    	
    	
    	<input type="submit" id="save" name="_eventId_save" value="Save" />
    </form:form>
    Bean educationBean is added to xml with mvc configuration. However server fails to generate servlet out of JSP due to errors with accessing bean property or something alike. Is there any easy way to creaste such page (I might be going wrong way, please, correct me, any help is welcome).

  • #2
    Probably this would work (and, by the way, c:out will encode your <div></div> tag, so you probably don't need to use both c:out and HTML generation in Java code):
    Code:
    public class DiplomaBean implements Serializable {
    	...
    
    	public String getWebCast() {
    		return "<div class=\"diploma-data\">" + this.toString() + "</div>";
    	}
    
    }
    Code:
    ...
    	<c:forEach var="diploma" items="educationBean.diplomas">
    		<c:out value="${diploma.webCast}"/>
    	</c:forEach>	
    ...
    Last edited by axtavt; Nov 30th, 2009, 11:04 AM.

    Comment


    • #3
      should do the trick but it does not:/ maybe it has something to do with the use of WebFlow. All I am trying to get is a page looking like this:

      Your diplomas:

      First diploma teaser <edit> <delete>
      Second diploma teaser <edit> <delete>
      ...

      ( with information taken from educationBean.diplomas ) and after clicking edit I want to be redirected to a form with fields bound to the fields (properties) of the corresponding DiplomaBean instance that is contained in the ArrayList educationBean.diplomas .

      Comment


      • #4
        Solved!

        ok, my fault, I have made some changes to the code and discovered that update of Web Flow library to 2.0.8 solves problem with mapping (thefre was an issue with using bean both as bind model and in jstl core tags results in random errors (probably something with acces to the bean).

        Comment

        Working...
        X