如何预选 h:selectOneMenu 的选项 [英] How to preselect an option of h:selectOneMenu

查看:21
本文介绍了如何预选 h:selectOneMenu 的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从选择菜单中预先选择其中一个选项?

Is it possible to preselect one of the options from the select menu?

我有这个 UI 组件:

I have this UI Component:

<h:selectOneMenu value="#{authenticateController.country}">
    <f:selectItems value="#{constants.countrySelectMenu}" />
</h:selectOneMenu>

#{constants.countrySelectMenu} 的值是国家 ID - 国家名称对的列表.有没有办法使用预选值呈现列表,或者至少有解决方法来完成这项工作?

The values of #{constants.countrySelectMenu} are a list of country ID - country name pairs. Is there a way to render the list with a preselected value or at least is there a work-around to get this done?

推荐答案

只需将 后面的属性预设为所需的值即可.您可以在例如 bean 的 (post) 构造函数、action(listener) 方法等中执行此操作.

Just preset the property behind <h:selectOneMenu value> with the desired value. You can do it in for example the bean's (post)constructor, action(listener) method, etc.

在您的具体示例中,例如

In your specific example, thus e.g.

public class AuthenticateController {

    private String country;

    @PostConstruct
    public void init() {
        country = "NL";
    }

    // ...
}

它对所有其他 的工作方式完全相同UIInput 组件,如 <h:inputText> 等.输入组件的值本身只是表示(预)选择/检查/填充的值.

It works exactly the same way for all other UIInput components like <h:inputText> and so on. The input component's value itself simply represents the (pre)selected/checked/filled value.

这篇关于如何预选 h:selectOneMenu 的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆