2016-05-06 62 views
1

現在,customerCaseController.customerCase.caseId是一串數字,並且正在工作,如果我只是將它作爲標題或標籤打印在xhtml頁面上。如何通過JSF參數的值作爲方法參數?

我想調用的方法findByCustomerCase(String caseId)在我fileAttachmentController但這不是工作:

<f:param customerCase="#{customerCaseController.customerCase.caseId}" /> 
    <p:dataTable var="fileAttachment" 
    value="#{fileAttachmentController.findByCustomerCase(customerCase)}"> 

    ...table-contents... 

    </p:dataTable> 

這將文本「customerCase」作爲參數只是傳遞給方法findByCustomerCase和沒有價值參數customerCase。我怎麼能通過這個價值?

回答

2

您的問題是您使用的方式不正確,請使用f:param。該元素不用於定義局部變量。這意味着customerCase在這一點上不是一個有效的變量。

您正在訪問customerCaseController.customerCase.caseId而不僅僅是customerCase,因此您需要傳遞與參數完全相同的值,並跳過整個f:param

你的代碼更改爲以下以訪問所需caseId

<p:dataTable var="fileAttachment" 
value="#{fileAttachmentController.findByCustomerCase(customerCaseController.customerCase.caseId)}"> 

...table-contents... 

</p:dataTable> 

如果你想保持的保持一個局部變量考慮下面的,而不是f:param方式:

<ui:param name="customerCase" value="#{customerCaseController.customerCase.caseId}" /> 

XML命名空間:xmlns:ui="http://java.sun.com/jsf/facelets"

這將允許您使用上面的代碼。只需用此代碼替換f:param即可。

+0

謝謝!這樣可行。我想我只是不習慣於xhtml的一面。提出ui:param +1。 –