23.12.2012 Views

ZK Developer's Guide

ZK Developer's Guide

ZK Developer's Guide

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.

}<br />

}<br />

}<br />

item.setValue(media.getTitle());<br />

[ 81 ]<br />

Chapter 3<br />

We manually set the value of listitem with item.setValue(media.getTitle())<br />

to have the possibility of accessing that value in the onSelect listener of the<br />

listbox. Most of the <strong>ZK</strong> controls implement the setValue and getValue methods,<br />

as a way of exchanging data over the application.<br />

After seeing the implementation of the ListItemRenderer, we should look at the<br />

implementation of the ListModel.<br />

public class SearchMediaListModel extends AbstractListModel<br />

{<br />

/**<br />

* @see org.zkoss.zul.ListModel#getElementAt(int)<br />

*/<br />

public Object getElementAt(final int index)<br />

{<br />

String searchattribute = (String)<br />

Sessions.getCurrent().getAttribute(„searchattribute");<br />

if (searchattribute == null)<br />

{<br />

searchattribute = „";<br />

}<br />

return MediaDAOFactory.getDAO().searchByTitle(searchattribute, 5)<br />

.toArray()[index];<br />

}<br />

/**<br />

* @see org.zkoss.zul.ListModel#getSize()<br />

*/<br />

public int getSize()<br />

{<br />

String searchattribute = (String)<br />

Sessions.getCurrent().getAttribute(„searchattribute");<br />

if (searchattribute == null)<br />

{<br />

searchattribute = „";<br />

}<br />

return MediaDAOFactory.getDAO().searchByTitle(searchattribute, 5)<br />

size();<br />

}<br />

public void update()<br />

{

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

Saved successfully!

Ooh no, something went wrong!