0

I have a database that stores questions inside of a Hashmap. This code is supposed to count the total amount of questions so that I have the total amount of questions rather than the highest primary key. Here is the code.

public String getTotalQuestions(HttpServletRequest request) {

Integer tId = 0;

   Iterable<QuizQuestion> quizQuestions = quizQuestionDAO.findAll();
  for(QuizQuestion quizQuestion:quizQuestions) {

    tId++;

    request.getSession().setAttribute("count",tId);

    // This just shoes me that its counting with a reminder
    System.out.println(tId);
    System.out.println("Get this number printing in the JSP");

  }
//returns to my jsp
return "dashboard/dashboard";


 }

After returning to my JSP which looks like this :

<h1>Stats Board</h1>

<%--<c:forEach var="count" items="${tId}" >--%>
<div style="color:green;font-weight: bold;">
    Total Questions:    <c:out value="${count.tId}"/>
</div>
<%--</c:forEach>--%>

My JSTL is designed to print my total amount of questions on the view. However this is my error:

javax.el.PropertyNotFoundException: Property 'tId' not found on type 
java.lang.Integer

I know that this is a similar questions to this link: Property 'someproperty' not found on type java.lang.String

But I have my setAttribute and it still does not work. where am I going wrong? Are there pieces I am using that I might not understand completely?

Community
  • 1
  • 1
JFaux
  • 23
  • 6
  • `` if you want the total. Or `` if you want it to be updated each time. – Susannah Potts Aug 24 '16 at 19:41
  • Thank you Susannah Potts. I just need the extra pair of eyes! – JFaux Aug 24 '16 at 19:48
  • Loading all the questions in memory just to know how many there are is quite inefficient. Why don't you use a query that just counts them? Also, why are you setting the attribute at each iteration of the loop, rather than after the loop? – JB Nizet Aug 24 '16 at 21:48
  • I have moved the attribute at the return now rather than in the iteration. Thats a good point tho. I am going to switch over to sql to count through my query. It will be much more efficient. – JFaux Aug 25 '16 at 02:50

0 Answers0