2016-05-06 63 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。 –