Как мне инициализировать компонент f: selectOneRadioButton? - PullRequest
0 голосов
/ 03 апреля 2019

Я думаю, что это низко висящий фрукт, но мы с коллегами ежедневно обсуждаем такие вещи, как этот.

Таким образом, у меня есть несколько переключателей на моем виде, около 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>
...