如何将JSF param的值作为方法参数传递?

时间:2016-05-06 12:22:58

标签: java primefaces jsf-2.2 param method-parameters

现在,customerCaseController.customerCase.caseId是一串数字,如果我只是将它作为标题或标签打印在xhtml页面上,它就可以了。

我想在findByCustomerCase(String caseId)中调用方法fileAttachmentController,但这不起作用:

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

   ...table-contents...

   </p:dataTable>

这只会将文本“customerCase”作为参数传递给方法findByCustomerCase,而不是param customerCase的值。我该如何传递该值?

1 个答案:

答案 0 :(得分: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-Namespace:xmlns:ui="http://java.sun.com/jsf/facelets"

这将允许您使用上面的代码。只需使用此代码段替换f:param