javajsprequestscope

How can I get the value of an object inside an object by requestscope?


I have many children of class object inside a big class object. I have set value for those child object and I want them to be printed in my jsp page through request scope. How do I implement this in jsp?

My big class object

public class BookUser implements Serializable {

    private Books book;
    private Users user;

    public BookUser() {
    }

    public Books getBook() {
        return book;
    }

    public void setBook(Books book) {
        this.book = book;
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }
}

My jsp

<c:set var="listBookNew" value="${requestScope.LISTALLBOOKORIGINAL}"/>
        <c:if test="${not empty listBookNew}">
            <table border="1">
                <thead>
                    <tr>
                        <th>Id</th>
                        <th>Title</th>
                        <th>Price</th>
                        <th>Quantity</th>
                        <th>Date</th>                       
                    </tr>
                </thead>
                <tbody>
                    <c:forEach var="dtoX" items="${listBookNew}">
                        <tr>
                            <td>${dtoX.book.id}</td>
                            <td>${dtoX.book.bookTitle}</td>
                            <td>${dtoX.book.price}</td>
                            <td>${dtoX.book.quantity}</td>
                            <td>${dtoX.book.bookDate}</td>                       
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </c:if>

Edit: I was typing my requestscope attribute name wrong. Sorry everyone and thank you all for your time reading this.


Solution

  • You could add c:set in-between forEach and tr like below:

    <c:forEach var="dtoX" items="${listBookNew}">
        <c:set var="book" value="${dtoX.book}"/>
        <c:set var="user" value="${dtoX.user}"/>
        <tr>
            <td>${book.id}</td>
            <td>${book.bookTitle}</td>
            <td>${book.price}</td>
            <td>${book.quantity}</td>
            <td>${book.bookDate}</td>                       
        </tr>
        <tr>
            <td>${user.id}</td>
           ...                    
        </tr>
    </c:forEach>