JSF的"total"变量类似于JSTL中的c:set [英] JSF 'total' variable something like c:set in JSTL

查看:59
本文介绍了JSF的"total"变量类似于JSTL中的c:set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不喜欢JSF,但是我需要用它来解决这个问题,我正在纯" JSF中工作. 所以这是我迫切需要的,但是我不知道如何用JSF完成它:

I don't like JSF but I need to solve this problem with it, I am working in "pure" JSF. So this is what I baisicly need but I don't know how to accomplish it with JSF:

<c:set var="total" value="0"></c:set>

<c:forEach var="item" items="${cart}">
    <tr>
        <td>${item.product.name}</td>
        <td>${item.product.price}</td>
        <td>${item.quantity}</td>
        <td>${item.product.price * item.quantity}</td>
    </tr>
    <c:set var="total" value="${total + item.product.price * item.quantity}"></c:set>
</c:forEach>

现在,如您所知,我可以使用简单的$ {total}来显示总价值.

Now I can display total value with simple ${total} as u know.

我的JSF表如下:

    <h:dataTable var="item" value="#{mbProducts.cart_items}" binding="#{mbProducts.tableComponent}" border="1">

        <h:column>
            <f:facet name="header">
                <h:outputText value="NAME" />
            </f:facet>

            <h:outputText value="#{item.product.name}" />
        </h:column>

        <h:column>
            <f:facet name="header">
                <h:outputText value="PRICE" />
            </f:facet>

            <h:outputText value="#{item.product.price}" />
        </h:column>

        <h:column>
            <f:facet name="header">
                <h:outputText value="NUM" />
            </f:facet>

            <h:outputText value="#{item.quantity}" />
        </h:column>

        <h:column>
            <f:facet name="header">
                <h:outputText value="TOTAL PRICE" />
            </f:facet>

            <h:outputText value="#{item.product.price * item.quantity}"/>
        </h:column>

    </h:dataTable>

但是我不知道如何设置将在每次迭代中增加的总变量? 该怎么解决?!

But I don't know how to set total variable which will be increased in each iteration? How to solve this?!

推荐答案

为什么不只在后备bean中进行计算,而只是使用jsf检索呢?

why dont you just do the calculation in the backing bean and just use jsf to retreive it?

要回答您的问题,我不知道仅使用JSF库设置变量的可能性.

And to answer your question, i don't know of a possiblity to set variables using just JSF libraries.

这篇关于JSF的"total"变量类似于JSTL中的c:set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆