【问题标题】:How to change output text conditionally [duplicate]如何有条件地更改输出文本[重复]
【发布时间】:2017-03-22 21:59:52
【问题描述】:

我有一个列gst_invoice_type 的供应商表。该表有两行,值为 F 和 S。

在我的 PrimeFaces 数据表中,我还创建了一个包含 Gst_Invoice_Type 列的表,其下拉菜单过滤器如下代码

<p:column filterBy="#{vo.gstInvoiceType}" headerText="GST Invoice Type." sortBy="#{vo.gstInvoiceType}"
                        style="width:130px;" visible="false">
                    <f:facet name="filter">
                        <p:selectOneMenu style="width:110px; vertical-align:middle;" autoWidth="false"
                        onchange="PF('varTable').filter()">
                            <f:selectItem itemLabel="ALL" itemValue="" noSelectionOption="true" />
                            <f:selectItem itemLabel="Full Tax Invoice" itemValue="F" />
                            <f:selectItem itemLabel="Simplified Invoice" itemValue="S" />
                        </p:selectOneMenu>
                    </f:facet>
                    <h:outputText value="#{vo.gstInvoiceType}"/>
                </p:column>

When select All, all data (F and S) will be retrieved and located in Gst_Invoice_Type, which working correctly.但是是否可以让 F 和 S 显示为 Full Tax Invoice 和 Simplified Invoice ?

【问题讨论】:

  • 对不起,我不明白。请详细说明您想要什么或问题所在。
  • @irieill 好的。我在 MySQL 中有 FS 的值。有没有办法让 PrimeFaces dataTable 中的 F 显示为 Full Tax Invoice 和 S 显示为 Simplified Invoice ?

标签: jsf labels conditional-rendering


【解决方案1】:

只需插入两个具有不同值的有条件渲染的&lt;h:outputText /&gt; 元素。

<p:column>
  <h:outputText
    value="Full Tax Invoice"
    rendered="#{vo.gstInvoiceType eq 'F'}"
  />
  <h:outputText
    value="Simplified Invoice"
    rendered="#{vo.gstInvoiceType eq 'S'}"
  />
</p:column>

另一种选择是在 bean 方法中以编程方式进行映射,例如:

<p:column>
  <h:outputText value="#{bean.map(vo.gstInvoiceType)}" />
</p:column>

public class Bean {
  public String map(String input) {
    // however you implement your mapping
  }
}

【讨论】:

  • 谢谢,但是如果我有一个有 100 行的案例,并且某些列包含空,您的答案会起作用吗?
  • @AI。当然它会起作用(为不同的情况写下更多的代码)。
猜你喜欢
  • 2020-01-21
  • 1970-01-01
  • 1970-01-01
  • 2019-07-22
  • 2018-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多