![](/img/trans.png)
[英]How to pass parameter in value expression and method expression in JSF 2?
[英]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.