user3316715
user3316715

Reputation:

When it is essential to use a h:form, a a4j:region and a a4j:form in JSF?

Sorry but i don´t understand to exactly differences between these JSF elements. For example, when can i use a h:form and a a4j:form and when it is inevitable in JSF to use a form in general?

Many thanks ! Maik

Upvotes: 1

Views: 4681

Answers (2)

trims
trims

Reputation: 452

I agree with Vasil Lukach about the <h:form and <a4j:form but <a4j:region needs much bigger explanation, because a lot of people do not understand what it does and how it work and for what it should be used.

In richfaces 3 there were <a4j:region tag and ajaxSingle attribute. First ajaxSingle attribute is the same if you surround one single component with <a4j:region.

In JSF 2 with ajax support execute attribute was introduced where you can specify ids of the components @form, @region, @this. @this is equal to Richfaces 3 ajaxSingle attribute.

All these attributes and tag were created for one thing. To limit components that will be processed on the server side on ajax request. By saying limit components processing here I mean that two phases, number 3 Process Validation and 4 Update Model values will be skipped for components that are not inside <a4j:region or not listed in execute attribute.

From what I say you can see that such features are useful when you have a big rich form that has ajax controls. By default if you have validators on the fields and want to update part of the form without validators with some ajax control you will see validation errors. JSF will not allow you to do such update. But if you surround this part of the form with <a4j:region or list all inputs from this part in execute attribute(for JSF 2 only) you will be able to successfully submit part of the form without validation of fields that you do not need at this step.

Also I would like to tell about immediate attribute on ajax components. It is important to know what it does along with region and ajaxsingle. It forces JSF lifecycle to skip all phases and go right to 5 Invoke application. What does it mean? It means that no validation will executed on any component and no form values the form will be assigned to your beans. Just listener or action method will be called. It is very useful for cancel or return buttons implementation. Or when you need to remove part of big rich form that has validation(delete section).

Upvotes: 1

Vasil Lukach
Vasil Lukach

Reputation: 3728

h:form renders an HTML form element. It can be more that 1 h:form on the page. Forms on the page

  1. cannot be nested nor overlap
  2. only data in the form that contains the control component (for example Submit button) that fired off the request will be posted back to the server
  3. if ANY control value on the submitted form fails validation, NONE of the backing bean properties will get updated and the action method and/or listeners will not be fired. If h:messages tag exists on the page, then "validation failed" message is displayed.

a4j:form was part of RichFaces 3 and is not supported in RichFaces 4 (h:form should be used). It was ajax-related version of html form (see ajaxListener, ajaxSingle, ajaxSubmit, reRender, limitToList attributes).

In RichFaces 3 and RichFaces 4 for purpose re-rendering the part of page is used the a4j:region tag.

The component specifies a part of the JSF component tree to be processed on the server. The region causes all the a4j and rich Ajax controls to execute: decoding, validating, and updating the model. The region causes these components to execute even if not explicitly declared. As such, processing areas can more easily be marked using a declarative approach.

Simple answer: use h:form when you don't need re-render components, or wrap components with a4j:region when you need re-render it with ajax.

Upvotes: 2

Related Questions