我认为这是低落的果实,但是我和我的同事每天都在讨论诸如此类的事情。
因此,我的视图上有多个单选按钮,大约有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”);
}
OR
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>