You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JSF技术问询:<f:setPropertyActionListener>无法在<h:graphicImage>中使用?

关于<f:setPropertyActionListener>的使用疑问

每次尝试在<h:graphicImage>标签内使用<f:setPropertyActionListener>时都会出现错误,原代码如下:

<h:graphicImage value="/images/h.png">
     <f:setPropertyActionListener target="#{pokemonController.haarfarbe}" value="h" />
</h:graphicImage>

请问该组件是否仅能与<h:commandButton>配合使用?

编辑补充:正确用法如下

<h:commandLink action="Augenfarbe.xhtml">
      <h:graphicImage value="/images/h.png" />
      <f:setPropertyActionListener target="#{pokemonController.hautfarbe}" value="h" />
</h:commandLink>

解答

<f:setPropertyActionListener>并非只能和<h:commandButton>配合,但它必须依附于具备表单提交能力的UICommand类组件,比如<h:commandButton>、<h:commandLink>这类能触发POST请求提交表单的组件。

<h:graphicImage>属于纯展示型组件,本身不具备触发表单提交的能力,所以无法承载<f:setPropertyActionListener>。你补充的正确用法逻辑是对的:将图片放在<h:commandLink>内部,借助<h:commandLink>的表单提交能力,让监听器能够正常执行属性赋值操作。

内容的提问来源于stack exchange,提问作者yothats.ju

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 12:06:29