myfaces 2.1 h:commandButton呈现“提交查询”

时间:2012-11-27 17:27:19

标签: jsf-2 myfaces

奇怪的问题,我已阅读过各种帖子,但尚未找到合适的答案。

当我有一个h:commandButton,我想要一个图标来显示而不是文本,我试过了。

<h:commandButton value=" " image="UpArrow.png" style="position: absolute; left: 36px; top: 17px; width: 18px; height: 18px; cursor: pointer;" title="Pan up" actionListener="#{SarWindsImagesBean.panUp('testImage.jpg')}">
    <f:ajax  render="imagePan2"/>
</h:commandButton>

<h:commandButton image="UpArrow.png" style="position: absolute; left: 36px; top: 17px; width: 18px; height: 18px; cursor: pointer;" title="Pan up" actionListener="#{SarWindsImagesBean.panUp('testImage.jpg')}">
    <f:ajax  render="imagePan2"/>
</h:commandButton>

首先,大小是正确的,但我得到“提交查询”而不是图像。 在第二个,我遇到了同样的问题。

为什么呈现“提交查询”?如果我添加value =“”,它将不会显示图标,只显示一个空框。

1 个答案:

答案 0 :(得分:1)

当省略<input type="submit">属性时,这是HTML value元素的浏览器默认值。这不是由JSF生成的。在纯HTML页面中使用这样的HTML元素自己尝试一下。

至于为什么在value属性存在时添加image属性会导致出现一个空框,这可能是MyFaces特有的。我无法在Mojarra中重现它。

至于(ab)使用image属性来呈现背景图像,这毕竟不完全正确。您应该使用CSS background-image属性,

<h:commandButton value=" " style="background-image: url(UpArrow.png)" />

或只是一个<h:commandLink><h:graphicImage>,如果您根本不想看到按钮的外观:

<h:commandLink ...>
    <h:graphicImage value="UpArrow.png" />
</h:commandLink>
相关问题