java - Ho 获取 HTTP 输入字段值并使用它来使用 c :if 进行一些测试

标签 java html jsp jstl

我这里有一个 Spring MVC 应用程序。打开菜单页面时,我将放置两个模型属性:menuList 和 orderList。 menuList 填充了来自数据库的信息,orderList 是空列表,当客户端要提交动态表单时,我希望将其填满。我知道如何绑定(bind)订单列表中菜单中的所有产品,但这会浪费...很多东西。我需要做的是检查每个产品旁边动态附加的输入字段“pieces”的值或长度是否大于 0。我该怎么做?

<c:url value="/menu/order" var="orderPath"/>
<form:form action="${orderPath}" method="POST" modelAttribute="orderList">
    <table>
        <tr>                    
            <th>Name</th>
            <th>Code</th>
            <th>Price</th>
            <th>Description</th>
            <th>Calories</th>
            <th>Image</th>
            <th>Pieces</th>
        </tr>

        <c:set var="index" value="0" scope="page" />

        <c:forEach items="${menuList}" var="menu" varStatus="i">
            <tr>                    
                <td>${menu.name}</td>
                <td>${menu.code}</td>
                <td>${menu.price}</td>
                <td>${menu.description}</td>
                <td>${menu.calories}</td>
                <td><img src="<c:url value="/images/${menu.image}" />" alt="" width=120></td>
                <td><input type="text" name="pieces"></td>

                <!-- i need to take the "pieces" input field value here and check it if,                     
                 lets say, the length is greater than 0 (or the value is greater than 0)
                 and to make data binding only in those situations
                 I saw something like <c:if test="${param.pieces}>0"> but that's not working
                 or maybe i'm doing some kind of mistake, i don't know
                -->

                 <!--start: this code should be executed if the condition is evaluated to true -->
                    <form:hidden path="orderList[${index}].orderID"/>
                    <form:hidden path="orderList[${index}].menuID" value="${menu.menuID}"/>
                    <form:hidden path="orderList[${index}].pieces" value="**value-of-pieces-input-field**"/>
                    <c:set var="index" value="${index + 1}" scope="page" />
                 <!--end -->
            </tr>
        </c:forEach>
        <tr>
            <td colspan="2">
                <input type="submit" value="Make an order"/>
            </td>
        </tr>
    </table>        
</form:form> 

最佳答案

你已经很接近了。

<c:if test="${param.pieces > 0 }">
    <form:hidden path=.../>
</c:if>

关于java - Ho 获取 HTTP 输入字段值并使用它来使用 c :if 进行一些测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24963869/

相关文章:

java - 如何在 Java 中检查字符串的多个可能值

java - 如何使用来自另一个 JSP 的参数进行查询

java - 获取错误: connect ECONNREFUSED while making active MQ Connection?

Java文件删除和System.gc()

html - 如何控制嵌套 <p><a> 中文本的溢出行间距

javascript - Vue 如何在加载数据填充工作表之前将文本作为 v-card 中的占位符?

javascript - 如何连续从右向左移动图像/div?

jsp - 如何在jsp中设置request.getParameter :setProperty

java - 带有动态 html 的 JSP 页面

java - 为什么 one ceil 函数给出不同的答案?