Java Reference
In-Depth Information
In ContactListActionBean , we just have to receive the filter parameter and
use it
to retrieve the matching contacts in
the
findByName ( )
event
handler:
Download email_36/src/stripesbook/action/ContactListActionBean.java
public String filter;
public Resolution findByName() {
if (filter != null && filter.length() > 0) {
contacts = contactDao.findByName(filter, getUser());
}
return new ForwardResolution(TABLE);
}
Notice that we filter only if there is at least one character in the text
field. That way, if the user deletes everything from the text field, the
contact list goes back to being fully populated.
Finally, a simple query in the Contact DAO retrieves the list of contacts
that match the filter:
Download email_36/src/stripesbook/dao/impl/stripersist/ContactDaoImpl.java
@SuppressWarnings("unchecked")
public List<Contact> findByName(String startsWith, User user) {
return Stripersist.getEntityManager()
.createQuery("select distinct c from "
+ getEntityClass().getName() + " c "
+ "where (c.firstName like '" + startsWith + "%' or "
+ "c.lastName like '" + startsWith + "%') "
+ "and c.user = :user"
).setParameter("user", user).getResultList();
}
The contact list now changes as the user types characters in the Filter
field. Pretty spiffy!
Viewing Contact Details
To view the contact details, the user clicks the ā€œiā€ icon in the column.
The contact's information appears next to the table, as you can see in
Figure 15.12 , on the next page. A small ā€œxā€ lets the user remove the
details area from the page.
We used a plain HTML control for the Filter text field because there
wasn't much to gain from using the Stripes equivalent. For the con-
tact details link, however, we can take advantage of the <s:link> tag's
features and attach an event to the onclick= attribute.
 
 
Search WWH ::




Custom Search