Java Reference
In-Depth Information
Managed bean for the article JSF page
As we need to display all of the Section id and Edition id IDs in the article.
jsp JSF page when the page is run, we have added a value binding in the
selectOneMenu labels in article.jsp to SelectItem ArrayLists in the managed
bean. To display the Section id and Edition id IDs, we shall retrieve all the
Section id and Edition id IDs in the managed bean and bind the id values to the
Menu lists. Define parameterized ArrayList variables of type SelectItem for the
Section id Menu and the Edition id Menu :
private ArrayList<SelectItem> sectionItems;
private ArrayList<SelectItem> editionItems;
Next, retrieve all the Section id IDs and add the id values to the sectionItems
ArrayList , which is of type SelectItem . Add the method getAllSections() to
retrieve and bind all the Section id IDs. In the getAllSections() method, create
an InitialContext object and lookup the session bean via its remote interface:
InitialContext context = new InitialContext();
Retrieve all the Section entities in the database with the getAllSections method:
List<Section> sections =beanRemote.getAllSections();
Initialize the sectionItems ArrayList with its size set to the size of the
List<Section> retrieved:
sectionItems = new ArrayList<SelectItem>(sections.size());
Using a ForEach loop, iterate over the List<Section> object sections and retrieve
the Section id IDs for the Section entity instances. For each of the Section id
IDs, create a SelectItem object and add the SelectItem object to sectionItems
ArrayList<SelectItem> , which has a value binding to the Section id Menu list in
article.jsp :
for (Section section : sections) {
String sectionId = section.getId();
SelectItem selectItem=new SelectItem(sectionId,sectionId);
Search WWH ::

Custom Search