10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Writing Backing Bean Methods<br />

406<br />

This ValueChangeListener instance handles the event of entering a value in the field<br />

corresponding to the component. When the user enters a value, a value-change event is<br />

generated, and the processValueChange(ValueChangeEvent) method of the<br />

ValueChangeListener class is invoked.<br />

Instead of implementing ValueChangeListener, you can write a backing bean method to<br />

handle this event. To do this, you move the processValueChange(ValueChangeEvent) method<br />

from the ValueChangeListener class, called NameChanged, to your backing bean.<br />

Here is the backing bean method that processes the event of entering a value in the name field on<br />

the bookcashier.jsp page:<br />

public void processValueChange(ValueChangeEvent event)<br />

throws AbortProcessingException {<br />

if (null != event.getNewValue()) {<br />

FacesContext.getCurrentInstance().<br />

getExternalContext().getSessionMap().<br />

put("name", event.getNewValue());<br />

}<br />

}<br />

<strong>The</strong> page author can make this method handle the ValueChangeEvent object emitted by a<br />

UIInput component by referencing this method from the component tag’s<br />

valueChangeListener attribute. See “Referencing a Method That Handles a Value-change<br />

Event” on page 370 for more information.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!