Author: ppitonak(a)redhat.com
Date: 2010-09-29 08:37:23 -0400 (Wed, 29 Sep 2010)
New Revision: 19370
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAjax/hInputTextWrapped.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/Attributes.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JAjaxBean.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/A4JAjaxBean.properties
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAjax/list.xhtml
Log:
* added page with a4j:ajax wrapping 3 text inputs
* added method for testing attribute 'listener' and 'onerror'
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/Attributes.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/Attributes.java 2010-09-29
12:02:10 UTC (rev 19369)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/Attributes.java 2010-09-29
12:37:23 UTC (rev 19370)
@@ -47,6 +47,7 @@
import javax.faces.component.behavior.BehaviorBase;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
+import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.model.SelectItem;
import org.richfaces.tests.metamer.bean.RichBean;
@@ -106,7 +107,7 @@
}
logger.debug(attributes.keySet().toString());
-
+
loadHelp();
loadSelectOptions();
}
@@ -145,7 +146,7 @@
} catch (MissingResourceException mre) {
return;
}
-
+
Enumeration<String> keys = rb.getKeys();
String key = null;
Attribute attribute = null;
@@ -408,7 +409,7 @@
}
RichBean.logToPage("* action listener invoked");
-
+
// if no select options for "actionListener" are defined in property
file and it is an EL expression
if (!hasSelectOptions("actionListener") &&
isStringEL(listener)) {
method =
@@ -427,6 +428,45 @@
}
/**
+ * An action listener for tested JSF component. Can be modified dynamically.
+ *
+ * @param event
+ * event representing the activation of a user interface component
+ */
+ public void listener(AjaxBehaviorEvent event) {
+ ELContext elContext = FacesContext.getCurrentInstance().getELContext();
+ MethodExpression method = null;
+
+ if (attributes.get("listener") == null) {
+ return;
+ }
+
+ String listener = (String) attributes.get("listener").getValue();
+
+ if (listener == null) {
+ return;
+ }
+
+ RichBean.logToPage("* listener invoked");
+
+ // if no select options for "listener" are defined in property file and
it is an EL expression
+ if (!hasSelectOptions("listener") && isStringEL(listener)) {
+ method =
+ getExpressionFactory().createMethodExpression(elContext, listener,
void.class,
+ new Class[]{AjaxBehaviorEvent.class});
+ method.invoke(elContext, new Object[]{event});
+ }
+
+ // if select options for "listener" are defined in property file
+ if (hasSelectOptions("listener")) {
+ method =
+ getExpressionFactory().createMethodExpression(elContext,
getMethodEL(listener), void.class,
+ new Class[]{AjaxBehaviorEvent.class});
+ method.invoke(elContext, new Object[]{event});
+ }
+ }
+
+ /**
* Method used for creating EL expressions for methods.
*
* @param methodName
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JAjaxBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JAjaxBean.java 2010-09-29
12:02:10 UTC (rev 19369)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JAjaxBean.java 2010-09-29
12:37:23 UTC (rev 19370)
@@ -19,7 +19,6 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
*******************************************************************************/
-
package org.richfaces.tests.metamer.bean;
import java.io.Serializable;
@@ -27,10 +26,14 @@
import java.util.List;
import javax.annotation.PostConstruct;
+import javax.faces.FacesException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
+import javax.faces.event.AjaxBehaviorEvent;
+import javax.faces.model.SelectItem;
import org.ajax4jsf.component.behavior.AjaxBehavior;
+import org.richfaces.tests.metamer.Attribute;
import org.richfaces.tests.metamer.Attributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,6 +49,7 @@
public class A4JAjaxBean implements Serializable {
private static final long serialVersionUID = -546567867L;
+ private static final int ACTION_STRING_LENGTH = 6;
private static Logger logger;
private Attributes attributes;
private String input;
@@ -64,10 +68,21 @@
attributes = Attributes.getBehaviorAttributes(AjaxBehavior.class, getClass());
// the 'event' attribute for behavior tag must be a literal
attributes.remove("event");
-
+
attributes.setAttribute("render", "output1, output2");
attributes.setAttribute("execute", "@form");
-
+
+ // FIXME not found attribute
+ Attribute listenerAttr = new Attribute("listener");
+ List<SelectItem> selectOptions = new ArrayList<SelectItem>();
+ selectOptions.add(new SelectItem("doubleStringListener",
"doubleStringListener"));
+ selectOptions.add(new SelectItem("first6CharsListener",
"first6CharsListener"));
+ selectOptions.add(new SelectItem("toUpperCaseListener",
"toUpperCaseListener"));
+ selectOptions.add(new SelectItem("causeErrorListener",
"causeErrorListener"));
+ selectOptions.add(new SelectItem(null, "null"));
+ listenerAttr.setSelectOptions(selectOptions);
+ attributes.put(listenerAttr.getName(), listenerAttr);
+
cars = new ArrayList<String>();
cars.add("Ferrari");
cars.add("Lexus");
@@ -132,5 +147,55 @@
public void setBoolVal(boolean boolVal) {
this.boolVal = boolVal;
}
-
+
+ /**
+ * An action listener that takes the first six characters from input and stores it to
input.
+ *
+ * @param event
+ * an event representing the activation of a user interface component (not
used)
+ */
+ public void first6CharsListener(AjaxBehaviorEvent event) {
+ if (input == null) {
+ input = "";
+ } else {
+ int endIndex = input.length() > ACTION_STRING_LENGTH ?
ACTION_STRING_LENGTH : input.length();
+ input = (String) input.subSequence(0, endIndex);
+ }
+ }
+
+ /**
+ * An action listener that takes user's input, doubles it and stores it to
input.
+ *
+ * @param event
+ * an event representing the activation of a user interface component (not
used)
+ */
+ public void doubleStringListener(AjaxBehaviorEvent event) {
+ if (input == null) {
+ input = "";
+ } else {
+ input = input.concat(input);
+ }
+ }
+
+ /**
+ * An action listener that takes user's input, converts it to upper case and
stores it to input3.
+ *
+ * @param event
+ * an event representing the activation of a user interface component (not
used)
+ */
+ public void toUpperCaseListener(AjaxBehaviorEvent event) {
+ if (input == null) {
+ input = "";
+ } else {
+ input = input.toUpperCase();
+ }
+ }
+
+ /**
+ * An action listener causing error. Suitable for testing onerror attribute.
+ * @param event an event representing the activation of a user interface component
(not used)
+ */
+ public void causeErrorListener(AjaxBehaviorEvent event) {
+ throw new FacesException("Ajax request caused an error. This is intentional
behavior.");
+ }
}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2010-09-29
12:02:10 UTC (rev 19369)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2010-09-29
12:37:23 UTC (rev 19370)
@@ -19,7 +19,6 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
*******************************************************************************/
-
package org.richfaces.tests.metamer.bean;
import java.io.Serializable;
@@ -32,12 +31,11 @@
import javax.annotation.PostConstruct;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
-import javax.faces.application.FacesMessage;
+import javax.faces.FacesException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
-import javax.faces.validator.ValidatorException;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
@@ -68,6 +66,7 @@
private String container;
public enum Skinning {
+
NONE, SKINNING, SKINNING_CLASSES
}
@@ -334,10 +333,10 @@
* Action that causes an error. Suitable for testing 'onerror' attribute.
*
* @return method never returns any value
- * @throws ValidationException
+ * @throws FacesException
* thrown always
*/
public String causeError() {
- throw new ValidatorException(new FacesMessage("Ajax request caused an error.
This is intentional behavior."));
+ throw new FacesException("Ajax request caused an error. This is intentional
behavior.");
}
}
Modified:
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/A4JAjaxBean.properties
===================================================================
---
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/A4JAjaxBean.properties 2010-09-29
12:02:10 UTC (rev 19369)
+++
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/A4JAjaxBean.properties 2010-09-29
12:37:23 UTC (rev 19370)
@@ -0,0 +1,6 @@
+attr.listener.first6CharsListener=first6CharsListener
+attr.listener.doubleStringListener=doubleStringListener
+attr.listener.toUpperCaseListener=toUpperCaseListener
+attr.listener.causeErrorListener=causeErrorListener
+attr.listener.null=
+
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAjax/hInputTextWrapped.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAjax/hInputTextWrapped.xhtml
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAjax/hInputTextWrapped.xhtml 2010-09-29
12:37:23 UTC (rev 19370)
@@ -0,0 +1,80 @@
+<!--
+JBoss, Home of Professional Open Source
+Copyright 2010, Red Hat, Inc. and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+-->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="head">
+ <f:metadata>
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ <h:outputStylesheet library="css"
name="a4jAjax.css"/>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ </ui:define>
+
+ <ui:define name="component">
+
+ <a4j:ajax id="inputAjax"
bypassUpdates="#{a4jAjaxBean.attributes['bypassUpdates'].value}"
+ data="#{a4jAjaxBean.attributes['data'].value}"
+
disabled="#{a4jAjaxBean.attributes['disabled'].value}"
+ event="keyup"
+
execute="#{a4jAjaxBean.attributes['execute'].value}"
+
immediate="#{a4jAjaxBean.attributes['immediate'].value}"
+
limitRender="#{a4jAjaxBean.attributes['limitRender'].value}"
+ listener="#{a4jAjaxBean.attributes.listener}"
+
onbeforedomupdate="#{a4jAjaxBean.attributes['onbeforedomupdate'].value}"
+
onbegin="#{a4jAjaxBean.attributes['onbegin'].value}"
+
oncomplete="#{a4jAjaxBean.attributes['oncomplete'].value}"
+
onerror="#{a4jAjaxBean.attributes['onerror'].value}"
+
onevent="#{a4jAjaxBean.attributes['onevent'].value}"
+
queueId="#{a4jAjaxBean.attributes['queueId'].value}"
+
render="#{a4jAjaxBean.attributes['render'].value}"
+
status="#{a4jAjaxBean.attributes['status'].value}"
+ >
+ <h:inputText id="input1"
value="#{a4jAjaxBean.input}"/><br/>
+ <h:inputText id="input2"
value="#{a4jAjaxBean.input}"/><br/>
+ <h:inputText id="input3"
value="#{a4jAjaxBean.input}"/><br/>
+ </a4j:ajax>
+
+ <a4j:outputPanel id="output1" layout="block">
+ <h:outputText value="#{a4jAjaxBean.input}"/>
+ </a4j:outputPanel>
+ <a4j:outputPanel id="output2" layout="block">
+ <h:outputText value="#{a4jAjaxBean.input}"/>
+ </a4j:outputPanel>
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{a4jAjaxBean.attributes}"
id="attributes" render="log"/>
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAjax/list.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAjax/list.xhtml 2010-09-29
12:02:10 UTC (rev 19369)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAjax/list.xhtml 2010-09-29
12:37:23 UTC (rev 19370)
@@ -45,6 +45,10 @@
Simple page that contains <b>h:inputText</b> with
<b>a4j:ajax</b> and input boxes for all its attributes.
</metamer:testPageLink>
+ <metamer:testPageLink id="hInputTextWrapped"
outcome="hInputTextWrapped" value="Input Text Wrapped">
+ Simple page that contains <b>h:inputText</b> nested in
<b>a4j:ajax</b> and input boxes for all its attributes.
+ </metamer:testPageLink>
+
<metamer:testPageLink id="hInputSecret"
outcome="hInputSecret" value="Input Secret">
Simple page that contains <b>h:inputSecret</b> with
<b>a4j:ajax</b> and input boxes for all its attributes.
</metamer:testPageLink>