java request ajax,Sending an Ajax Request

Sending an Ajax Request

To activate Ajax functionality, the web application must create an Ajax request and

send it to the server. The server then processes the request.

The application uses the attributes of the f:ajax tag listed in Table 11-1 to

create the Ajax request. The following sections explain the process of creating and sending

an Ajax request using some of these attributes.

Note -Behind the scenes, the jsf.ajax.request() method of the JavaScript resource library collects the

data provided by the f:ajax tag and posts the request to the

JavaServer Faces lifecycle.

Using the event Attribute

The event attribute defines the event that triggers the Ajax action. Some of

the possible values for this attribute are click, keyup, mouseover, focus, and

blur.

If not specified, a default event based on the parent component will be

applied. The default event is action for javax.faces.component.ActionSource components such as a

commandButton, and valueChange for javax.faces.component.EditableValueHolder components such as inputText. In the following example,

an Ajax tag is associated with the button component, and the event that

triggers the Ajax action is a mouse click:

Note -You may have noticed that the listed events are very similar to JavaScript

events. In fact, they are based on JavaScript events, but do not have

the on prefix.

For a command button, the default event is click, so that you do

not actually need to specify event="click" to obtain the desired behavior.

Using the execute Attribute

The execute attribute defines the component or components to be executed on the

server. The component is identified by its id attribute. You can specify more

than one executable component. If more than one component is to be executed,

specify a space-delimited list of components.

When a component is executed, it participates in all phases of the

request processing lifecycle except the Render Response phase.

The execute attribute can also be a keyword, such as @all, @none, @this, or

@form. The default value is @this, which refers to the component within which

the f:ajax tag is nested.

The following code specifies that the h:inputText component with the id value of

userNo should be executed when the button is clicked:

title="Type a number from 0 to 10:"

value="#{userNumberBean.userNumber}">

...

Using the immediate Attribute

The immediate attribute indicates whether user inputs are to be processed early in

the application lifecycle or later. If the attribute is set to true, events

generated from this component are broadcast during the Apply Request Values phase. Otherwise,

the events will be broadcast during the Invoke Applications phase.

If not defined, the default value of this attribute is false.

Using the listener Attribute

The listener attribute refers to a method expression that is executed on the

server side in response to an Ajax action on the client. The listener’s

javax.faces.event.AjaxBehaviorListener.processAjaxBehavior method is called once during the Invoke Application phase of the lifecycle.

In the following example, a listener attribute is defined by an f:ajax tag,

which refers to a method from the bean.

The following code represents the someaction method in mybean.

public void someaction(AjaxBehaviorEvent event) {

dosomething;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值