繁体   English   中英

如何通过JSF param的值作为方法参数?

[英]How to pass JSF param's value as method parameter?

现在,customerCaseController.customerCase.caseId是一个数字字符串,如果我将其作为标题或标签打印在xhtml页面上,则可以正常工作。

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

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

   ...table-contents...

   </p:dataTable>

只需将文本“ customerCase”作为参数传递给方法findByCustomerCase,而不是参数customerCase的值。 如何传递价值?

您的问题是您使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM