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 />

In JSF, the view is rendered on the server. When we add Ajax, the view is still rendered on the<br />

server—we just don’t need to render everything. We render specified components and thus we refer to it<br />

as partial view rendering. When the rendered response (after an Ajax request) is sent to the browser,<br />

that’s where the partial page update happens in the browser. There is a JavaScript library that takes the<br />

response and does the DOM (Document Object Model) update. It’s fine to use a partial page update or<br />

partial view rendering—as long as you understand that the markup is rendered on the server and the<br />

actual page update happens in the browser.<br />

Partial View Processing<br />

Without Ajax, when a page (form) is submitted, the entire form is processed on the server. When we say<br />

processed on the server, we refer to input or action components that go through the JSF life cycle; in<br />

particular, phases such as Apply Request Values, Process Validation, Update Model, and Invoke<br />

Application.<br />

Again, without Ajax it’s simple. The entire form or all the components within the form are<br />

processed. When working with Ajax, the situation is different. We might want only a particular<br />

component to be processed and not process all other components; for example, if we only want to<br />

validate one component and don’t need to validate anything else. In such case, we need to be able to<br />

select which component is processed.<br />

Deciding what to process is done via the execute attribute, described in Table 2-4.<br />

Table 2-4. Execute attribute<br />

Attribute Description<br />

execute Determines ids of components to be processed on server.<br />

The execute attribute can have different values, as shown in Table 2-5.<br />

Table 2-5. Execute attribute values<br />

Attribute Description<br />

@all Process all components in the view.<br />

@none Process no components in the view.<br />

@this Process only this component, the component that triggered the Ajax request (default).<br />

@form Process all components within this form (from which Ajax request was fired).<br />

ids Implicit ids of components to be processed, space separated.<br />

EL Process ids resolved form Collection of strings.<br />

Notice that default value is @this, which means that the component firing the Ajax request will be<br />

processed by default. Listing 2-17 shows an example.

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

Saved successfully!

Ooh no, something went wrong!