0

I'm trying to write a condition to jstl if tag,

        <c:forEach var="ledg" items="user_ledgers">

            <c:if test="${ledg.transactionID == param['trns']}">

                <c:out value="${ledg.name}"/>
            </c:if>
        </c:forEach>

Ledg is an object of ledger class and transactionID is a field of type long.

I found this error while runtime.

javax.el.PropertyNotFoundException: Property 'transactionID' not found on type java.lang.String

I tried to convert transactioID value to String by several ways. But not working

String concatination

<c:if test="${(ledg.transactionID+’’) == param['trns']}">

Using custom tag

            <c:set var="equals" scope="page">
                <z:doTheyEquals v1="${ledg.transactionID}" v2="${param['trns']}"/>
            </c:set>

It also expects String type.

Setting user_ledges to session scope

            LedgerDAO ledg = Data.getLedgerDAO();
            List ledgers = ledg.getLedgers(u);
            session.setAttribute("user_ledgers",ledgers);

getLedgers()

public List<Ledger> getLedgers(User u) {
        List ledgers = new ArrayList<Ledger>();
        try (Connection conn = pool.getConnection()){
            PreparedStatement query = conn.prepareStatement("SELECT * FROM user_ledgers INNER JOIN ledgers ON user_ledgers.l_id = ledgers.id WHERE user_ledgers.u_id=? ORDER BY name ASC;");
            query.setString(1,u.getId()+"");
            ResultSet rs = query.executeQuery();
            while(rs.next()){
                Ledger l = new Ledger();
                l.setId(rs.getLong(4));
                l.setName(rs.getString(5));
                l.setLayout(rs.getString(7));
                l.setTransactionID(rs.getLong(3));
                l.setType(rs.getString(6));
                ledgers.add(l);
            }
        } catch (Exception e) {
            e.printStackTrace();
            ledgers=null;
        }
        return ledgers;
    }

Any help? Thank you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jBugger
  • 31
  • 5
  • How are you passing the user_ledgers object into the JSP? The exception you are receiving clearly states that the ledg object is a String. – DSF Mar 27 '15 at 06:36
  • user_ledgers is a List which contains set of ledger objects and located at session scope as an attribute. – jBugger Mar 27 '15 at 06:44
  • Post the code on how you do that. – DSF Mar 27 '15 at 06:48

1 Answers1

0

Use this:

<c:forEach var="ledg" items="${sessionScope.user_ledgers}">
            <c:if test="${ledg.transactionID == param['trns']}">
                <c:out value="${ledg.name}"/>
            </c:if>
  </c:forEach>
DSF
  • 804
  • 7
  • 15
  • This is the code which cause above error. javax.el.PropertyNotFoundException: Property 'transactionID' not found on type java.lang.String – jBugger Mar 27 '15 at 07:06
  • No. I've replaced items="sessionScope.user_ledgers" with items="${sessionScope.user_ledgers}". Problem was you were not reading the list properly. – DSF Mar 27 '15 at 07:07