如何在jsp中设置c:set属性中的值

时间:2014-09-17 13:10:11

标签: hibernate jsp spring-mvc jstl

您能告诉我如何设置c:set的价值。

我正在尝试将item[0]的值设置为id中的bean属性TransactionAction并将其发送到控制器类。

当我在控制器类中打印此值时,它为null。但是,我能够查看此JSP中的值。

            

            <table>

                <tr><th>ID</th>
                    <th>LOGIN ID</th>
                    <th>LAST UPDATE BY</th>
                    <th>TRANSACTION TYPE</th>
                    <th>STATUS</th>
                </tr>    
                <c:forEach var="item" items="${ToDoList}">
                    <tr>
                        <td>${item[0]}</td>
                        <td>${item[1]}</td>
                        <td>${item[2]}</td>
                        <td>${item[3]}</td>   
                        <td>${item[4]}<td>

                        <td>
                            <c:set value = "item[0]" target="${transactionAction}" property="id" />

                            <form:select path="action" tabindex="50">

                        <form:option value="----------Please select---------" />
                        <form:option value="APPROVE" label="APPROVE" />
                        <form:option value="REJECT" label="REJECT"/> 
            </li>
        </form:select>
                    </tr>
                </c:forEach>

            </table>

        </c:if>
<input type="submit" value="Submit"> 

    </form:form>

</body>
</html>

Controller类将ToDoList的值发送到上面的JSP

  public String adduser(LoginForm request,ModelMap map1) throws Exception {
    String currentUser = sessionUser.getUserName();
    System.out.println("========add user model ============================="+sessionUser.getUserName());
    String result = loginservice.adduser(request);
    List trx = loginservice.trxdetail(currentUser);
    map1.addAttribute("user", sessionUser.getUserName());
    map1.addAttribute("dateTime", sessionscopebillingdata.getDate());
    System.out.println("username from the controller class " + sessionUser.getUserName());        
    map1.addAttribute("ToDoList", trx);   
    map1.addAttribute("action",new TransactionAction());
    return "UserToDoList";
}

下面是我使用hibernate从数据库中获取值的方法

public List trxdetail(String userName) {
    Session session = sessionFactory.getCurrentSession();
    Query query;
    query = session.getNamedQuery("Loginuser.findApprover");
    query.setString("loginId", userName.toUpperCase());
    Long ownerId = (Long) query.uniqueResult();
    Query qry = session.createQuery("select lu.id,lu.loginId,lu.lastUpdateBy,trx.transactionType,trx.status from Loginuser lu , BillingSolutionTrx trx where lu.id = ref_id and owner_Trx_Id='" + ownerId + "'");
    BillingSolutionTrx transactionDetail = new BillingSolutionTrx();
    List transactionList = qry.list();


    return transactionList;
} 

1 个答案:

答案 0 :(得分:0)

在您的模型中,对象称为action而不是transactionAction

尝试将target="${transactionAction}"替换为target="${action}"