View Source

h2. Overview

_Since 3.3_

You can use the _icecore:defaultAction_ tag to initiate a form submit when a certain key is pressed. An action or an action listener can be defined to control which method to be invoked on the server side.

{tip}See the ICEfaces Showcase [Live Demo|http://icefaces-showcase.icesoft.org/showcase.jsf?grp=aceMenu&exp=defaultActionBean] of this component, complete with source code.{tip}


h2. Getting Started

To use the _icecore:defaultAction_ tag, first declare the core namespace:

{panel}
{code:html|borderStyle=dashed}
<html ... xmlns:icecore="http://www.icefaces.org/icefaces/core">
{code}
{panel}

Then add the tag to your page markup wiring the action to the bean method:

{panel}
{code:xml|borderStyle=dashed}
<h:form id="form">
...
<icecore:defaultAction actionListener="#{sampleBean.update}" key="Enter"/>
...
</h:form>
{code}
{panel}

The component can be used within a form to capture certain key press events. Multiple icecore:defaultAction instances can be used to capture different key press events.

{panel}
{code:xml|borderStyle=dashed}
<h:form id="form">
...
<icecore:defaultAction actionListener="#{sampleBean.update}" key="Enter"/>
<icecore:defaultAction action="#{sampleBean.cancel}" key="Esc"/>
<icecore:defaultAction action="#{helpBean.help}" key="F1"/>
...
</h:form>
{code}
{panel}

Multiple key mappings wired to the same action/actionListener can be done as well.
{panel}
{code:xml|borderStyle=dashed}
<h:form id="form">
...
<icecore:defaultAction actionListener="#{sampleBean.update}" key="Enter"/>
<icecore:defaultAction actionListener="#{sampleBean.update}" key="Esc"/>
<icecore:defaultAction actionListener="#{sampleBean.update}" key="LeftArrow"/>
...
</h:form>
{code}
{panel}

h2. Attributes

{tip:title=TagLib Documentation}This section covers attributes involved in the typical use-cases for this component. For reference, the complete taglib documentation for this component is available [here|http://res.icesoft.org/docs/v4_latest/core/comps/tld/icecore/defaultAction.html].{tip}

{panel}
*key* Use this attribute to specify the key-press that should be used for triggering the submit. The following predefined key names can be used: "Enter", "Esc", "Space", "PageUp", "PageDown", "PageUp", "LeftArrow", "UpArrow", "RightArrow", "DownArrow", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12".

*action* Use this attribute to reference a bean method. The method is invoked when the defined key is pressed and no other component within the form doesn't capture the fired event.

*actionListener* Use this attribute to reference a bean method. The method is invoked when the defined key is pressed and no other component within the form doesn't capture the fired event.
{panel}