2012-12-27 22 views
0

我在我的facelet下面的代碼:通過URL參數去後臺bean的方法

<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預計String作爲其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這解釋了爲什麼我的記錄器看到一個空字符串,但我不明白我應該如何做到這一點。

回答

0

不知道這是否可能,但至少這似乎是不好的做法。您可以在沒有任何驗證/轉換選項的情況下將字符串插入您的支持。

我找到了一個教程,解釋你應該如何使它工作here