【问题标题】:Using an image as a label of p:selectOneRadio使用图像作为 p:selectOneRadio 的标签
【发布时间】:2014-08-07 06:49:37
【问题描述】:

鉴于以下<p:selectOneRadio>列表。

<p:selectOneRadio layout="grid" columns="1" value="#{1}">
    <f:selectItem id="paypal" itemValue="1" itemLabel="Paypal"/>
    <f:selectItem id="wireTransfer" itemValue="2" itemLabel="Wire Transfer"/>
</p:selectOneRadio>

是否可以将图像显示为&lt;f:selectItem&gt; 的标签,以便列表如下所示?

我尝试使用&lt;p:outputLabel&gt;&lt;p:graphicImage&gt; 放置在内部,并从&lt;p:selectOneRadio&gt; 内部的&lt;f:selectItem&gt; 中删除itemLabel 属性,但无论哪种方式都不起作用。

<p:outputLabel for="paypal">
    <p:graphicImage library="default" name="images/payments/paypal_logo.jpeg"/>
</p:outputLabel>

【问题讨论】:

标签: jsf primefaces jsf-2.2 selectoneradio


【解决方案1】:

您可以使用SelectOneRadio - Custom Layout 解决它

这里是一个例子:

<h3>Custom Layout</h3>
<p:outputPanel id="customPanel" style="margin-bottom:10px">
    <p:selectOneRadio id="customRadio" value="#{radioView.color}" layout="custom">
        <f:selectItem itemLabel="Red" itemValue="Red" />
        <f:selectItem itemLabel="Green" itemValue="Green" />
        <f:selectItem itemLabel="Blue" itemValue="Blue" />
    </p:selectOneRadio>

    <h:panelGrid columns="3" cellpadding="5">
        <p:radioButton id="opt1" for="customRadio" itemIndex="0" />
        <h:outputLabel for="opt1" value="Red" />
        <p:spinner />

        <p:radioButton id="opt2" for="customRadio" itemIndex="1" />
        <h:outputLabel for="opt2" value="Green" />
        <p:inputText />

        <p:radioButton id="opt3" for="customRadio" itemIndex="2" />
        <h:outputLabel for="opt3" value="Blue" />
        <p:calendar />
    </h:panelGrid>
</p:outputPanel>

【讨论】:

  • 这个答案不能解决问题。我尝试使用 h:graphicImage 而不是 h:outputLabel。单击图像不会选择单选按钮。
【解决方案2】:
<p:selectOneRadio id="customRadio" value="#{radioView.image}" layout="custom">
    <f:selectItem itemLabel="Image1" itemValue="Image1" />
    <f:selectItem itemLabel="Image2" itemValue="Image2" />
</p:selectOneRadio>
<h:panelGrid columns="2" cellpadding="5">
    <p:radioButton id="opt1" for="customRadio" itemIndex="0" />
    <h:graphicImage value="/some/image2.png"/>
    <p:radioButton id="opt2" for="customRadio" itemIndex="1" />
    <h:graphicImage value="/some/image2.png"/>
<h:panelGrid columns="3" cellpadding="5">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 2011-10-30
    • 1970-01-01
    • 2013-11-06
    • 2016-11-26
    相关资源
    最近更新 更多