Reputation: 117
I have some troubles displaying some data on a JSF page. It deals with a pizza sql-search programm I have written. The java program itself works fine but the output makes some problem.
All pizzas are stored in an ArrayList of instances, like List< PizzaObject>. The class PizzaObject contains other instances like 'Pizza', 'Topping', 'Size'. So it is a nested list of different classes holding variable data.
For my output I make use of the ui:repeat method. There is no problem displaying the pizza and their attributes. But when it comes to display their sizes nested in a ui-repeat loop as SelectOneRadio-buttons, there is no output.
All pizzas are stored in an ArrayList, looking like this:
List<PizzaObject> results = new ArrayList<PizzaObject>();
The PizzaObject class looks like this:
public static class PizzaObject {
Pizza pizza;
List<Size> sizeList;
List<Topping> toppingList;
public PizzaObject(Pizza pizza, List<Size> sizeList, List<Topping> toppingList) {
this.pizza = pizza;
this.sizeList = sizeList;
this.toppingList = toppingList;
}
// getter and setter
}
The classes Pizza, Topping and Size contain different attributes belonging to each Pizza object. For example the Size class looks like this:
public static class Size {
int sizeID;
int diameter;
public Size(int sizeID, int diameter) {
this.sizeID = sizeID;
this.diameter = diameter;
}
// getter and setter
}
In my JSF output page I now want to display each pizza and each of their sizes and toppings. But since they don't have the same sizes I need to iterate the list sizeList and this is where the error occurs.
<ui:repeat var="results" value="#{pizzaSearchBean.results}">
<p>#{results.pizza.name}</p>
<p>sizes: </p>
<h:selectOneRadio id="pizzasize" value="#{pizzaSearchBean.pizzasize}">
<ui:repeat var="sizes" value="#{results.sizeList}">
<f:selectItem id="size" itemLabel="#{sizes.diameter}" itemValue="#{sizes.sizeID}"/>
</ui:repeat>
</h:selectOneRadio>
</ui:repeat>
I don't know why there is no output of radio boxes but I don't think that I have implemented it incorrectly.
Thanks for any help!
Upvotes: 2
Views: 2496
Reputation: 1801
Have a look at [<f:selectitems>][1]
, this is intended to render multiple component based on a collection. For instance, you could replace your <ui:repeat>
with
<f:selectItems value="#{results.sizeList}" var="size"
itemLabel="#{size.diameter}" itemValue="#{size.sizeId}" />
Upvotes: 2