jsf - 我应该如何初始化 f:selectOneRadioButton 组件?
问题描述
我认为这是唾手可得的成果,但我和我的同事每天都在讨论诸如此类的事情。
所以我的视图上有多个单选按钮,大约 10...
我应该直接在构造函数中将单选按钮标签和值初始化为 Map,创建封装方法并从构造函数调用它,在静态初始化块中构建列表,还是应该在视图中硬编码?有很多方法可以实现目标,但我不知道什么是最佳实践
public RadioButtonBean(){
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
}
或者
public RadioButtonBean(){
this.loadRadioButtonSelection();
}
private void loadRadioButtonSelection(){
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
this.radioButtonSelection.put(“Age”,”Age”);
}
与视图
<f:selectOneRadioButton value=“#{radioButtonBean.selection}”>
<f:selectItems value=“#{radioButtonBean.radioButtonSelection}”/>
</f:selectOneRadioButton>
或者就这个
<f:selectOneRadioButton value=“#{radioButtonBean.selection}”>
<f:selectItem value=“Age” label=“Age”/>
<f:selectItem value=“Age” label=“Age”/>
<f:selectItem value=“Age” label=“Age”/>
<f:selectItem value=“Age” label=“Age”/>
<f:selectItem value=“Age” label=“Age”/>
<f:selectItem value=“Age” label=“Age”/>
<f:selectItem value=“Age” label=“Age”/>
<f:selectItem value=“Age” label=“Age”/>
<f:selectItem value=“Age” label=“Age”/>
<f:selectItem value=“Age” label=“Age”/>
</f:selectOneRadioButton>
解决方案
推荐阅读
- angular - 如何修复错误:断言错误:应该在更新模式下运行 [预期 => 假 == 真 <= 实际]
- python - 在 Python 中将音频数据从 RTMP Stream 转换为 PCM 或 WAV 格式
- flutter - 用户注册与 Firebase 身份验证相关联,但与实时数据库无关
- spring-cloud - Spring Cloud Gateway 后面的 Geoserver Admin UI 无法按预期工作
- python - 使用 python 的 BDD 框架
- ios - 初始化一个CGImage?
- javascript - 添加值后无法验证 Angular 表单构建器表单组中的必填字段
- sql-server - 为什么 dbTimeStamp() 添加逗号?
- spring-boot - 关于硬件故障和服务间通信的 Saga 模式
- generate - 是否可以在flutlab中生成flutter .ipa文件?