我想知道如何在 ice:selectOneMenu 中实现多重选择。我有在支持 bean 初始化时加载的玩具列表,在 UI 中我有一张玩具表,其中每一行玩具都有一列 selectOneMenu 即玩具功能。我的问题是在每一行玩具中显示选定的玩具功能。到目前为止,我能够使用以下代码在 selectOneMenu 中显示选定的函数,但我不知道如何在不同的行上实现不同的选择,我的意思是我只有一个属性“selectedToyFunction”,它映射到每一行。我需要实现类似java.util.Map<ToyId,ToyFunction>
. 但我不知道如何以及在哪里处理这种实施。
JSPX
<ice:dataTable border="0" value="#{myBean.toys}" var="toy" scrollable="false" resizable="false">
<ice:column id="toyDetailRedirect" styleClass="smallColumn">
<ice:selectOneMenu styleClass="inputCombo" partialSubmit="true" valueChangeListener="#{myBean.redirectToToyFunctionDetail}" value="#{myBean.selectedToyFunction}">
<f:attribute name="toy" value="#{toy.id}" />
<f:selectItems value="#{myBean.toyFunctions}" />
</ice:selectOneMenu>
<f:facet name="header">
<ice:outputText value="Details" />
</f:facet>
</ice:column>
<ice:dataTable>
BackingBean
public class MyBean
{
//--- Services ---
private ToyService toyService;
//---- UI -----
private String selectedToyFunction;
private List<SelectItem> toyFunctions = new ArrayList<SelectItem>();
//--- properties
private List<Toy> toys = new ArrayList<Toy>();
private static final String DEFAULT_SELECTION ="--- Select ---";
private static final String FUNCTION_A ="A";
private static final String FUNCTION_B ="B";
private static final String FUNCTION_C ="C";
// ---- Logging ----
private final Logger logger = Logger.getLogger(MyBean.class);
public MyBean()
{
super();
}
@PostConstruct
public void loadToysAndPopulateToysFunctions( )
{
// loadToys
try
{
this.toys = this.toysService.findAllToys();
}
catch (Exception e)
{
this.logger.warn(e.getMessage());
this.logger.debug(e);
}
if ((this.toys == null) || this.toys.isEmpty())
{
/* Out if not toy has been found */
logger.debug("No Toy has been found !");
return;
}
// Populate default toy functions
this.populateToyFunctions();
}
private void populateToyFunctions( )
{
if ((this.toyFunctions == null) || this.toyFunctions.isEmpty())
{
this.toyFunctions = new ArrayList<SelectItem>();
this.toyFunctions.add(new SelectItem(DEFAULT_SELECTION));
this.toyFunctions.add(new SelectItem(FUNCTION_A));
this.toyFunctions.add(new SelectItem(FUNCTION_B));
this.toyFunctions.add(new SelectItem(FUNCTION_C));
}
//Default selection
this.selectedToyFunction = DEFAULT_SELECTION;
}
public void redirectToToyFunctionDetail(ValueChangeEvent e)
{
FacesContext.getCurrentInstance()
.getExternalContext()
.redirect("/Store/Details.jspx?id=" +e.getNewValue().toString());
}
// ---- Getters & Setters -----
public List<Toy> getToys( )
{
return this.toys;
}
public void setToys(List<Toy> toys)
{
this.toys = toys;
}
public List<SelectItem> getToyFunctions( )
{
return this.toyFunctions;
}
public void setToyFunctions(List<SelectItem> toyFunctions)
{
this.toyFunctions = toyFunctions;
}
public void setSelectedToyFunction(String selectedToyFunction)
{
this.selectedToyFunction = selectedToyFunction;
}
public String getSelectedToyFunction()
{
return this.selectedToyFunction;
}
}