【问题标题】:How to display image button inline with text in a table cell?如何在表格单元格中显示与文本内联的图像按钮?
【发布时间】:2012-03-05 02:14:19
【问题描述】:

我有一个使用 ICEfaces 1.8 的 JSF 1.2 数据表。在一个列中,我想显示来自支持 bean 的文本,然后在它的右侧,在同一行上显示一个小图像,而不会换行。

图像实际上是一个ice:commandButton 组件,设置了图像属性。点击图片的动作是显示ice:panelPopup面板。

下面是dataTable中列的相关代码:

<ice:column id="col1">
    <ice:outputText escape="false" value="#{document.column1Value}" />
    <ice:form>
        <ice:commandButton actionListener="#{bean1.open}" image="images/popup.gif">
            <f:attribute name="docParam" value="#{document.parameter}" />                           
        </ice:commandButton>
        ...
    </ice:form>
</ice:column>

我尝试了各种添加CSS样式信息到各种标签,包括white-space:nowrapfloat,但都无法得到想要的效果。

【问题讨论】:

  • 我不确定我是否发现了问题。您已经将文本和图像按钮放在 &lt;ice:panelGrid&gt; 的一个 hacky 的 2 列表中,但它们仍然显示在彼此下方?或者您实际上是在问如何在不使用表格的情况下实现它?
  • @BalusC。 &lt;ice:panelPopup&gt; 中的图像不是问题。我想我可以把那个组件拿出来,但我把它包括在内以防万一。问题是commandButton (images/popup.gif) 中显示的图像显示在来自#{document1.column1Value} 的文本下方。我正在尝试让它们都在列单元格中内联显示。
  • 哦,我现在明白你的意思了。我已经从问题中删除了一些代码噪音并发布了答案。

标签: css jsf icefaces


【解决方案1】:

&lt;ice:form&gt; 生成 HTML &lt;form&gt;,默认情况下是 block level element,因此它总是从新行开始。您需要将&lt;form&gt;的样式设置为display: inline

<ice:form style="display: inline;">

或者,您也可以只将该文本移动到表单中。

<ice:form>
    <ice:outputText escape="false" value="#{document.column1Value}"/>
    <ice:commandButton actionListener="#{bean1.open}" image="images/popup.gif">
        <f:attribute name="docParam" value="#{document.parameter}" />                           
    </ice:commandButton>
    ...
</ice:form>

无论哪种方式,您仍然只需要在单元格的宽度没有剩余空间时防止单元格的内容被空格包裹。您可以通过在两个元素的公共父元素上设置white-space: nowrap 来实现这一点。如果是第一种方法(将表单设置为display: inline),那将是&lt;td&gt; 元素,如果是第二种方法(将文本放在同一个表单中),那将是&lt;form&gt; 元素。例如

<ice:form style="white-space: nowrap;">
    <ice:outputText escape="false" value="#{document.column1Value}"/>
    <ice:commandButton actionListener="#{bean1.open}" image="images/popup.gif">
        <f:attribute name="docParam" value="#{document.parameter}" />                           
    </ice:commandButton>
    ...
</ice:form>

(注意,style 属性在上述示例中是示例性的,实际上您应该使用 CSS 文件而不是样式类)

【讨论】:

  • 这让我想通了。我在表单中移动了 outputText 并在表单上设置了white-space:nowrap。但是为了让它工作,我必须将display:inline 添加到&lt;ice:outputText&gt;,这对我来说没有意义,因为标签只生成一个&lt;span&gt;。看看 ICEfaces 添加到跨度的 CSS 类,没有什么会导致这种情况。
  • 不客气。这确实没有意义。也许跨度的CSS在其他地方被改变了?当您执行右键单击和检查元素时,Chrome/Firebug/IE9 等 Web 开发人员工具可以针对特定元素显示所有内容。
  • 啊,是的,跨度正在其他地方设置块显示。在我使用 Firebug 之前,我没有看到这一点。谢谢。
猜你喜欢
  • 2021-11-05
  • 2012-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多