Java Reference
In-Depth Information
The first sectionId argument is displayed as the label of the list and the second
argument is for the value. Similarly, create a parameterized ArrayList of type
SelectItem for the Edition id IDs. In the managed bean method commandButton1_
action , retrieve the values for the id , title , and author :
String id = (String)inputText1.getValue();
String title = (String)inputText2.getValue();
String author = (String)inputText3.getValue();
The Menu components have a binding with UI components of type
HtmlSelectOneMenu in the managed bean, and the Menu list items have a binding
with UI components of type UISelectItems in the managed bean. Retrieve the
ArrayList objects for the Menu items.
java.util.ArrayList sectionUIComponents =
java.util.ArrayList editionUIComponents =
Because, we bound the select items in the Menus to ArrayLists of type SelectItem ,
the items in the ArrayList lists retrieved are of type SelectItem . As only one
value is returned to the managed bean when a Menu item is selected, the retrieved
ArrayList lists have only one item in each of the lists. Retrieve the list item from
ArrayList using the get method with index value as 0 , as ArrayList lists are 0
based. As the list item is of type SelectItem , cast the retrieved object to SelectItem .
SelectItem sectionItem=(SelectItem)sectionUIComponents.get(0);
SelectItem editionItem=(SelectItem)editionUIComponents.get(0);
Retrieve the Section id and Edition id values from the SelectItem objects using
the getValue method:
String sectionId=(String)sectionItem.getValue();
String editionId=(String)editionItem.getValue();
Next, create an InitialContext object and lookup the session bean through the
JNDI name for its remote interface:
InitialContext context = new InitialContext();
EJB3SessionEJB beanRemote = (EJB3SessionEJB)context.lookup(
Invoke the createArticle method of the session bean to create and persist an
Article entity:
beanRemote.createArticle(id, title, author, sectionId,editionId);
Search WWH ::

Custom Search