Generic behavior

A generic behavior which lets you attach a JSF Action to any event handler on any HTML tag.

The Generic behavior is used to execute a JSF action in response to any event firing on any tag. It provides a mechanism through which a user can run a handy pre-defined blob of JavaScriptâ„¢ functionality in response to an event instead of running code they write themselves.

While there are no limits on what kind of tag or what kind of event the generic behavior can be attached to, care must be taken that the action(s) assigned to the behavior can be run in the context in which they are defined (that they can run in the event handler). For example, executing an alert action in an onresize event handler is not a wise thing to do. The Generic Behavior does not check if an action makes sense in the context it is run. It is the responsibility of the coder/designer to ensure that the action makes sense in the context.

JSF tags that emit the component

<hx:behavior>

Base HTML

Use with any HTML tag that supports event handlers.

JavaScript constructor

hX_5.addBehavior("id", "eventname", new hX_5.JSFBehaviorGeneric(attributes)); where

id

The ID of the HTML tag to which the component is attached.

attributes

Comma separated list of attributes where each attribute is a quoted string consisting of the attribute name and value separated by a colon, for example "label:MyLabel".

eventname

The HTML eventname that invokes the behavior. For example, onclick or onkeydown. Each behavior supports only some HTML event names (for example, the mouseclick behavior can't be bound to a keyboard event). In some cases, the behavior needs to be bound to multiple HTML events in which case a "pseudo" event name is used. For example, the mouseclick behavior is bound to multiple events so the eventname is "onmouse".

Supported events

Event

Description

any

All event handlers are supported though normally this is used with keyboard handlers, mouse handlers, focus and blur handlers.

Attributes

Table 1. Generic behavior attributes

Attribute name

Description

action

An action (or a set of actions) to be performed when a click-able entity is clicked. A target for the action (or a set of targets) are normally required.

target

If supplied, the ID of an input type='text' field in the page. Whenever something is selected in the menu, the text of the menu item is set as the value of the specified field. This is normally only used when making a popup menu which is emulating a combo-box (that is you have an input field with an adjacent menu where the top-level of the menu is a single button, clicking the button displays the menu, choosing an item from the menu sets the value of the input field.)

function

A JavaScript function (or inline string of JavaScript) to perform when the key is pressed.

Sequencing

Runs after any other handlers provided for the event.

Stops the event continuing/bubbling if the action stops the event.

API calls

API call

Description

object = setAttribute(attribute)

Sets an attribute or changes its value (if it was set previously).

string = getAttribute(attribute-name)

Retrieves the current value of an attribute.

Limitations

As noted above, binding an action that is inappropriate to a tag/event can cause a browser to misbehave (badly).


Feedback