1

我有一个 selectOneRadio 菜单,其中包含一些 selectItem。我想显示基于属性文件的选择。例如,如果一家商店没有信用卡读卡器,那么我就不会显示信用卡选项。应该有一个配置/属性文件来指定显示的内容和不显示的内容。

有没有办法做到这一点?我假设我需要将属性文件读入支持 bean,然后有类似“渲染”属性的东西。但是,我刚刚尝试过,“渲染”似乎不适用于 selectItem。

<h:selectOneRadio id="selectedPaymentMethod" layout="pageDirection" 
        value="#{selectPaymentMethodAction.selectedPaymentMethod}">

    <f:selectItem itemValue="online" itemLabel="#{paymentMsg['payment.online.lbl']}"/>
    <f:selectItem itemValue="cash" itemLabel="#{paymentMsg['payment.cash.lbl']}"/>
    <f:selectItem itemValue="credit" itemLabel="#{paymentMsg['payment.credit.lbl']}"/>
    <f:selectItem itemValue="debit" itemLabel="#{paymentMsg['payment.debit.lbl']}"/>

</h:selectOneRadio>
4

1 回答 1

2

使用<f:selectItems>您提供的List<SelectItem>基于捆绑文件的文件。通过这种方式,您可以使用通常的 Java 代码来控制是否应该添加该项目。

例如

<f:selectItems value="#{selectPaymentMethodAction.paymentMethods}" />

private List<SelectItem> paymentMethods; // +getter

public Bean() {
    paymentMethods = new ArrayList<SelectItem>();
    ResourceBundle bundle = ResourceBundle.getBundle("com.example.Messages", FacesContext.getCurrentInstance().getViewRoot().getLocale());

    if (condition) {
        paymentMethods.add(new SelectItem("online", bundle.getString("payment.online.lbl")));
    }

    // ...
}
于 2011-03-16T23:00:05.737 回答