Java Reference
In-Depth Information
when the value-change event occurs. The ValueChangeEvent instance stores the old
and the new values of the component that fired the event.
In the Duke's Bookstore case study, the NameChanged listener implementation is re-
gistered on the name UIInput component on the bookcashier.xhtml page. This
listener stores into session scope the name the user entered in the text field corresponding
to the name component.
The bookreceipt.xhtml subsequently retrieves the name from the session scope:
Click here to view code image
<h:outputFormat title="thanks"
value="#{bundle.ThankYouParam}">
<f:param value="#{sessionScope.name}"/>
</h:outputFormat>
When the bookreceipt.xhtml page is loaded, it displays the name inside the mes-
sage:
"Thank you, {0}, for purchasing your books from us."
Here is part of the NameChanged listener implementation:
Click here to view code image
public class NameChanged extends Object implements
ValueChangeListener {
@Override
public void processValueChange(ValueChangeEvent event)
throws AbortProcessingException {
if (null != event.getNewValue()) {
FacesContext.getCurrentInstance().getExternalContext().
getSessionMap().put("name", event.getNewValue());
}
}
}
When the user enters the name in the text field, a value-change event is generated, and
the processValueChange(ValueChangeEvent) method of the NameChanged
listener implementation is invoked. This method first gets the ID of the component that
fired the event from the ValueChangeEvent object, and it puts the value, along with
an attribute name, into the session map of the FacesContext instance.
Search WWH ::




Custom Search