20.04.2013 Views

Practical RichFaces, Second Edition

Practical RichFaces, Second Edition

Practical RichFaces, Second Edition

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.

CHAPTER 2 GETTING STARTED<br />

}<br />

}<br />

public void selectComponents (AjaxBehaviorEvent event){<br />

renderComponents.add(selection);<br />

}<br />

public List getRenderComponents() {<br />

return renderComponents;<br />

}<br />

public String getSelection() {<br />

return selection;<br />

}<br />

public void setSelection(String selection) {<br />

this.selection = selection;<br />

}<br />

public Date getClock1() {<br />

return new Date();<br />

}<br />

public Date getClock2() {<br />

return new Date();<br />

}<br />

public Date getClock3() {<br />

return new Date();<br />

}<br />

Notice that we no longer need to add the button to the list of components to be rendered. Running<br />

the application, everything is now updated as you would expect.<br />

Simplicity is just one of the advantages to using and the render attribute bound to EL.<br />

One more advantage is that evaluating the ids on the server instead of getting them client side is more<br />

secure, as anyone could send a request with ids using . If this happens with , these<br />

ids will simply be ignored.<br />

Note The same functionality is available on other <strong>RichFaces</strong> tags, such as ,<br />

, , and . We will cover this in Chapter 3. We used the listener<br />

attribute on either or behaviors. If you have an action or an actionListener set on<br />

the button or link, those will be invoked in a standard way.<br />

execute Attribute Options<br />

The same way it’s possible to bind the render attribute to EL or decide which components to render in<br />

runtime, it’s also possible to decide which components to execute in runtime or bind the execute<br />

attribute to EL. For example:<br />

<br />

When using just JSF 2, execute works in similar fashion to render in regards to when the ids are<br />

resolved. As with render, the ids in execute are resolved but then rendered to the page and only used on<br />

the next request. When using <strong>RichFaces</strong> a4j:ajax behavior instead of f:ajax, then ids are resolved and<br />

those components are executed in the current request.<br />

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

Saved successfully!

Ooh no, something went wrong!