Richfaces 重点技术精讲
转载 richfaces 精讲
http://hintcnuie.iteye.com/blog/127309
?
关键字: ajax4jsf richfaces 总结
Defining the eventsQueue along with requestDelay allows to protect against unnecessary traffic flood and synchronizes Ajax requests order. If you have several sources of Ajax requests, you can define the same queue name there. This might be very helpful if you have Ajax components that invoke request asynchronously from the ones produced by events from users. For example a4j:poll or a4j:push. In case the requests from such components modify the same data, the synchronization might be very helpful.
immediate attribute has the same purpose as any other non-JSF component. The default ActionListener should be executed immediately (i.e. during the Apply Request Values phase of a request processing lifecycle), rather than waiting until the Invoke Application phase. Using immediate="true" is one of the ways to have some data model values updated when other cannot be updated because of a problem with passing the Validation phase successfully. This might be important inside the h:dataTable like components where using a4j:region is impossible due to the h:dataTable component architecture.
bypassUpdates attribute allows to bypass the Update Model phase. It might be useful if you need to check user input against the available validator, but not to update the model with those data. Note, that an action will be invoked at the end of the Validation phase only if the Validation phase is passed successfully. The listeners of the Application phase will not be invoked in any case.
Action and NavigationAjax component is similar to any other non-Ajax JSF component like h:commandButton. It allows to submit the form. You can use action and actionListener attribute to invoke the action method and define the action event.
action method must return null if you want to have an Ajax Response with a partual page update. This is regular mode called "Ajax request generates Ajax Response". In case of action does not return null, but the action outcome that matches one of navigation rules, RichFaces starts to work in "Ajax request generates Non-Ajax Response" mode. This mode might be helpful in two major cases:
RichFaces allows writing Ajax-enabled JSF application without writing any Javascript code. However, you can still invoke the javascript code if you need. There are several ajax attributes that helps to do it.
onsubmit attribute allows to invoke javascript code before an Ajax request is sent. If 'onsubmit' returns false, the Ajax request is canceled. The code of 'onsubmit' is inserted before the RichFaces Ajax call. Hence, the 'onsubmit' should not has a 'return' statement if you want the Ajax request to be sent. If you are going to invoke a javscript function that returns true or false, use the conditional statement to return something only when you need to cancel the request. For example, onsubmit="if (mynosendfunct()==false){return false}".
onclick attribute is similar to the 'onsubmit', but for clickable components such as a4j:commandLink and a4j:commandButton. If it returns false, the Ajax request is canceled also.
oncomplete attribute allows to invoke the javascript code right after the Ajax Response is returned back and the DOM tree of the browser is updated. Richfaces registers the code for further invocation of XMLHTTP request object before an Ajax request is sent. This means the code will not be changed during processing of the request on the server if you use JSF EL value binding. Also, you cannot use 'this' inside the code, because it will not point the component where Ajax request was initiated.
data attribute allows to get the additional data from the server during an Ajax call. You can use JSF EL to point the property of the managed bean and its value will be serialized in JSON format and be available on the client side. You can refer to it using the 'data' variable. For example:
<!----><a4j:commandButton?value="Update"?data="#{userBean.name}"?oncomplete="showTheName(data.name)"?/>Richfaces allows to serialize not only primitive types into JSON format, but also complex types including arrays and collections. The beans should be serializable to be refered with 'data'.