Java Reference
In-Depth Information
} catch (Exception e) {
throw new EJBException(e.getMessage());
}
}
}
The
producerfields
Facelets Pages and Managed Bean
The
producerfields
example has two Facelets pages,
index.xhtml
and
todol-
ist.xhtml
. The simple form on the
index.xhtml
page asks the user only for the
task. When the user clicks the Submit button, the
listBean.createTask
method is
called. When the user clicks the Show Items button, the action specifies that the
todol-
ist.xhtml
file should be displayed:
<h:body>
<h2>To Do List</h2>
<p>Type a task to be completed.</p>
<h:form id="todolist">
<p><h:outputLabel value="Type a string: "
for="inputString"/>
<h:inputText id="inputString"
value="#{listBean.inputString}"/></p>
<p><h:commandButton value="Submit"
action="#{listBean.createTask()}"/></p>
<p><h:commandButton value="Show Items"
action="todolist"/></p>
</h:form>
...
</h:body>
The managed bean,
web.ListBean
, injects the
ejb.RequestBean
session bean. It
declares the
entity.ToDo
entity and a list of the entity, along with the input string that
it passes to the session bean. The
inputString
is annotated with the
@NotNull
Bean
Validation constraint, so an attempt to submit an empty string results in an error.
@Named
@ConversationScoped
public class ListBean implements Serializable {
...
@EJB
private RequestBean request;