0

我的 Facelet 中有以下代码:

<ui:composition template="/templates/mastertemplate.xhtml">
    <ui:define name="pageTitle">
        <h:outputFormat value="#{msgs.productPageTitle}">
            <f:param value="#{param.productName}"/>
        </h:outputFormat>
    </ui:define>
    <ui:param name="categoryName" value="#{param.categoryName}"/>

    <ui:define name="content">
        <p>#{param.productName}</p>
        <h:form>
            <h:commandLink action="#{cartBean.addItemToCart(param.productName)}">
                <f:ajax event="action" render=":cart :cartPrice" />
                <h:graphicImage value="resources/img/addToCart.gif"/>
            </h:commandLink>
        </h:form>
    </ui:define>
</ui:composition>

#{param.productName}它按应有的方式打印。cartBean期望 aString作为其方法的参数(addItemToCart我知道这很糟糕,但不是我的选择)。我在我的设置了一个记录器,cartBean它告诉我参数没有通过,它是空的。

如果我执行以下操作:

<h:commandLink action="#{cartBean.addItemToCart('someProductName')}">
    <f:ajax event="action" render=":cart :cartPrice" />
    <h:graphicImage value="resources/img/addToCart.gif"/>
</h:commandLink>

我用#{param.productName}字符串文字代替,它工作正常。为什么我不能将参数值作为参数传递?我得到一个EvaluationException解释为什么我的记录器看到一个空字符串但我不明白我应该怎么做。

4

1 回答 1

0

不确定是否有可能,但至少这似乎是不好的做法。您将在没有任何验证/转换选项的情况下将字符串插入到您的支持中。

我找到了一个教程,它解释了你应该怎么做才能让它在这里工作。

于 2012-12-28T19:45:23.717 回答