0

I've read the same problem solutions, but it didn't helped me. there is a part of my Bean class with good written getter:

@Entity
@Table(name = "notes")
public class Note {
    @Id
    @GeneratedValue (strategy = GenerationType.IDENTITY)
    @Column (name = "id")
    private int id;    
    @Column (name = "content")
    private String content;


    public Note() {
    }

    public Note(String title, String content, GregorianCalendar date, boolean done) {
        this.title = title;
        this.content = content;
        this.date = date;
        this.done = done;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }    

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    } 
}

Using debug mode i can see, that i've got my ArrayList of notes from dataBase. It means, that connection is good. there is a code from servlet:

public static final String OUTPUT_LIST = "List For Pager";

// other code, not nessesary for showing  

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            Integer pageNumber =  (Integer) req.getAttribute(PAGE_NUMBER);
            if(pageNumber==null) pageNumber = 1;
            ArrayList<Note> result = new ArrayList<Note>();
            ArrayList<Note> notes = DaoDriver.getActualNotesHandler().getNotesList();
            //iteration method for filling result
            fillListForPage(pageNumber,notes,result);
            req.setAttribute(OUTPUT_LIST,result);
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("/index_test.jsp");
            requestDispatcher.forward(req,resp);

There is a place, where i call my list from jsp:

<c:forEach var="note" items="${MainServlet.OUTPUT_LIST}">

      <div class="row" padding="5" >
        <div class="card-deck">
          <div class="card">
            <div class="card-header">Title1</div>
            <div class="card-body"><p>${note.content}</p></div>
            <div class="card-footer">
              <input type="checkbox" class="Done">
              <label>Done</label>
              <button>Edit Note</button>
            </div>
          </div>

    </c:forEach>

i have additional problem here, that can crash my application. I have the same situation, like in this question: JPA Cannot resolve column/IntelliJ

but i have my data associated and quick fix doesn't resolve this problem.

what is wrong with my code?

UPD: I've fixed this problem by changing 2 strings:

req.setAttribute("list",result);

and

<c:forEach var="note" items="${list}">

And that's why i have new question: why can't i use the staic final string value (constant) from MainServlet.class for the key of request's property?

Mr.Mazle
  • 9
  • 2
  • Could you try simply printing the value of the expression you use for items outside the forEach and inside only the class of note? – jokster Sep 24 '18 at 05:56

1 Answers1

-1

Try changing ${MainServlet.OUTPUT_LIST} to ${requestScope.OUTPUT_LIST}

<c:forEach var="note" items="${requestScope.OUTPUT_LIST}">
Huy Nguyen
  • 1,931
  • 1
  • 11
  • 11