JBoss Rich Faces SVN: r19757 - sandbox/trunk/examples/calendar-demo.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2010-10-29 07:36:03 -0400 (Fri, 29 Oct 2010)
New Revision: 19757
Modified:
sandbox/trunk/examples/calendar-demo/pom.xml
Log:
add calendar api lib dependency
Modified: sandbox/trunk/examples/calendar-demo/pom.xml
===================================================================
--- sandbox/trunk/examples/calendar-demo/pom.xml 2010-10-29 11:35:31 UTC (rev 19756)
+++ sandbox/trunk/examples/calendar-demo/pom.xml 2010-10-29 11:36:03 UTC (rev 19757)
@@ -109,6 +109,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.richfaces.ui.calendar</groupId>
+ <artifactId>richfaces-ui-calendar-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.richfaces.ui.core</groupId>
<artifactId>richfaces-ui-core-ui</artifactId>
</dependency>
13 years, 6 months
JBoss Rich Faces SVN: r19756 - in sandbox/trunk/ui/calendar: ui/src/main/java/org/richfaces/renderkit/html/images and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2010-10-29 07:35:31 -0400 (Fri, 29 Oct 2010)
New Revision: 19756
Modified:
sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java
sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeListener.java
sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarIcon.java
sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarSeparator.java
sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/DisabledCalendarIcon.java
sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/CalendarHandler.java
sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/MethodExpressionCurrentDateChangeListener.java
Log:
add author section and license headers
Modified: sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java
===================================================================
--- sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java 2010-10-29 11:14:51 UTC (rev 19755)
+++ sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java 2010-10-29 11:35:31 UTC (rev 19756)
@@ -1,23 +1,25 @@
-/**
- * License Agreement.
+/*
+ * 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.
*
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ * 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.
*
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
+ * 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
+ * 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * 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.
*/
+
package org.richfaces.event;
import java.util.Date;
@@ -26,6 +28,10 @@
import javax.faces.event.FacesEvent;
import javax.faces.event.FacesListener;
+/**
+ * @author amarkhel
+ *
+ */
public class CurrentDateChangeEvent extends FacesEvent {
private static final long serialVersionUID = -8169207286087810907L;
@@ -38,12 +44,11 @@
}
public boolean isAppropriateListener(FacesListener listener) {
- return false;
+ return (listener instanceof CurrentDateChangeListener);
}
public void processListener(FacesListener listener) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ ((CurrentDateChangeListener)listener).processCurrentDateChange(this);
}
public Date getCurrentDate() {
Modified: sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeListener.java
===================================================================
--- sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeListener.java 2010-10-29 11:14:51 UTC (rev 19755)
+++ sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeListener.java 2010-10-29 11:35:31 UTC (rev 19756)
@@ -1,22 +1,23 @@
-/**
- * License Agreement.
+/*
+ * 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.
*
- * JBoss RichFaces - Ajax4jsf Component Library
+ * 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.
*
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
+ * 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
+ * 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * 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.
*/
package org.richfaces.event;
@@ -25,9 +26,7 @@
/**
* @author Alexej Kushunin - akushunin(a)exadel.com
- * created 28.08.2007
- *
- * Base calendar events interface
+ *
*/
public interface CurrentDateChangeListener extends FacesListener {
Modified: sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarIcon.java
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarIcon.java 2010-10-29 11:14:51 UTC (rev 19755)
+++ sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarIcon.java 2010-10-29 11:35:31 UTC (rev 19756)
@@ -1,3 +1,25 @@
+/*
+ * 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.
+ */
+
package org.richfaces.renderkit.html.images;
import java.awt.BasicStroke;
Modified: sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarSeparator.java
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarSeparator.java 2010-10-29 11:14:51 UTC (rev 19755)
+++ sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/CalendarSeparator.java 2010-10-29 11:35:31 UTC (rev 19756)
@@ -1,3 +1,25 @@
+/*
+ * 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.
+ */
+
package org.richfaces.renderkit.html.images;
import java.awt.Color;
Modified: sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/DisabledCalendarIcon.java
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/DisabledCalendarIcon.java 2010-10-29 11:14:51 UTC (rev 19755)
+++ sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/html/images/DisabledCalendarIcon.java 2010-10-29 11:35:31 UTC (rev 19756)
@@ -1,22 +1,23 @@
-/**
- * License Agreement.
+/*
+ * 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.
*
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ * 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.
*
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
+ * 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
+ * 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * 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.
*/
package org.richfaces.renderkit.html.images;
Modified: sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/CalendarHandler.java
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/CalendarHandler.java 2010-10-29 11:14:51 UTC (rev 19755)
+++ sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/CalendarHandler.java 2010-10-29 11:35:31 UTC (rev 19756)
@@ -1,3 +1,26 @@
+/*
+ * 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.
+ */
+
+
package org.richfaces.taglib;
import javax.faces.view.facelets.ComponentConfig;
@@ -11,6 +34,10 @@
import org.richfaces.component.AbstractCalendar;
+/**
+ * @author amarkhel
+ *
+ */
public class CalendarHandler extends ComponentHandler {
private static final CalendarHandlerMetaRule METARULE = new CalendarHandlerMetaRule();
Modified: sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/MethodExpressionCurrentDateChangeListener.java
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/MethodExpressionCurrentDateChangeListener.java 2010-10-29 11:14:51 UTC (rev 19755)
+++ sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/MethodExpressionCurrentDateChangeListener.java 2010-10-29 11:35:31 UTC (rev 19756)
@@ -28,6 +28,10 @@
import org.richfaces.event.CurrentDateChangeEvent;
import org.richfaces.event.CurrentDateChangeListener;
+/**
+ * @author amarkhel
+ *
+ */
public class MethodExpressionCurrentDateChangeListener implements CurrentDateChangeListener {
private MethodExpression methodExpression;
13 years, 6 months
JBoss Rich Faces SVN: r19755 - in sandbox/trunk/ui/calendar: api/src/main/java/org/richfaces/event and 6 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2010-10-29 07:14:51 -0400 (Fri, 29 Oct 2010)
New Revision: 19755
Removed:
sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/events/
Modified:
sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java
sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/model/CalendarDataModel.java
sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/model/CalendarDataModelItem.java
sandbox/trunk/ui/calendar/pom.xml
sandbox/trunk/ui/calendar/ui/pom.xml
sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/CalendarHandler.java
sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/MethodExpressionCurrentDateChangeListener.java
Log:
use events classes from api
Modified: sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java
===================================================================
--- sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java 2010-10-29 09:58:54 UTC (rev 19754)
+++ sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/event/CurrentDateChangeEvent.java 2010-10-29 11:14:51 UTC (rev 19755)
@@ -28,42 +28,34 @@
public class CurrentDateChangeEvent extends FacesEvent {
-
- private static final long serialVersionUID = -8169207286087810907L;
- private Date currentDate = null;
- private String currentDateString = null;
+ private static final long serialVersionUID = -8169207286087810907L;
+ private Date currentDate = null;
+ private String currentDateString = null;
- @Deprecated
- public CurrentDateChangeEvent(UIComponent component, Date curentDate) {
- super(component);
- this.currentDate = curentDate;
+ public CurrentDateChangeEvent(UIComponent component, String curentDateString) {
+ super(component);
+ this.currentDateString = curentDateString;
+ }
- }
-
- public CurrentDateChangeEvent(UIComponent component, String curentDateString) {
- super(component);
- this.currentDateString = curentDateString;
- }
+ public boolean isAppropriateListener(FacesListener listener) {
+ return false;
+ }
- public boolean isAppropriateListener(FacesListener listener) {
- return false;
- }
+ public void processListener(FacesListener listener) {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException();
+ }
- public void processListener(FacesListener listener) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
+ public Date getCurrentDate() {
+ return currentDate;
+ }
- public Date getCurrentDate() {
- return currentDate;
- }
+ public void setCurrentDate(Date currentDate) {
+ this.currentDate = currentDate;
+ }
- public void setCurrentDate(Date currentDate) {
- this.currentDate = currentDate;
- }
-
- public String getCurrentDateString() {
- return currentDateString;
- }
+ public String getCurrentDateString() {
+ return currentDateString;
+ }
}
Modified: sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/model/CalendarDataModel.java
===================================================================
--- sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/model/CalendarDataModel.java 2010-10-29 09:58:54 UTC (rev 19754)
+++ sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/model/CalendarDataModel.java 2010-10-29 11:14:51 UTC (rev 19755)
@@ -21,24 +21,26 @@
package org.richfaces.model;
import java.util.Date;
+
/**
- * @author Alexej Kushunin
- * created 19.06.2007
- *
+ * @author Alexej Kushunin created 19.06.2007
+ *
*/
public interface CalendarDataModel {
-
- /**
- * @return array of CalendarDataModelItems for selected dates.
- * This method will be called every time when components will need next block of CalendarDataItems.
- * That may happens when calendar rendered, or when user navigate to next(previous) month or in any other case when calendar renders.
- * This method will be called in Ajax mode when Calendar renders new page.
- * */
- public CalendarDataModelItem[] getData(Date[] dateArray);
-
- /**
- * @return tool tip when it's used in "single" mode
- * This method used when tool tips are displayed in "single" mode
- * */
- public Object getToolTip(Date date);
+
+ /**
+ * @return array of CalendarDataModelItems for selected dates. This method
+ * will be called every time when components will need next block of
+ * CalendarDataItems. That may happens when calendar rendered, or
+ * when user navigate to next(previous) month or in any other case
+ * when calendar renders. This method will be called in Ajax mode
+ * when Calendar renders new page.
+ * */
+ public CalendarDataModelItem[] getData(Date[] dateArray);
+
+ /**
+ * @return tool tip when it's used in "single" mode This method used when
+ * tool tips are displayed in "single" mode
+ * */
+ public Object getToolTip(Date date);
}
Modified: sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/model/CalendarDataModelItem.java
===================================================================
--- sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/model/CalendarDataModelItem.java 2010-10-29 09:58:54 UTC (rev 19754)
+++ sandbox/trunk/ui/calendar/api/src/main/java/org/richfaces/model/CalendarDataModelItem.java 2010-10-29 11:14:51 UTC (rev 19755)
@@ -20,49 +20,49 @@
*/
package org.richfaces.model;
-
-
/**
- * @author Alexej Kushunin
- * created 19.06.2007
- *
+ * @author Alexej Kushunin created 19.06.2007
+ *
*/
public interface CalendarDataModelItem {
-
- /**
- *@return true if date is �selectable� on calendar, default implementation return true
- **/
- public boolean isEnabled();
-
- /**
- * @return String that will be appended to style class for that date span.
- * For example it may be �relevant holyday� � that mean class will be like �rich-cal-day relevant holyday�.
- * Default implementation return empty string.
- * */
- public String getStyleClass();
-
- /**
- * @return any additional payload that must be JSON-serialazable object.
- * May be used in custom date representation on calendar (inside custom facet).*/
- public Object getData();
-
- /**
- * @return true if given date has an associated with it tooltip data.
- * Default implementation return false.*/
- public boolean hasToolTip();
-
- /**
- *@return tool tip data that will be used in �batch� tooltip loading mode.
- **/
- public Object getToolTip();
-
- /**
- *@return day of the month on which data must be shown.
- **/
- public int getDay();
-
-}
+ /**
+ * @return true if date is �selectable� on calendar, default
+ * implementation return true
+ **/
+ public boolean isEnabled();
+ /**
+ * @return String that will be appended to style class for that date span.
+ * For example it may be �relevant holyday� � that mean class
+ * will be like �rich-cal-day relevant holyday�. Default
+ * implementation return empty string.
+ * */
+ public String getStyleClass();
+ /**
+ * @return any additional payload that must be JSON-serialazable object. May
+ * be used in custom date representation on calendar (inside custom
+ * facet).
+ */
+ public Object getData();
+
+ /**
+ * @return true if given date has an associated with it tooltip data.
+ * Default implementation return false.
+ */
+ public boolean hasToolTip();
+
+ /**
+ * @return tool tip data that will be used in �batch� tooltip loading
+ * mode.
+ **/
+ public Object getToolTip();
+
+ /**
+ * @return day of the month on which data must be shown.
+ **/
+ public int getDay();
+
+}
Modified: sandbox/trunk/ui/calendar/pom.xml
===================================================================
--- sandbox/trunk/ui/calendar/pom.xml 2010-10-29 09:58:54 UTC (rev 19754)
+++ sandbox/trunk/ui/calendar/pom.xml 2010-10-29 11:14:51 UTC (rev 19755)
@@ -35,6 +35,7 @@
<name>Richfaces UI Components: Calendar Aggregator</name>
<modules>
+ <module>api</module>
<module>ui</module>
</modules>
</project>
Modified: sandbox/trunk/ui/calendar/ui/pom.xml
===================================================================
--- sandbox/trunk/ui/calendar/ui/pom.xml 2010-10-29 09:58:54 UTC (rev 19754)
+++ sandbox/trunk/ui/calendar/ui/pom.xml 2010-10-29 11:14:51 UTC (rev 19755)
@@ -63,5 +63,10 @@
<groupId>org.richfaces.ui.input</groupId>
<artifactId>richfaces-ui-input-ui</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.richfaces.ui.calendar</groupId>
+ <artifactId>richfaces-ui-calendar-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
Modified: sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2010-10-29 09:58:54 UTC (rev 19754)
+++ sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2010-10-29 11:14:51 UTC (rev 19755)
@@ -43,12 +43,14 @@
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.events.CurrentDateChangeEvent;
-import org.richfaces.events.CurrentDateChangeListener;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.utils.CalendarHelper;
+import org.richfaces.event.CurrentDateChangeEvent;
+import org.richfaces.event.CurrentDateChangeListener;
+
+
/**
* @author amarkhel
*
Modified: sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2010-10-29 09:58:54 UTC (rev 19754)
+++ sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2010-10-29 11:14:51 UTC (rev 19755)
@@ -52,7 +52,7 @@
import org.richfaces.component.util.MessageUtil;
import org.richfaces.component.util.SelectUtils;
import org.richfaces.component.util.ViewUtil;
-import org.richfaces.events.CurrentDateChangeEvent;
+import org.richfaces.event.CurrentDateChangeEvent;
import org.richfaces.utils.CalendarHelper;
/**
Modified: sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/CalendarHandler.java
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/CalendarHandler.java 2010-10-29 09:58:54 UTC (rev 19754)
+++ sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/CalendarHandler.java 2010-10-29 11:14:51 UTC (rev 19755)
@@ -11,11 +11,10 @@
import org.richfaces.component.AbstractCalendar;
-public class CalendarHandler extends ComponentHandler{
-
+public class CalendarHandler extends ComponentHandler {
+
private static final CalendarHandlerMetaRule METARULE = new CalendarHandlerMetaRule();
-
public CalendarHandler(ComponentConfig config) {
super(config);
}
@@ -39,7 +38,7 @@
static class CalendarMapper extends Metadata {
- private static final Class[] SIGNATURE = new Class[] { org.richfaces.events.CurrentDateChangeListener.class };
+ private static final Class[] SIGNATURE = new Class[] { org.richfaces.event.CurrentDateChangeListener.class };
private final TagAttribute attribute;
@@ -48,7 +47,8 @@
}
public void applyMetadata(FaceletContext ctx, Object instance) {
- ((AbstractCalendar) instance).addCurrentDateChangeListener((new MethodExpressionCurrentDateChangeListener(this.attribute.getMethodExpression(ctx, null, SIGNATURE))));
+ ((AbstractCalendar) instance).addCurrentDateChangeListener((new MethodExpressionCurrentDateChangeListener(
+ this.attribute.getMethodExpression(ctx, null, SIGNATURE))));
}
}
}
Modified: sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/MethodExpressionCurrentDateChangeListener.java
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/MethodExpressionCurrentDateChangeListener.java 2010-10-29 09:58:54 UTC (rev 19754)
+++ sandbox/trunk/ui/calendar/ui/src/main/java/org/richfaces/taglib/MethodExpressionCurrentDateChangeListener.java 2010-10-29 11:14:51 UTC (rev 19755)
@@ -25,8 +25,8 @@
import javax.el.MethodExpression;
import javax.faces.context.FacesContext;
-import org.richfaces.events.CurrentDateChangeEvent;
-import org.richfaces.events.CurrentDateChangeListener;
+import org.richfaces.event.CurrentDateChangeEvent;
+import org.richfaces.event.CurrentDateChangeListener;
public class MethodExpressionCurrentDateChangeListener implements CurrentDateChangeListener {
13 years, 6 months
JBoss Rich Faces SVN: r19754 - in modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest: richInputNumberSpinner and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-10-29 05:58:54 -0400 (Fri, 29 Oct 2010)
New Revision: 19754
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinner.java
Log:
https://jira.jboss.org/browse/RFPL-857
* added 48 tests for rich:inputNumberSpinner
Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinner.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinner.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinner.java 2010-10-29 09:58:54 UTC (rev 19754)
@@ -0,0 +1,538 @@
+/*******************************************************************************
+ * 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.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richInputNumberSpinner;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardNoRequest;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URL;
+
+import javax.faces.event.PhaseId;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.AttributeLocator;
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/richInputNumberSpinner/simple.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestRichSpinner extends AbstractMetamerTest {
+
+ private JQueryLocator spinner = pjq("span[id$=spinner]");
+ private JQueryLocator input = pjq("span[id$=spinner] input.rf-insp-inp");
+ private JQueryLocator up = pjq("span[id$=spinner] span.rf-insp-inc");
+ private JQueryLocator down = pjq("span[id$=spinner] span.rf-insp-dec");
+ private JQueryLocator output = pjq("span[id$=output]");
+ private JQueryLocator time = jq("span[id$=requestTime]");
+ private String[] correctNumbers = {"-10", "-5", "-1", "0", "1", "5", "10"};
+ private String[] smallNumbers = {"-11", "-15", "-100"};
+ private String[] bigNumbers = {"11", "15", "100"};
+ private String[] decimalNumbers = {"1.4999", "5.6", "7.0001", "-5.50001", "-9.9", "1.222e0", "0e0", "-5.50001e0"};
+ @Inject
+ @Use(empty = true)
+ private String number;
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath, "faces/components/richInputNumberSpinner/simple.xhtml");
+ }
+
+ @Test
+ public void testInit() {
+ assertTrue(selenium.isDisplayed(spinner), "Spinner is not present on the page.");
+ assertTrue(selenium.isDisplayed(input), "Spinner's input is not present on the page.");
+ assertTrue(selenium.isDisplayed(up), "Spinner's up button is not present on the page.");
+ assertTrue(selenium.isDisplayed(down), "Spinner's down button is not present on the page.");
+
+ }
+
+ @Test
+ @Use(field = "number", value = "correctNumbers")
+ public void testTypeIntoInputCorrect() {
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, number);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+
+ assertEquals(selenium.getText(output), number, "Output was not updated.");
+ }
+
+ @Test
+ @Use(field = "number", value = "smallNumbers")
+ public void testTypeIntoInputSmall() {
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, number);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+
+ assertEquals(selenium.getText(output), "-10", "Output was not updated.");
+ assertEquals(getInputValue(), "-10", "Input was not updated.");
+ }
+
+ @Test
+ @Use(field = "number", value = "bigNumbers")
+ public void testTypeIntoInputBig() {
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, number);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+
+ assertEquals(selenium.getText(output), "10", "Output was not updated.");
+ assertEquals(getInputValue(), "10", "Input was not updated.");
+ }
+
+ @Test
+ @Use(field = "number", value = "decimalNumbers")
+ public void testTypeIntoInputDecimal() {
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, number);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+
+ int roundedNumber = (int) Math.round(Double.parseDouble(number));
+
+ assertEquals(selenium.getText(output), Integer.toString(roundedNumber), "Output was not updated.");
+ assertEquals(getInputValue(), Integer.toString(roundedNumber), "Input was not updated.");
+ }
+
+ @Test
+ public void testTypeIntoInputNotNumber() {
+ guardNoRequest(selenium).type(input, "aaa");
+ assertEquals(selenium.getText(output), "2", "Output should not be updated.");
+ assertEquals(getInputValue(), "2", "Input should not be updated.");
+ }
+
+ @Test
+ public void testClickUp() {
+ clickArrow(up, 4);
+ assertEquals(selenium.getText(output), "6", "Output was not updated.");
+
+ clickArrow(up, 4);
+ assertEquals(selenium.getText(output), "10", "Output was not updated.");
+
+ selenium.mouseDown(up);
+ guardNoRequest(selenium).mouseUp(up);
+
+ assertEquals(selenium.getText(output), "10", "Output was not updated.");
+ }
+
+ @Test
+ public void testClickDown() {
+ clickArrow(down, 4);
+ assertEquals(selenium.getText(output), "-2", "Output was not updated.");
+
+ clickArrow(down, 8);
+ assertEquals(selenium.getText(output), "-10", "Output was not updated.");
+
+ selenium.mouseDown(down);
+ guardNoRequest(selenium).mouseUp(down);
+
+ assertEquals(selenium.getText(output), "-10", "Output was not updated.");
+ }
+
+ @Test
+ public void testCycled() {
+ JQueryLocator selectOption = pjq("input[type=radio][name$=cycledInput][value=true]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, "10");
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+
+ // test that value change to min value (10 -> -10)
+ clickArrow(up, 1);
+ assertEquals(selenium.getText(output), "-10", "Output was not updated.");
+
+ // test that value change to max value (-10 -> 10)
+ clickArrow(down, 1);
+ assertEquals(selenium.getText(output), "10", "Output was not updated.");
+ }
+
+ @Test
+ public void testDisabled() {
+ JQueryLocator selectOption = pjq("input[type=radio][name$=disabledInput][value=true]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ AttributeLocator disabledAttribute = input.getAttribute(new Attribute("disabled"));
+ assertEquals(selenium.getAttribute(disabledAttribute), "disabled", "Input should be disabled.");
+
+ assertFalse(selenium.isElementPresent(up), "Arrow up should be disabled.");
+ assertFalse(selenium.isElementPresent(down), "Arrow down should be disabled.");
+
+ JQueryLocator upDisabled = pjq("span[id$=spinner] span.rf-insp-inc-dis");
+ JQueryLocator downDisabled = pjq("span[id$=spinner] span.rf-insp-dec-dis");
+
+ assertTrue(selenium.isElementPresent(upDisabled), "An disabled up arrow should be displayed.");
+ assertTrue(selenium.isElementPresent(downDisabled), "An disabled downarrow should be displayed.");
+ }
+
+ @Test
+ public void testEnableManualInput() {
+ JQueryLocator selectOption = pjq("input[type=radio][name$=enableManualInputInput][value=false]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ AttributeLocator readonlyAttribute = input.getAttribute(new Attribute("readonly"));
+ assertEquals(selenium.getAttribute(readonlyAttribute), "readonly", "Input should be read-only.");
+
+ assertTrue(selenium.isElementPresent(up), "Arrow up should be displayed.");
+ assertTrue(selenium.isElementPresent(down), "Arrow down should be displayed.");
+ }
+
+ @Test
+ public void testImmediate() {
+ JQueryLocator immediateInput = pjq("input[type=radio][name$=immediateInput][value=true]");
+ selenium.click(immediateInput);
+ selenium.waitForPageToLoad();
+
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, "4");
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+ assertEquals(selenium.getText(output), "4", "Output was not updated.");
+
+ assertPhases(PhaseId.RESTORE_VIEW, PhaseId.APPLY_REQUEST_VALUES, PhaseId.PROCESS_VALIDATIONS, PhaseId.UPDATE_MODEL_VALUES,
+ PhaseId.INVOKE_APPLICATION, PhaseId.RENDER_RESPONSE);
+ }
+
+ @Test
+ public void testItemContentClass() {
+ testStyleClass(input, "inputClass");
+ }
+
+ @Test
+ public void testInputSize() {
+ JQueryLocator selectOption = pjq("input[type=text][id$=inputSizeInput]");
+
+ selenium.type(selectOption, "3");
+ selenium.waitForPageToLoad();
+ AttributeLocator sizeAttribute = input.getAttribute(new Attribute("size"));
+ assertEquals(selenium.getAttribute(sizeAttribute), "3", "Input's size attribute.");
+
+ selenium.type(selectOption, "40");
+ selenium.waitForPageToLoad();
+ assertEquals(selenium.getAttribute(sizeAttribute), "40", "Input's size attribute.");
+ }
+
+ @Test
+ public void testMaxValueType() {
+ JQueryLocator selectOption = pjq("input[type=text][id$=maxValueInput]");
+ selenium.type(selectOption, "13");
+ selenium.waitForPageToLoad();
+
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, "11");
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+ assertEquals(selenium.getText(output), "11", "Output was not updated.");
+
+ reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, "13");
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+ assertEquals(selenium.getText(output), "13", "Output was not updated.");
+
+ }
+
+ @Test
+ public void testMaxValueClick() {
+ JQueryLocator selectOption = pjq("input[type=text][id$=maxValueInput]");
+ selenium.type(selectOption, "13");
+ selenium.waitForPageToLoad();
+
+ clickArrow(up, 9);
+ assertEquals(selenium.getText(output), "11", "Output was not updated.");
+
+ clickArrow(up, 2);
+ assertEquals(selenium.getText(output), "13", "Output was not updated.");
+ }
+
+ @Test
+ public void testMinValueType() {
+ JQueryLocator selectOption = pjq("input[type=text][id$=minValueInput]");
+ selenium.type(selectOption, "-13");
+ selenium.waitForPageToLoad();
+
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, "-11");
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+ assertEquals(selenium.getText(output), "-11", "Output was not updated.");
+
+ reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, "-13");
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+ assertEquals(selenium.getText(output), "-13", "Output was not updated.");
+
+ }
+
+ @Test
+ public void testMinValueClick() {
+ JQueryLocator selectOption = pjq("input[type=text][id$=minValueInput]");
+ selenium.type(selectOption, "-13");
+ selenium.waitForPageToLoad();
+
+ clickArrow(down, 13);
+ assertEquals(selenium.getText(output), "-11", "Output was not updated.");
+
+ clickArrow(down, 2);
+ assertEquals(selenium.getText(output), "-13", "Output was not updated.");
+ }
+
+ @Test
+ public void testOnblur() {
+ testFireEvent(Event.BLUR, input);
+ }
+
+ @Test
+ public void testOnchangeType() {
+ ElementLocator<?> eventInput = pjq("input[id$=onchangeInput]");
+ String value = "metamerEvents += \"change \"";
+ selenium.type(eventInput, value);
+ selenium.waitForPageToLoad(TIMEOUT);
+
+ selenium.getEval(new JavaScript("window.metamerEvents = \"\";"));
+
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).type(input, "4");
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+
+ String[] events = selenium.getEval(new JavaScript("window.metamerEvents")).split(" ");
+
+ assertEquals(events[0], "change", "Attribute onchange doesn't work");
+ assertEquals(events.length, 1, "Only one event should be fired");
+ }
+
+ @Test
+ public void testOnchangeClick() {
+ ElementLocator<?> eventInput = pjq("input[id$=onchangeInput]");
+ String value = "metamerEvents += \"change \"";
+ selenium.type(eventInput, value);
+ selenium.waitForPageToLoad(TIMEOUT);
+
+ selenium.getEval(new JavaScript("window.metamerEvents = \"\";"));
+
+ clickArrow(up, 1);
+
+ String[] events = selenium.getEval(new JavaScript("window.metamerEvents")).split(" ");
+
+ assertEquals(events[0], "change", "Attribute onchange doesn't work");
+ assertEquals(events.length, 1, "Only one event should be fired");
+
+ clickArrow(down, 1);
+
+ events = selenium.getEval(new JavaScript("window.metamerEvents")).split(" ");
+
+ assertEquals(events[0], "change", "Attribute onchange doesn't work.");
+ assertEquals(events[1], "change", "Attribute onchange doesn't work.");
+ assertEquals(events.length, 2, "Two events should be fired after two clicks on arrows.");
+ }
+
+ @Test
+ public void testOnclick() {
+ testFireEvent(Event.CLICK, spinner);
+ }
+
+ @Test
+ public void testOndblclick() {
+ testFireEvent(Event.DBLCLICK, spinner);
+ }
+
+ @Test
+ public void testOndownclick() {
+ testFireEvent(Event.CLICK, down, "downclick");
+ }
+
+ @Test
+ public void testOnfocus() {
+ testFireEvent(Event.FOCUS, input);
+ }
+
+ @Test
+ public void testOninputclick() {
+ testFireEvent(Event.CLICK, input, "inputclick");
+ }
+
+ @Test
+ @IssueTracking("https://jira.jboss.org/browse/RF-9568")
+ public void testOninputdblclick() {
+ testFireEvent(Event.DBLCLICK, input, "inputdblclick");
+ }
+
+ @Test
+ public void testOninputkeydown() {
+ testFireEvent(Event.KEYDOWN, input, "inputkeydown");
+ }
+
+ @Test
+ public void testOninputkeypress() {
+ testFireEvent(Event.KEYPRESS, input, "inputkeypress");
+ }
+
+ @Test
+ public void testOninputkeyup() {
+ testFireEvent(Event.KEYUP, input, "inputkeyup");
+ }
+
+ @Test
+ public void testOninputmousedown() {
+ testFireEvent(Event.MOUSEDOWN, input, "inputmousedown");
+ }
+
+ @Test
+ public void testOninputmousemove() {
+ testFireEvent(Event.MOUSEMOVE, input, "inputmousemove");
+ }
+
+ @Test
+ public void testOninputmouseout() {
+ testFireEvent(Event.MOUSEOUT, input, "inputmouseout");
+ }
+
+ @Test
+ public void testOninputmouseover() {
+ testFireEvent(Event.MOUSEOVER, input, "inputmouseover");
+ }
+
+ @Test
+ public void testOninputmouseup() {
+ testFireEvent(Event.MOUSEUP, input, "inputmouseup");
+ }
+
+ @Test
+ public void testOnmousedown() {
+ testFireEvent(Event.MOUSEDOWN, spinner);
+ }
+
+ @Test
+ public void testOnmousemove() {
+ testFireEvent(Event.MOUSEMOVE, spinner);
+ }
+
+ @Test
+ public void testOnmouseout() {
+ testFireEvent(Event.MOUSEOUT, spinner);
+ }
+
+ @Test
+ public void testOnmouseover() {
+ testFireEvent(Event.MOUSEOVER, spinner);
+ }
+
+ @Test
+ public void testOnmouseup() {
+ testFireEvent(Event.MOUSEUP, spinner);
+ }
+
+ @Test
+ public void testOnselect() {
+ testFireEvent(Event.SELECT, input);
+ }
+
+ @Test
+ public void testOnupclick() {
+ testFireEvent(Event.CLICK, up, "upclick");
+ }
+
+ @Test
+ public void testRendered() {
+ JQueryLocator renderedInput = pjq("input[type=radio][name$=renderedInput][value=false]");
+ selenium.click(renderedInput);
+ selenium.waitForPageToLoad();
+
+ assertFalse(selenium.isElementPresent(spinner), "Spinner should not be rendered when rendered=false.");
+ }
+
+ @Test
+ public void testStyle() {
+ testStyle(spinner);
+ }
+
+ @Test
+ public void testStyleClass() {
+ testStyleClass(spinner, "styleClass");
+ }
+
+ @Test
+ @Use(field = "number", value = "correctNumbers")
+ public void testValueCorrect() {
+ selenium.type(pjq("input[id$=valueInput]"), number);
+ selenium.waitForPageToLoad();
+
+ assertEquals(selenium.getText(output), number, "Output was not updated.");
+ }
+
+ @Test
+ @Use(field = "number", value = "smallNumbers")
+ public void testValueSmall() {
+ selenium.type(pjq("input[id$=valueInput]"), number);
+ selenium.waitForPageToLoad();
+
+ assertEquals(selenium.getText(output), number, "Output was not updated.");
+ assertEquals(getInputValue(), "-10", "Input was not updated.");
+ }
+
+ @Test
+ @Use(field = "number", value = "bigNumbers")
+ public void testValueBig() {
+ selenium.type(pjq("input[id$=valueInput]"), number);
+ selenium.waitForPageToLoad();
+
+ assertEquals(selenium.getText(output), number, "Output was not updated.");
+ assertEquals(getInputValue(), "10", "Input was not updated.");
+ }
+
+ /**
+ * Getter for value that is displayed in spinner input.
+ * @return spinner input value
+ */
+ private String getInputValue() {
+ String id = selenium.getEval(new JavaScript("window.testedComponentId"));
+ return selenium.getEval(new JavaScript("window.RichFaces.$('" + id + "').value"));
+ }
+
+ /**
+ * Clicks on spinner's arrow.
+ * @param arrow spinner's up or down arrow locator
+ * @param clicks how many times should it be clicked
+ */
+ private void clickArrow(ElementLocator<?> arrow, int clicks) {
+ String reqTime = null;
+
+ for (int i = 0; i < clicks; i++) {
+ reqTime = selenium.getText(time);
+ guardXhr(selenium).runScript(new JavaScript("jQuery(\"" + arrow.getRawLocator() + "\").mousedown().mouseup()"));
+
+ waitGui.failWith("Page was not updated").waitForChange(reqTime, retrieveText.locator(time));
+ }
+ }
+}
Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinner.java
___________________________________________________________________
Name: svn:keywords
+ Revision
13 years, 6 months
JBoss Rich Faces SVN: r19753 - in sandbox/trunk/ui/calendar/ui/src/main: templates and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2010-10-29 05:42:50 -0400 (Fri, 29 Oct 2010)
New Revision: 19753
Modified:
sandbox/trunk/ui/calendar/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
sandbox/trunk/ui/calendar/ui/src/main/templates/calendar.template.xml
Log:
modify calendar markup to allow component works after ajax update
Modified: sandbox/trunk/ui/calendar/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2010-10-29 09:21:23 UTC (rev 19752)
+++ sandbox/trunk/ui/calendar/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2010-10-29 09:42:50 UTC (rev 19753)
@@ -381,6 +381,7 @@
this.TIME_EDITOR_BUTTON_CANCEL = this.id+'TimeEditorButtonCancel';
this.DATE_EDITOR_BUTTON_OK = this.id+'DateEditorButtonOk';
this.DATE_EDITOR_BUTTON_CANCEL = this.id+'DateEditorButtonCancel';
+ this.CALENDAR_CONTENT = this.id+"Content";
this.firstDateIndex = 0;
@@ -403,7 +404,7 @@
var tempStr = "RichFaces.$('"+this.id+"').";
- var htmlTextHeader = '<table id="'+this.id+'" border="0" cellpadding="0" cellspacing="0" class="rich-calendar-exterior rich-calendar-popup '+this.params.styleClass+'" style="'+popupStyles+this.params.style+'" onclick="'+tempStr+'skipEventOnCollapse=true;"><tbody>';
+ var htmlTextHeader = '<table id="'+this.CALENDAR_CONTENT+'" border="0" cellpadding="0" cellspacing="0" class="rich-calendar-exterior rich-calendar-popup '+this.params.styleClass+'" style="'+popupStyles+this.params.style+'" onclick="'+tempStr+'skipEventOnCollapse=true;"><tbody>';
var colspan = (this.params.showWeeksBar ? "8" : "7");
var htmlHeaderOptional = (this.params.optionalHeaderMarkup) ? '<tr><td class="rich-calendar-header-optional" colspan="'+colspan+'" id="'+this.id+'HeaderOptional"></td></tr>' : '';
var htmlFooterOptional = (this.params.optionalFooterMarkup) ? '<tr><td class="rich-calendar-footer-optional" colspan="'+colspan+'" id="'+this.id+'FooterOptional"></td></tr>' : '';
@@ -472,7 +473,7 @@
htmlTextWeek.push('</tr>');
}
- var div = rf.getDomElement(this.id);
+ var div = rf.getDomElement(this.CALENDAR_CONTENT);
div = $(div).replaceWith(htmlTextHeader+htmlHeaderOptional+htmlControlsHeader+htmlTextWeekDayBar.join('')+htmlTextWeek.join('')+htmlControlsFooter+htmlFooterOptional+htmlTextFooter);
this.attachToDom(this.id); // TODO: optimize double $
@@ -627,7 +628,7 @@
createEditor: function()
{
- var element = $(rf.getDomElement(this.id));
+ var element = $(rf.getDomElement(this.CALENDAR_CONTENT));
var zindex = parseInt(element.css('z-index'), 10);
var htmlBegin = '<div id="'+this.EDITOR_SHADOW_ID+'" class="rich-calendar-editor-shadow" style="position:absolute; display:none;z-index:'+zindex+'"></div><table border="0" cellpadding="0" cellspacing="0" id="'+this.EDITOR_ID+'" style="position:absolute; display:none;z-index:'+(zindex+1)+'" onclick="RichFaces.$(\''+this.id+'\').skipEventOnCollapse=true;"><tbody><tr><td class="rich-calendar-editor-container" align="center"><div style="position:relative; width:100%">';
var htmlContent = '<div id="'+this.EDITOR_LAYOUT_SHADOW_ID+'" class="rich-calendar-editor-layout-shadow"></div>';
@@ -864,16 +865,14 @@
if (!this.params.popup || !this.isVisible) return;
- var element = rf.getDomElement(this.id);
-
- if (this.invokeEvent("collapse", element))
+ if (this.invokeEvent("collapse", rf.getDomElement(this.id)))
{
if (this.isEditorVisible) this.hideEditor();
this.scrollElements && rf.Event.unbindScrollEventHandlers(this.scrollElements, this);
this.scrollElements = null;
rf.Event.unbind(window.document, "click"+this.namespace);
- $(element).hide();
+ $(rf.getDomElement(this.CALENDAR_CONTENT)).hide();
this.isVisible = false;
}
@@ -914,7 +913,7 @@
base = baseButton;
};
- $(element).setPosition(base, {type:"DROPDOWN", from: this.params.jointPoint, to:this.params.direction, offset: this.popupOffset}).show();
+ $(rf.getDomElement(this.CALENDAR_CONTENT)).setPosition(base, {type:"DROPDOWN", from: this.params.jointPoint, to:this.params.direction, offset: this.popupOffset}).show();
this.isVisible = true;
@@ -1717,7 +1716,7 @@
var editor_shadow = rf.getDomElement(this.EDITOR_SHADOW_ID);
- this.clonePosition(rf.getDomElement(this.id), [editor, editor_shadow]);
+ this.clonePosition(rf.getDomElement(this.CALENDAR_CONTENT), [editor, editor_shadow]);
this.updateTimeEditor();
@@ -1781,7 +1780,7 @@
var editor_shadow = rf.getDomElement(this.EDITOR_SHADOW_ID);
- this.clonePosition(rf.getDomElement(this.id), [editor, editor_shadow]);
+ this.clonePosition(rf.getDomElement(this.CALENDAR_CONTENT), [editor, editor_shadow]);
$(editor_shadow).show();
$(editor).show();
Modified: sandbox/trunk/ui/calendar/ui/src/main/templates/calendar.template.xml
===================================================================
--- sandbox/trunk/ui/calendar/ui/src/main/templates/calendar.template.xml 2010-10-29 09:21:23 UTC (rev 19752)
+++ sandbox/trunk/ui/calendar/ui/src/main/templates/calendar.template.xml 2010-10-29 09:42:50 UTC (rev 19753)
@@ -22,6 +22,7 @@
<cdk:renderer-type>org.richfaces.CalendarRenderer</cdk:renderer-type>
</cc:interface>
<cc:implementation>
+ <span id="#{clientId}">
<span id="#{clientId}Popup"
style="#{component.attributes['popup'] ? '' : 'display: none'}">
<c:choose>
@@ -63,14 +64,15 @@
autocomplete="off" name="#{clientId}InputCurrentDate"
value="#{getCurrentDateAsString(facesContext, component)}" />
</span>
- <div style="display: none;" id="#{clientId}"></div>
- <div style="display: none;" id="#{clientId}Script">
+ <span style="display: none;" id="#{clientId}Content"></span>
+ <span style="display: none;" id="#{clientId}Script">
<script type="text/javascript">
<cdk:call
expression="buildAddLocaleScript(responseWriter, facesContext, component);" />
<cdk:call
expression="buildCalendarScript(responseWriter, facesContext, component);" />
</script>
- </div>
+ </span>
+ </span>
</cc:implementation>
</cdk:root>
13 years, 6 months
JBoss Rich Faces SVN: r19752 - in modules/tests/metamer/trunk/application/src/main: webapp/components/richInputNumberSpinner and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-10-29 05:21:23 -0400 (Fri, 29 Oct 2010)
New Revision: 19752
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichInputNumberSpinnerBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richInputNumberSpinner/simple.xhtml
Log:
https://jira.jboss.org/browse/RFPL-857
* default, min and max values changed
* added component id script to the page
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichInputNumberSpinnerBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichInputNumberSpinnerBean.java 2010-10-29 09:17:07 UTC (rev 19751)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichInputNumberSpinnerBean.java 2010-10-29 09:21:23 UTC (rev 19752)
@@ -57,10 +57,11 @@
attributes = Attributes.getUIComponentAttributes(HtmlInputNumberSpinner.class, getClass());
attributes.setAttribute("enableManualInput", true);
- attributes.setAttribute("maxValue", 100);
- attributes.setAttribute("minValue", 0);
+ attributes.setAttribute("maxValue", 10);
+ attributes.setAttribute("minValue", -10);
attributes.setAttribute("rendered", true);
attributes.setAttribute("step", 1);
+ attributes.setAttribute("value", 2);
// TODO has to be tested in another way
attributes.remove("validator");
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richInputNumberSpinner/simple.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richInputNumberSpinner/simple.xhtml 2010-10-29 09:17:07 UTC (rev 19751)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richInputNumberSpinner/simple.xhtml 2010-10-29 09:21:23 UTC (rev 19752)
@@ -34,6 +34,9 @@
<f:converter converterId="templatesListConverter" />
</f:viewParam>
</f:metadata>
+ <script type="text/javascript">
+ testedComponentId = "#{rich:clientId('spinner')}";
+ </script>
</ui:define>
<ui:define name="outOfTemplateBefore">
@@ -91,7 +94,7 @@
value="#{richInputNumberSpinnerBean.attributes['value'].value}"
valueChangeListeners="#{richInputNumberSpinnerBean.attributes['valueChangeListeners'].value}">
- <a4j:ajax render="output"/>
+ <a4j:ajax render="output" action="#{richBean.dummyAction}" actionListener="#{richBean.dummyActionListener}" />
</rich:inputNumberSpinner>
13 years, 6 months
JBoss Rich Faces SVN: r19751 - modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-10-29 05:17:07 -0400 (Fri, 29 Oct 2010)
New Revision: 19751
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
Log:
* added dummy action and action listener
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-10-29 04:32:06 UTC (rev 19750)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2010-10-29 09:17:07 UTC (rev 19751)
@@ -35,6 +35,7 @@
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpSession;
@@ -343,4 +344,23 @@
public String causeError() {
throw new FacesException("Ajax request caused an error. This is intentional behavior.");
}
+
+ /**
+ * An action that does nothing.
+ * @return null
+ */
+ public String dummyAction() {
+ logToPage("* action invoked");
+ return null;
+ }
+
+ /**
+ * An action listener that does nothing.
+ *
+ * @param event
+ * an event representing the activation of a user interface component (not used)
+ */
+ public void dummyActionListener(ActionEvent event) {
+ logToPage("* action listener invoked");
+ }
}
13 years, 6 months
JBoss Rich Faces SVN: r19750 - in branches/RF-8742/ui/validator: impl/src/main/java/org/richfaces/application and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-10-29 00:32:06 -0400 (Fri, 29 Oct 2010)
New Revision: 19750
Added:
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java
Modified:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorFactory.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/application/ValidatorModule.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/MessageFactory.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
Log:
RESOLVED - issue RF-9510: BeanValidatorService tests and implementation
https://jira.jboss.org/browse/RF-9510
Modified: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorFactory.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorFactory.java 2010-10-29 01:43:38 UTC (rev 19749)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorFactory.java 2010-10-29 04:32:06 UTC (rev 19750)
@@ -3,8 +3,12 @@
*/
package org.richfaces.validator;
+import java.lang.annotation.Annotation;
+
+import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.validation.Validator;
+import javax.validation.metadata.ConstraintDescriptor;
/**
* @author asmirnov
@@ -14,4 +18,6 @@
Validator getValidator(FacesContext context);
+ FacesMessage interpolateMessage(FacesContext context, final ConstraintDescriptor<? extends Annotation> constrain);
+
}
Modified: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/application/ValidatorModule.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/application/ValidatorModule.java 2010-10-29 01:43:38 UTC (rev 19749)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/application/ValidatorModule.java 2010-10-29 04:32:06 UTC (rev 19750)
@@ -25,13 +25,19 @@
import javax.validation.ValidationException;
+import org.richfaces.el.ValueExpressionAnalayserImpl;
import org.richfaces.validator.BeanValidator;
+import org.richfaces.validator.BeanValidatorFactory;
+import org.richfaces.validator.BeanValidatorService;
+import org.richfaces.validator.BeanValidatorServiceImpl;
import org.richfaces.validator.ConverterServiceImpl;
+import org.richfaces.validator.DummyBeanValidatorService;
import org.richfaces.validator.FacesConverterService;
import org.richfaces.validator.FacesValidatorService;
import org.richfaces.validator.FacesValidatorServiceImpl;
import org.richfaces.validator.NullValidator;
import org.richfaces.validator.ObjectValidator;
+import org.richfaces.validator.RichFacesBeanValidatorFactory;
/**
* <p class="changed_added_4_0">
@@ -49,29 +55,30 @@
* @see org.richfaces.application.Module#configure(org.richfaces.application.ServicesFactory)
*/
public void configure(ServicesFactory factory) {
- factory.setInstance(ObjectValidator.class, createObjectValidator());
+ configureBeanValidators(factory);
factory.setInstance(FacesConverterService.class, new ConverterServiceImpl());
factory.setInstance(FacesValidatorService.class, new FacesValidatorServiceImpl());
}
- /**
- * Create BeanValidator instance. For a Junit tests only.
- *
- * @return
- */
- static ObjectValidator createObjectValidator() {
- ObjectValidator validator = null;
+
+ void configureBeanValidators(ServicesFactory factory){
+ BeanValidatorService service ;
+ ObjectValidator validator;
try {
- validator = new BeanValidator();
+ BeanValidatorFactory validatorFactory = new RichFacesBeanValidatorFactory();
+ service = new BeanValidatorServiceImpl(new ValueExpressionAnalayserImpl(), validatorFactory);
+ validator = new BeanValidator(validatorFactory);
} catch (ValidationException e) {
// JSR-303 is available but not initialised.
+ service = new DummyBeanValidatorService();
validator = new NullValidator();
} catch (NoClassDefFoundError e){
// JSR-303 is not avalable.
// log.warn("Validator implementations not found at classpath, default NullValidator will be used.");
+ service = new DummyBeanValidatorService();
validator = new NullValidator();
}
- return validator;
+ factory.setInstance(BeanValidatorService.class, service);
+ factory.setInstance(ObjectValidator.class, validator);
}
-
}
Modified: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java 2010-10-29 01:43:38 UTC (rev 19749)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java 2010-10-29 04:32:06 UTC (rev 19750)
@@ -5,17 +5,13 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Locale;
import java.util.Set;
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.validation.ConstraintViolation;
-import javax.validation.MessageInterpolator;
-import javax.validation.Validation;
import javax.validation.Validator;
-import javax.validation.ValidatorContext;
-import javax.validation.ValidatorFactory;
+import javax.validation.groups.Default;
/**
* @author asmirnov
@@ -23,20 +19,12 @@
*/
public class BeanValidator extends ObjectValidator {
- private static final Class[] DEFAULT_PROFILE = new Class[] {};
- private final ValidatorFactory validatorFactory;
- private ValidatorContext validatorContext;
+ private static final Class<?>[] DEFAULT_PROFILE = new Class[] {Default.class};
+ private final BeanValidatorFactory validatorFactory;
- public BeanValidator() {
- // Enforce class to load
- ValidatorFactory.class.getName();
- // Check Factory, to avoid instantiation errors
- // https://jira.jboss.org/jira/browse/RF-7226
- validatorFactory = Validation.buildDefaultValidatorFactory();
- validatorContext = validatorFactory.usingContext();
- MessageInterpolator jsfMessageInterpolator =
- new JsfMessageInterpolator(validatorFactory.getMessageInterpolator());
- validatorContext.messageInterpolator(jsfMessageInterpolator);
+
+ public BeanValidator(BeanValidatorFactory validatorFactory) {
+ this.validatorFactory = validatorFactory;
}
/*
@@ -115,37 +103,8 @@
}
protected Validator getValidator(FacesContext facesContext) {
- Validator beanValidator = validatorContext.getValidator();
+ Validator beanValidator = validatorFactory.getValidator(facesContext);
return beanValidator;
}
- private static class JsfMessageInterpolator implements MessageInterpolator {
-
- private MessageInterpolator delegate;
-
- public JsfMessageInterpolator(MessageInterpolator delegate) {
- this.delegate = delegate;
- }
-
- public String interpolate(String messageTemplate, Context context) {
-
- Locale locale = ObjectValidator.calculateLocale(FacesContext.getCurrentInstance());
- if (null != locale) {
- return delegate.interpolate(messageTemplate, context, locale);
- } else {
- return delegate.interpolate(messageTemplate, context);
- }
- }
-
- public String interpolate(String messageTemplate, Context context, Locale locale) {
- Locale faceslocale = ObjectValidator.calculateLocale(FacesContext.getCurrentInstance());
- if (null != faceslocale) {
- return delegate.interpolate(messageTemplate, context, faceslocale);
- } else {
- return delegate.interpolate(messageTemplate, context, locale);
- }
- }
-
- }
-
}
Modified: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2010-10-29 01:43:38 UTC (rev 19749)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2010-10-29 04:32:06 UTC (rev 19750)
@@ -12,9 +12,11 @@
import javax.el.ELException;
import javax.el.ValueExpression;
+import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.validation.Validator;
import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
import org.richfaces.el.ValueDescriptor;
import org.richfaces.el.ValueExpressionAnalayser;
@@ -55,25 +57,32 @@
Collection<ValidatorDescriptor> processBeanAttribute(FacesContext context, ValueDescriptor descriptor,
Class<?>... groups) {
- Set<ConstraintDescriptor<?>> constraints = getValidator(context)
- .getConstraintsForClass(descriptor.getBeanType()).getConstraintsForProperty(descriptor.getName())
- .findConstraints().unorderedAndMatchingGroups(groups) // or the requested list of groups)
- .getConstraintDescriptors();
+ PropertyDescriptor constraintsForProperty = getValidator(context).getConstraintsForClass(
+ descriptor.getBeanType()).getConstraintsForProperty(descriptor.getName());
+ if (null != constraintsForProperty) {
+ Set<ConstraintDescriptor<?>> constraints = constraintsForProperty.findConstraints()
+ .unorderedAndMatchingGroups(groups) // or the requested list of groups)
+ .getConstraintDescriptors();
- // ContextHolder is an arbitrary object, it will depend on the implementation
- Set<ValidatorDescriptor> descriptors = new HashSet<ValidatorDescriptor>(constraints.size());
- processConstraints(context, constraints, descriptors);
- return descriptors;
+ // ContextHolder is an arbitrary object, it will depend on the implementation
+ Set<ValidatorDescriptor> descriptors = new HashSet<ValidatorDescriptor>(constraints.size());
+ processConstraints(context, constraints, descriptors);
+ return descriptors;
+
+ } else {
+ return Collections.emptySet();
+ }
}
void processConstraints(FacesContext context, Set<ConstraintDescriptor<?>> constraints,
Collection<ValidatorDescriptor> descriptors) {
- for (ConstraintDescriptor cd : constraints) {
+ for (ConstraintDescriptor<?> cd : constraints) {
Annotation a = cd.getAnnotation();
Map<String, Object> parameters = cd.getAttributes();
// TODO if cd.isReportedAsSingleConstraint() make sure than only the root constraint raises an error message
// if one or several of the composing constraints are invalid)
- BeanValidatorDescriptor beanValidatorDescriptor = new BeanValidatorDescriptor(a.getClass(), null);
+ FacesMessage message = validatorFactory.interpolateMessage(context, cd);
+ BeanValidatorDescriptor beanValidatorDescriptor = new BeanValidatorDescriptor(a.getClass(), message);
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
beanValidatorDescriptor.addParameter(entry.getKey(), entry.getValue());
}
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java 2010-10-29 04:32:06 UTC (rev 19750)
@@ -0,0 +1,26 @@
+/**
+ *
+ */
+package org.richfaces.validator;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class DummyBeanValidatorService implements BeanValidatorService {
+
+ /* (non-Javadoc)
+ * @see org.richfaces.validator.BeanValidatorService#getConstrains(javax.faces.context.FacesContext, javax.el.ValueExpression, java.lang.Class<?>[])
+ */
+ public Collection<ValidatorDescriptor> getConstrains(FacesContext context, ValueExpression expression,
+ Class<?>... groups) {
+ return Collections.emptySet();
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/MessageFactory.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/MessageFactory.java 2010-10-29 01:43:38 UTC (rev 19749)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/MessageFactory.java 2010-10-29 04:32:06 UTC (rev 19750)
@@ -53,7 +53,7 @@
return new FacesMessage(summary, detail);
}
- private static Locale getCurrentLocale(FacesContext context) {
+ public static Locale getCurrentLocale(FacesContext context) {
UIViewRoot viewRoot = context.getViewRoot();
Locale locale;
if (null == viewRoot) {
Modified: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java 2010-10-29 01:43:38 UTC (rev 19749)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java 2010-10-29 04:32:06 UTC (rev 19750)
@@ -3,14 +3,19 @@
*/
package org.richfaces.validator;
+import java.lang.annotation.Annotation;
import java.util.Locale;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.validation.MessageInterpolator;
+import javax.validation.MessageInterpolator.Context;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorContext;
import javax.validation.ValidatorFactory;
+import javax.validation.metadata.ConstraintDescriptor;
/**
* @author asmirnov
@@ -39,8 +44,28 @@
public Validator getValidator(FacesContext context) {
return validatorContext.getValidator();
}
+
+ public FacesMessage interpolateMessage(FacesContext context,final ConstraintDescriptor<? extends Annotation> constrain){
+ if(constrain.getAttributes().containsKey("message")){
+ Object object = constrain.getAttributes().get("message");
+ String interpolatedMessage;
+ interpolatedMessage = validatorFactory.getMessageInterpolator().interpolate(object.toString(), new Context() {
+
+ public Object getValidatedValue() {
+ return "{0}";
+ }
+
+ public ConstraintDescriptor<?> getConstraintDescriptor() {
+ return constrain;
+ }
+ }, MessageFactory.getCurrentLocale(context));
+ return new FacesMessage(interpolatedMessage);
+ } else {
+ return MessageFactory.createMessage(context, UIInput.UPDATE_MESSAGE_ID);
+ }
+ }
- private static class JsfMessageInterpolator implements MessageInterpolator {
+ private static final class JsfMessageInterpolator implements MessageInterpolator {
private MessageInterpolator delegate;
@@ -50,7 +75,7 @@
public String interpolate(String messageTemplate, Context context) {
- Locale locale = ObjectValidator.calculateLocale(FacesContext.getCurrentInstance());
+ Locale locale = MessageFactory.getCurrentLocale(FacesContext.getCurrentInstance());
if (null != locale) {
return delegate.interpolate(messageTemplate, context, locale);
} else {
@@ -59,7 +84,7 @@
}
public String interpolate(String messageTemplate, Context context, Locale locale) {
- Locale faceslocale = ObjectValidator.calculateLocale(FacesContext.getCurrentInstance());
+ Locale faceslocale = MessageFactory.getCurrentLocale(FacesContext.getCurrentInstance());
if (null != faceslocale) {
return delegate.interpolate(messageTemplate, context, faceslocale);
} else {
Modified: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java 2010-10-29 01:43:38 UTC (rev 19749)
+++ branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java 2010-10-29 04:32:06 UTC (rev 19750)
@@ -7,8 +7,10 @@
import java.lang.annotation.Annotation;
import java.util.Collection;
+import java.util.Locale;
import javax.el.ValueExpression;
+import javax.faces.component.UIViewRoot;
import javax.validation.constraints.Size;
import org.jboss.test.faces.mock.Environment;
@@ -41,6 +43,9 @@
@Mock
private ValueExpressionAnalayser analayser;
+ @Mock
+ private UIViewRoot viewRoot;
+
private MockController controller;
private BeanValidatorServiceImpl validatorService;
@@ -48,7 +53,10 @@
@Before
public void setUp() throws Exception {
- validatorService = new BeanValidatorServiceImpl(analayser);
+ RichFacesBeanValidatorFactory validatorFactory = new RichFacesBeanValidatorFactory();
+ validatorService = new BeanValidatorServiceImpl(analayser,validatorFactory);
+ expect(environment.getFacesContext().getViewRoot()).andStubReturn(viewRoot);
+ expect(viewRoot.getLocale()).andStubReturn(Locale.ENGLISH);
}
@After
@@ -65,6 +73,14 @@
public void testGetNoValidator() throws Exception {
forProperty(Bean.class, "list");expectValidators();
}
+
+ @Test
+ public void testValidatorMessageExtractor() throws Exception {
+ forProperty(Bean.class, "string");
+ Collection<ValidatorDescriptor> validators = expectValidators(Size.class);
+ ValidatorDescriptor validatorDescriptor = Iterables.getOnlyElement(validators);
+ assertEquals("size must be between 0 and 2",validatorDescriptor.getMessage().getSummary());
+ }
private void forProperty(Class<?> beanClass,String property){
expect(analayser.getPropertyDescriptor(environment.getFacesContext(), expression)).andReturn(new ValueDescriptor(beanClass,property));
@@ -84,7 +100,7 @@
for (final Class<? extends Annotation> class1 : validators) {
Iterables.find(constrains, new Predicate<ValidatorDescriptor>(){
public boolean apply(ValidatorDescriptor input) {
- return class1.equals(input.getImplementationClass());
+ return class1.isAssignableFrom(input.getImplementationClass());
}
});
Modified: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-10-29 01:43:38 UTC (rev 19749)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-10-29 04:32:06 UTC (rev 19750)
@@ -26,6 +26,7 @@
import org.richfaces.validator.LibraryScriptString;
import org.richfaces.validator.ScriptNotFoundException;
import org.richfaces.validator.FacesObjectDescriptor;
+import org.richfaces.validator.ValidatorDescriptor;
import com.google.common.collect.Lists;
@@ -130,7 +131,7 @@
ComponentValidatorScript createValidatorScript(ClientBehaviorContext behaviorContext,
ClientValidatorBehavior behavior) {
ValidatorScriptBase validatorScript;
- Collection<FacesObjectDescriptor> validators = behavior.getValidators(behaviorContext);
+ Collection<ValidatorDescriptor> validators = behavior.getValidators(behaviorContext);
if (!validators.isEmpty()) {
try {
ConverterDescriptor converter = behavior.getConverter(behaviorContext);
@@ -160,7 +161,7 @@
}
private ValidatorScriptBase createValidatorScript(ClientBehaviorContext behaviorContext,
- ClientValidatorBehavior behavior, Collection<FacesObjectDescriptor> validators,
+ ClientValidatorBehavior behavior, Collection<ValidatorDescriptor> validators,
LibraryScriptString clientSideConverterScript) {
Collection<? extends LibraryScriptString> validatorScripts = getClientSideValidatorScript(behaviorContext.getFacesContext(), validators);
if (validatorScripts.isEmpty()) {
@@ -216,7 +217,7 @@
* @throws ScriptNotFoundException
*/
Collection<? extends LibraryScriptString> getClientSideValidatorScript(FacesContext facesContext,
- Collection<FacesObjectDescriptor> validators) {
+ Collection<ValidatorDescriptor> validators) {
ClientScriptService clientScriptService =
ServiceTracker.getService(facesContext, ClientScriptService.class);
List<LibraryScriptString> scripts = Lists.newArrayList();
13 years, 6 months
JBoss Rich Faces SVN: r19749 - in branches/RF-8742/ui/validator: api/src/main/java/org/richfaces/validator and 5 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-10-28 21:43:38 -0400 (Thu, 28 Oct 2010)
New Revision: 19749
Added:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorFactory.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorDescriptor.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java
Modified:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/CapturingELContext.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Bean.java
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
Log:
CODING IN PROGRESS - issue RF-9510: BeanValidatorService tests and implementation
https://jira.jboss.org/browse/RF-9510
Modified: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java 2010-10-28 20:31:56 UTC (rev 19748)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java 2010-10-29 01:43:38 UTC (rev 19749)
@@ -11,9 +11,7 @@
public class ValueDescriptor {
private final String name;
-
- private final boolean readOnly;
-
+
private final Class<?> beanType;
private final Class<?> propertyType;
@@ -24,15 +22,14 @@
* @param propertyType
* @param readOnly
*/
- ValueDescriptor(Class<?> beanType, String name, Class<?> propertyType, boolean readOnly) {
+ public ValueDescriptor(Class<?> beanType, String name, Class<?> propertyType) {
this.beanType = beanType;
this.name = name;
this.propertyType = propertyType;
- this.readOnly = readOnly;
}
- ValueDescriptor(Class<?> beanType, String name) {
- this(beanType,name,Object.class,false);
+ public ValueDescriptor(Class<?> beanType, String name) {
+ this(beanType,name,Object.class);
}
/**
@@ -42,12 +39,6 @@
return name;
}
- /**
- * @return the readOnly
- */
- public boolean isReadOnly() {
- return readOnly;
- }
/**
* @return the beanType
Added: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorFactory.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorFactory.java (rev 0)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorFactory.java 2010-10-29 01:43:38 UTC (rev 19749)
@@ -0,0 +1,17 @@
+/**
+ *
+ */
+package org.richfaces.validator;
+
+import javax.faces.context.FacesContext;
+import javax.validation.Validator;
+
+/**
+ * @author asmirnov
+ *
+ */
+public interface BeanValidatorFactory {
+
+ Validator getValidator(FacesContext context);
+
+}
Property changes on: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/CapturingELContext.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/CapturingELContext.java 2010-10-28 20:31:56 UTC (rev 19748)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/CapturingELContext.java 2010-10-29 01:43:38 UTC (rev 19749)
@@ -118,7 +118,7 @@
context.setPropertyResolved(true);
reference = new ValueReference(base, property, reference);
}
- return Object.class;
+ return delegate.getType(context, base, property);
}
@Override
Modified: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java 2010-10-28 20:31:56 UTC (rev 19748)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java 2010-10-29 01:43:38 UTC (rev 19749)
@@ -1,20 +1,25 @@
package org.richfaces.el;
+import javax.el.ELException;
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;
public class ValueExpressionAnalayserImpl implements ValueExpressionAnalayser {
- public ValueDescriptor getPropertyDescriptor(FacesContext context, ValueExpression expression) {
+ public ValueDescriptor getPropertyDescriptor(FacesContext context, ValueExpression expression) throws ELException {
+ if(null == context || null == expression){
+ throw new NullPointerException();
+ }
CapturingELContext capturingContext = new CapturingELContext(context.getELContext());
- expression.getType(capturingContext);
+ Class<?> type = expression.getType(capturingContext);
ValueReference reference = capturingContext.getReference();
if(null != reference && null != reference.getBase() && null != reference.getProperty()){
// TODO - detect arrays, maps and lists. Check JSF implementation code - seems that Mojarra dosn't validate such fields.
- ValueDescriptor descriptor = new ValueDescriptor(reference.getBase().getClass(),reference.getProperty().toString());
+ ValueDescriptor descriptor = new ValueDescriptor(reference.getBase().getClass(),reference.getProperty().toString(),type);
return descriptor;
+ } else {
+ throw new ELException("Cannot determine property for expression "+expression.getExpressionString());
}
- return null;
}
}
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorDescriptor.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorDescriptor.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorDescriptor.java 2010-10-29 01:43:38 UTC (rev 19749)
@@ -0,0 +1,13 @@
+package org.richfaces.validator;
+
+import java.lang.annotation.Annotation;
+
+import javax.faces.application.FacesMessage;
+
+public class BeanValidatorDescriptor extends BaseFacesObjectDescriptor<Annotation> implements ValidatorDescriptor {
+
+ public BeanValidatorDescriptor(Class<? extends Annotation> validatorClass, FacesMessage message) {
+ super(validatorClass, message);
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorDescriptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2010-10-29 01:43:38 UTC (rev 19749)
@@ -0,0 +1,85 @@
+/**
+ *
+ */
+package org.richfaces.validator;
+
+import java.lang.annotation.Annotation;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+import javax.validation.Validator;
+import javax.validation.metadata.ConstraintDescriptor;
+
+import org.richfaces.el.ValueDescriptor;
+import org.richfaces.el.ValueExpressionAnalayser;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class BeanValidatorServiceImpl implements BeanValidatorService {
+
+ private final ValueExpressionAnalayser analayser;
+ private final BeanValidatorFactory validatorFactory;
+
+ public BeanValidatorServiceImpl(ValueExpressionAnalayser analayser, BeanValidatorFactory validatorFactory) {
+ this.analayser = analayser;
+ this.validatorFactory = validatorFactory;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.validator.BeanValidatorService#getConstrains(javax.faces.context.FacesContext,
+ * javax.el.ValueExpression, java.lang.Class<?>[])
+ */
+ public Collection<ValidatorDescriptor> getConstrains(FacesContext context, ValueExpression expression,
+ Class<?>... groups) {
+ try {
+ ValueDescriptor propertyDescriptor = analayser.getPropertyDescriptor(context, expression);
+ return processBeanAttribute(context, propertyDescriptor, groups);
+ } catch (ELException e) {
+ return Collections.emptySet();
+ }
+ }
+
+ private Validator getValidator(FacesContext context) {
+ return validatorFactory.getValidator(context);
+ }
+
+ Collection<ValidatorDescriptor> processBeanAttribute(FacesContext context, ValueDescriptor descriptor,
+ Class<?>... groups) {
+ Set<ConstraintDescriptor<?>> constraints = getValidator(context)
+ .getConstraintsForClass(descriptor.getBeanType()).getConstraintsForProperty(descriptor.getName())
+ .findConstraints().unorderedAndMatchingGroups(groups) // or the requested list of groups)
+ .getConstraintDescriptors();
+
+ // ContextHolder is an arbitrary object, it will depend on the implementation
+ Set<ValidatorDescriptor> descriptors = new HashSet<ValidatorDescriptor>(constraints.size());
+ processConstraints(context, constraints, descriptors);
+ return descriptors;
+ }
+
+ void processConstraints(FacesContext context, Set<ConstraintDescriptor<?>> constraints,
+ Collection<ValidatorDescriptor> descriptors) {
+ for (ConstraintDescriptor cd : constraints) {
+ Annotation a = cd.getAnnotation();
+ Map<String, Object> parameters = cd.getAttributes();
+ // TODO if cd.isReportedAsSingleConstraint() make sure than only the root constraint raises an error message
+ // if one or several of the composing constraints are invalid)
+ BeanValidatorDescriptor beanValidatorDescriptor = new BeanValidatorDescriptor(a.getClass(), null);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ beanValidatorDescriptor.addParameter(entry.getKey(), entry.getValue());
+ }
+ beanValidatorDescriptor.makeImmutable();
+ descriptors.add(beanValidatorDescriptor);
+ processConstraints(context, cd.getComposingConstraints(), descriptors); // process the composing constraints
+ }
+ }
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java 2010-10-29 01:43:38 UTC (rev 19749)
@@ -0,0 +1,72 @@
+/**
+ *
+ */
+package org.richfaces.validator;
+
+import java.util.Locale;
+
+import javax.faces.context.FacesContext;
+import javax.validation.MessageInterpolator;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+import javax.validation.ValidatorFactory;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class RichFacesBeanValidatorFactory implements BeanValidatorFactory {
+
+ private ValidatorFactory validatorFactory;
+ private ValidatorContext validatorContext;
+
+ public RichFacesBeanValidatorFactory() {
+ // Enforce class to load
+ ValidatorFactory.class.getName();
+ // Check Factory, to avoid instantiation errors
+ // https://jira.jboss.org/jira/browse/RF-7226
+ validatorFactory = Validation.buildDefaultValidatorFactory();
+ validatorContext = validatorFactory.usingContext();
+ MessageInterpolator jsfMessageInterpolator =
+ new JsfMessageInterpolator(validatorFactory.getMessageInterpolator());
+ validatorContext.messageInterpolator(jsfMessageInterpolator);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.validator.BeanValidatorFactory#getValidator(javax.faces.context.FacesContext)
+ */
+ public Validator getValidator(FacesContext context) {
+ return validatorContext.getValidator();
+ }
+
+ private static class JsfMessageInterpolator implements MessageInterpolator {
+
+ private MessageInterpolator delegate;
+
+ public JsfMessageInterpolator(MessageInterpolator delegate) {
+ this.delegate = delegate;
+ }
+
+ public String interpolate(String messageTemplate, Context context) {
+
+ Locale locale = ObjectValidator.calculateLocale(FacesContext.getCurrentInstance());
+ if (null != locale) {
+ return delegate.interpolate(messageTemplate, context, locale);
+ } else {
+ return delegate.interpolate(messageTemplate, context);
+ }
+ }
+
+ public String interpolate(String messageTemplate, Context context, Locale locale) {
+ Locale faceslocale = ObjectValidator.calculateLocale(FacesContext.getCurrentInstance());
+ if (null != faceslocale) {
+ return delegate.interpolate(messageTemplate, context, faceslocale);
+ } else {
+ return delegate.interpolate(messageTemplate, context, locale);
+ }
+ }
+
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/RichFacesBeanValidatorFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java 2010-10-28 20:31:56 UTC (rev 19748)
+++ branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java 2010-10-29 01:43:38 UTC (rev 19749)
@@ -1,17 +1,57 @@
package org.richfaces.el;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.*;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+import org.jboss.test.faces.mock.FacesMock;
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockTestRunner;
import org.junit.After;
import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.el.model.Bean;
-public class ValueExpressionAnalayserTest {
+(a)RunWith(MockTestRunner.class)
+public class ValueExpressionAnalayserTest extends ELTestBase {
+
+
+ private ValueExpressionAnalayser analayser;
+
+ @Mock
+ private FacesContext facesContext;
@Before
- public void setUp() throws Exception {
+ public void setUpAnalayser() throws Exception {
+ analayser = new ValueExpressionAnalayserImpl();
}
@After
- public void tearDown() throws Exception {
+ public void tearDownAnalayser() throws Exception {
+ analayser = null;
}
-
+ @Test
+ public void testGetDescriptionPositive() throws Exception {
+ ValueExpression expression = parse("#{bean.string}");
+ expect(facesContext.getELContext()).andReturn(elContext);
+ FacesMock.replay(facesContext);
+ ValueDescriptor propertyDescriptor = analayser.getPropertyDescriptor(facesContext, expression);
+ assertEquals(Bean.class, propertyDescriptor.getBeanType());
+ assertEquals("string", propertyDescriptor.getName());
+ assertEquals(String.class,propertyDescriptor.getPropertyType());
+ FacesMock.verify(facesContext);
+ }
+
+ @Test(expected=ELException.class)
+ public void testGetDescriptionNegative() throws Exception {
+ ValueExpression expression = parse("#{bean}");
+ expect(facesContext.getELContext()).andReturn(elContext);
+ FacesMock.replay(facesContext);
+ ValueDescriptor propertyDescriptor = analayser.getPropertyDescriptor(facesContext, expression);
+ }
}
Modified: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Bean.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Bean.java 2010-10-28 20:31:56 UTC (rev 19748)
+++ branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Bean.java 2010-10-29 01:43:38 UTC (rev 19749)
@@ -4,6 +4,8 @@
import java.util.List;
import java.util.Map;
+import javax.validation.constraints.Size;
+
public class Bean {
private List<String> list;
@@ -28,6 +30,7 @@
this.map = map;
}
+ @Size(max=2)
public String getString() {
return string;
}
Modified: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java 2010-10-28 20:31:56 UTC (rev 19748)
+++ branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java 2010-10-29 01:43:38 UTC (rev 19749)
@@ -1,17 +1,94 @@
package org.richfaces.validator;
+import static junit.framework.Assert.assertEquals;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.*;
+
+import java.lang.annotation.Annotation;
+import java.util.Collection;
+
+import javax.el.ValueExpression;
+import javax.validation.constraints.Size;
+
+import org.jboss.test.faces.mock.Environment;
+import org.jboss.test.faces.mock.Environment.Feature;
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockController;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.jboss.test.faces.mock.MockTestRunner;
import org.junit.After;
import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.el.ValueDescriptor;
+import org.richfaces.el.ValueExpressionAnalayser;
+import org.richfaces.el.model.Bean;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+(a)RunWith(MockTestRunner.class)
public class BeanValidatorServiceConstrainsTest {
+
+ @Mock
+ @Environment(Feature.EL_CONTEXT)
+ private MockFacesEnvironment environment;
+
+ @Mock
+ private ValueExpression expression;
+
+ @Mock
+ private ValueExpressionAnalayser analayser;
+
+ private MockController controller;
+ private BeanValidatorServiceImpl validatorService;
+
+
@Before
public void setUp() throws Exception {
+ validatorService = new BeanValidatorServiceImpl(analayser);
}
@After
public void tearDown() throws Exception {
+ validatorService = null;
}
+
+ @Test
+ public void testGetSingleValidator() throws Exception {
+ forProperty(Bean.class, "string");expectValidatorWithParameter(Size.class,"max",2);
+ }
+
+ @Test
+ public void testGetNoValidator() throws Exception {
+ forProperty(Bean.class, "list");expectValidators();
+ }
+ private void forProperty(Class<?> beanClass,String property){
+ expect(analayser.getPropertyDescriptor(environment.getFacesContext(), expression)).andReturn(new ValueDescriptor(beanClass,property));
+ }
+
+ private void expectValidatorWithParameter(Class<? extends Annotation> validator,String param,Object value) {
+ Collection<ValidatorDescriptor> validators = expectValidators(validator);
+ ValidatorDescriptor validatorDescriptor = Iterables.getOnlyElement(validators);
+ assertTrue(validatorDescriptor.getAdditionalParameters().containsKey(param));
+ assertEquals(value, validatorDescriptor.getAdditionalParameters().get(param));
+ }
+ private Collection<ValidatorDescriptor> expectValidators(Class<? extends Annotation>... validators) {
+ controller.replay();
+ Collection<ValidatorDescriptor> constrains = validatorService.getConstrains(environment.getFacesContext(), expression);
+ controller.verify();
+ assertEquals(validators.length, constrains.size());
+ for (final Class<? extends Annotation> class1 : validators) {
+ Iterables.find(constrains, new Predicate<ValidatorDescriptor>(){
+ public boolean apply(ValidatorDescriptor input) {
+ return class1.equals(input.getImplementationClass());
+ }
+
+ });
+ }
+ return constrains;
+ }
}
13 years, 6 months
JBoss Rich Faces SVN: r19748 - in branches/RF-8742/ui/validator: api/src/main/java/org/richfaces/el and 10 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-10-28 16:31:56 -0400 (Thu, 28 Oct 2010)
New Revision: 19748
Added:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/CapturingELContext.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueReference.java
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ELTestBase.java
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/TestCaptureEL.java
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Bean.java
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Person.java
branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
Modified:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
Log:
CODING IN PROGRESS - issue RF-9510: BeanValidatorService tests and implementation
https://jira.jboss.org/browse/RF-9510
Added: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java (rev 0)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,111 @@
+/**
+ *
+ */
+package org.richfaces.el;
+
+/**
+ * This class describes bean property.
+ * @author asmirnov
+ *
+ */
+public class ValueDescriptor {
+
+ private final String name;
+
+ private final boolean readOnly;
+
+ private final Class<?> beanType;
+
+ private final Class<?> propertyType;
+
+ /**
+ * @param beanType
+ * @param name
+ * @param propertyType
+ * @param readOnly
+ */
+ ValueDescriptor(Class<?> beanType, String name, Class<?> propertyType, boolean readOnly) {
+ this.beanType = beanType;
+ this.name = name;
+ this.propertyType = propertyType;
+ this.readOnly = readOnly;
+ }
+
+ ValueDescriptor(Class<?> beanType, String name) {
+ this(beanType,name,Object.class,false);
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the readOnly
+ */
+ public boolean isReadOnly() {
+ return readOnly;
+ }
+
+ /**
+ * @return the beanType
+ */
+ public Class<?> getBeanType() {
+ return beanType;
+ }
+
+ /**
+ * @return the propertyType
+ */
+ public Class<?> getPropertyType() {
+ return propertyType;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((beanType == null) ? 0 : beanType.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ValueDescriptor other = (ValueDescriptor) obj;
+ if (beanType == null) {
+ if (other.beanType != null) {
+ return false;
+ }
+ } else if (!beanType.equals(other.beanType)) {
+ return false;
+ }
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ return true;
+ }
+
+
+}
Property changes on: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueDescriptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java (rev 0)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.richfaces.el;
+
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+/**
+ * Implementation of this interface extract information about bean property from EL-expression.
+ * @author asmirnov
+ *
+ */
+public interface ValueExpressionAnalayser {
+
+ ValueDescriptor getPropertyDescriptor(FacesContext context, ValueExpression expression);
+
+}
Property changes on: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/el/ValueExpressionAnalayser.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java
===================================================================
--- branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java 2010-10-28 19:11:02 UTC (rev 19747)
+++ branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -19,9 +19,9 @@
* @param expression
* @return
*/
- Collection<FacesObjectDescriptor> getConstrains(FacesContext context, ValueExpression expression,Class<?> ...groups);
+ Collection<ValidatorDescriptor> getConstrains(FacesContext context, ValueExpression expression,Class<?> ...groups);
- Collection<String> validateExpression(FacesContext context,ValueExpression expression, Object newValue,Class<?> ...groups);
+// Collection<String> validateExpression(FacesContext context,ValueExpression expression, Object newValue,Class<?> ...groups);
- Collection<String> validateObject(FacesContext context,Object object, Object newValue,Class<?> ...groups);
+// Collection<String> validateObject(FacesContext context,Object object, Object newValue,Class<?> ...groups);
}
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/CapturingELContext.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/CapturingELContext.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/CapturingELContext.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,141 @@
+/**
+ *
+ */
+package org.richfaces.el;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+import java.util.Locale;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.VariableMapper;
+
+/**
+ * This class wraps original ELContext and capture whole call stack to the target object so it could be used to extract
+ * semantic information like annotations or Jena Model properties.
+ *
+ * @author asmirnov
+ *
+ */
+public class CapturingELContext extends ELContext {
+
+ private final ELContext parent;
+
+ private ValueReference reference = null;
+
+ private final InterceptingResolver resolver;
+
+ public CapturingELContext(ELContext parent) {
+ this.parent = parent;
+ resolver = new InterceptingResolver(parent.getELResolver());
+ }
+
+ public ValueReference getReference() {
+ return reference;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ELContext#getELResolver()
+ */
+ @Override
+ public ELResolver getELResolver() {
+ return resolver;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object getContext(Class key) {
+ return parent.getContext(key);
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ return parent.getFunctionMapper();
+ }
+
+ @Override
+ public Locale getLocale() {
+ return parent.getLocale();
+ }
+
+ @Override
+ public VariableMapper getVariableMapper() {
+ return parent.getVariableMapper();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void putContext(Class key, Object contextObject) {
+ parent.putContext(key, contextObject);
+ }
+
+ @Override
+ public void setLocale(Locale locale) {
+ parent.setLocale(locale);
+ }
+
+ /**
+ * This resolver records all intermediate objects from the EL-expression that can be used to detect Semantic Beans
+ * annotations or Jena Model properties.
+ *
+ * @author asmirnov
+ *
+ */
+ private final class InterceptingResolver extends ELResolver {
+
+ private ELResolver delegate;
+
+ public InterceptingResolver(ELResolver delegate) {
+ this.delegate = delegate;
+ }
+
+ // Capture the base and property rather than write the value
+ @Override
+ public void setValue(ELContext context, Object base, Object property, Object value) {
+ if (base != null) {
+ context.setPropertyResolved(true);
+ reference = new ValueReference(base, property, reference);
+ }
+ }
+
+ // The rest of the methods simply delegate to the existing context
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property) {
+ // Null value for the base means new properties chain.
+ // TODO - record each chain to the separate collection for compound expressions.
+ reference = new ValueReference(base, property, reference);
+ return delegate.getValue(context, base, property);
+ }
+
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ if (base != null) {
+ context.setPropertyResolved(true);
+ reference = new ValueReference(base, property, reference);
+ }
+ return Object.class;
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ return delegate.isReadOnly(context, base, property);
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
+ return delegate.getFeatureDescriptors(context, base);
+ }
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ return delegate.getCommonPropertyType(context, base);
+ }
+
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/CapturingELContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,20 @@
+package org.richfaces.el;
+
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+public class ValueExpressionAnalayserImpl implements ValueExpressionAnalayser {
+
+ public ValueDescriptor getPropertyDescriptor(FacesContext context, ValueExpression expression) {
+ CapturingELContext capturingContext = new CapturingELContext(context.getELContext());
+ expression.getType(capturingContext);
+ ValueReference reference = capturingContext.getReference();
+ if(null != reference && null != reference.getBase() && null != reference.getProperty()){
+ // TODO - detect arrays, maps and lists. Check JSF implementation code - seems that Mojarra dosn't validate such fields.
+ ValueDescriptor descriptor = new ValueDescriptor(reference.getBase().getClass(),reference.getProperty().toString());
+ return descriptor;
+ }
+ return null;
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueExpressionAnalayserImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueReference.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueReference.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueReference.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package org.richfaces.el;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ValueReference {
+ private final Object base;
+ private final Object property;
+ private final ValueReference parent;
+
+ public ValueReference(Object base, Object property, ValueReference parent) {
+ this.base = base;
+ this.property = property;
+ this.parent = parent;
+ }
+
+ public Object getBase() {
+ return base;
+ }
+
+ public Object getProperty() {
+ return property;
+ }
+
+ public boolean hasNext() {
+ return null != parent;
+ }
+
+ public ValueReference next() {
+ return parent;
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/el/ValueReference.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ELTestBase.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ELTestBase.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ELTestBase.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,143 @@
+package org.richfaces.el;
+
+import java.beans.FeatureDescriptor;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.el.BeanELResolver;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.ListELResolver;
+import javax.el.MapELResolver;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+
+import org.jboss.el.ExpressionFactoryImpl;
+import org.junit.After;
+import org.junit.Before;
+import org.richfaces.el.model.Bean;
+import org.richfaces.el.model.Person;
+
+import com.google.common.collect.Iterators;
+
+public class ELTestBase {
+
+ class DummyELResolver extends ELResolver {
+
+ private final ELResolver beanResolver = new BeanELResolver();
+ private final ELResolver mapResolver = new MapELResolver();
+ private final ELResolver listResolver = new ListELResolver();
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ return String.class;
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
+ return Iterators.emptyIterator();
+ }
+
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ if (null == base) {
+ if ("bean".equals(property)) {
+ return Bean.class;
+ } else if ("person".equals(property)) {
+ return Person.class;
+ }
+ } else if (base instanceof List) {
+ return listResolver.getType(context, base, property);
+ } else if (base instanceof Map) {
+ return mapResolver.getType(context, base, property);
+ }
+ return beanResolver.getType(context, base, property);
+ }
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property) {
+ if (null == base) {
+ if ("bean".equals(property)) {
+ return bean;
+ } else if ("person".equals(property)) {
+ return person;
+ }
+ } else if (base instanceof List) {
+ return listResolver.getValue(context, base, property);
+ } else if (base instanceof Map) {
+ return mapResolver.getValue(context, base, property);
+ }
+ return beanResolver.getValue(context, base, property);
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ return true;
+ }
+
+ @Override
+ public void setValue(ELContext context, Object base, Object property, Object value) {
+ // do nothing
+
+ }
+
+ }
+
+ class DummyELContext extends ELContext {
+
+ @Override
+ public ELResolver getELResolver() {
+ return elResolver;
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ return null;
+ }
+
+ @Override
+ public VariableMapper getVariableMapper() {
+ return null;
+ }
+
+ }
+
+ protected ExpressionFactoryImpl expressionFactory;
+ protected Bean bean;
+ protected ELResolver elResolver;
+ protected ELContext elContext;
+ protected CapturingELContext capturingELContext;
+ protected Person person;
+
+ @Before
+ public void setUp() throws Exception {
+ expressionFactory = new ExpressionFactoryImpl();
+ bean = new Bean();
+ person = new Person();
+ bean.setString("foo");
+ ArrayList<String> list = new ArrayList<String>(1);
+ list.add("bar");
+ bean.setList(list);
+ HashMap<String, String> map = new HashMap<String, String>();
+ map.put("boo", "baz");
+ bean.setMap(map);
+ elResolver = new DummyELResolver();
+ elContext = new DummyELContext();
+ capturingELContext = new CapturingELContext(elContext);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ expressionFactory = null;
+ }
+
+ protected ValueExpression parse(String expressionString) {
+ ValueExpression expression = expressionFactory.createValueExpression(elContext, expressionString, String.class);
+ return expression;
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ELTestBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/TestCaptureEL.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/TestCaptureEL.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/TestCaptureEL.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,61 @@
+package org.richfaces.el;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import javax.el.ValueExpression;
+
+import org.jboss.test.faces.mock.MockTestRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+(a)RunWith(MockTestRunner.class)
+public class TestCaptureEL extends ELTestBase {
+
+ @Test
+ public void testDummyResolverString() throws Exception {
+ ValueExpression expression = parse("#{bean.string}");
+ assertEquals("foo", expression.getValue(elContext));
+ }
+
+ @Test
+ public void testDummyResolverList() throws Exception {
+ ValueExpression expression = parse("#{bean.list[0]}");
+ assertEquals("bar", expression.getValue(elContext));
+ }
+
+ @Test
+ public void testDummyResolverMap() throws Exception {
+ ValueExpression expression = parse("#{bean.map['boo']}");
+ assertEquals("baz", expression.getValue(elContext));
+ }
+
+ @Test
+ public void captureString() throws Exception {
+ ValueExpression expression = parse("#{bean.string}");
+ expression.getType(capturingELContext);
+ ValueReference reference = capturingELContext.getReference();
+ assertEquals("string", reference.getProperty());
+ assertSame(bean, reference.getBase());
+ reference = reference.next();
+ assertNotNull(reference);
+ assertEquals("bean", reference.getProperty());
+ assertNull(reference.getBase());
+ assertNull(reference.next());
+ }
+
+ @Test
+ public void captureMap() throws Exception {
+ ValueExpression expression = parse("#{bean.map['boo']}");
+ expression.getType(capturingELContext);
+ ValueReference reference = capturingELContext.getReference();
+ assertEquals("boo", reference.getProperty());
+ assertSame(bean.getMap(), reference.getBase());
+ reference = reference.next();
+ assertNotNull(reference);
+ assertEquals("map", reference.getProperty());
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/TestCaptureEL.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,17 @@
+package org.richfaces.el;
+
+
+import org.junit.After;
+import org.junit.Before;
+
+public class ValueExpressionAnalayserTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/ValueExpressionAnalayserTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Bean.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Bean.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Bean.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,39 @@
+package org.richfaces.el.model;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class Bean {
+
+ private List<String> list;
+
+ private Map<String, String> map = new HashMap<String, String>();
+
+ private String string;
+
+ public List<String> getList() {
+ return list;
+ }
+
+ public void setList(List<String> list) {
+ this.list = list;
+ }
+
+ public Map<String, String> getMap() {
+ return map;
+ }
+
+ public void setMap(Map<String, String> map) {
+ this.map = map;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public void setString(String string) {
+ this.string = string;
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Bean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Person.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Person.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Person.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,98 @@
+/**
+ *
+ */
+package org.richfaces.el.model;
+
+import java.net.URI;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class Person {
+
+ public static final String FOO_BAR = "http://foo.bar/baz#";
+
+ public static final String FOAF = "http://xmlns.com/foaf/0.1/";
+ private String id;
+
+ private Collection<URI> emailAddress;
+
+ private String name;
+
+ private String dummy;
+
+ private Double account;
+
+ private String string;
+
+ private String property;
+
+ private Map<Integer, Object> options;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public Collection<URI> getEmailAddress() {
+ return emailAddress;
+ }
+
+ public void setEmailAddress(Collection<URI> email) {
+ this.emailAddress = email;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Double getAccount() {
+ return account;
+ }
+
+ public void setAccount(Double account) {
+ this.account = account;
+ }
+
+ public String getDummy() {
+ return dummy;
+ }
+
+ public void setDummy(String dummy) {
+ this.dummy = dummy;
+ }
+
+ public void setString(String string) {
+ this.string = string;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setOptions(Map<Integer, Object> options) {
+ this.options = options;
+ }
+
+ public Map<Integer, Object> getOptions() {
+ return options;
+ }
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/el/model/Person.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
===================================================================
--- branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java (rev 0)
+++ branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -0,0 +1,17 @@
+package org.richfaces.validator;
+
+
+import org.junit.After;
+import org.junit.Before;
+
+public class BeanValidatorServiceConstrainsTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+}
Property changes on: branches/RF-8742/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java 2010-10-28 19:11:02 UTC (rev 19747)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -6,7 +6,7 @@
import javax.faces.component.behavior.ClientBehaviorContext;
import org.richfaces.validator.ConverterDescriptor;
-import org.richfaces.validator.FacesObjectDescriptor;
+import org.richfaces.validator.ValidatorDescriptor;
/**
* <p class="changed_added_4_0">Interface for JSF Behavior that creates scripts for client-side validation</p>
@@ -39,7 +39,7 @@
* @param context
* @return
*/
- Collection<FacesObjectDescriptor> getValidators(ClientBehaviorContext context);
+ Collection<ValidatorDescriptor> getValidators(ClientBehaviorContext context);
/**
* <p class="changed_added_4_0">Returns array of classes that represents JSR-303 validation groups.</p>
Modified: branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2010-10-28 19:11:02 UTC (rev 19747)
+++ branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -22,7 +22,6 @@
*/
package org.richfaces.component.behavior;
-import java.util.ArrayList;
import java.util.Collection;
import javax.el.ValueExpression;
@@ -48,7 +47,7 @@
import org.richfaces.validator.ConverterDescriptor;
import org.richfaces.validator.FacesConverterService;
import org.richfaces.validator.FacesValidatorService;
-import org.richfaces.validator.FacesObjectDescriptor;
+import org.richfaces.validator.ValidatorDescriptor;
import com.google.common.collect.Lists;
@@ -177,10 +176,10 @@
* @see org.richfaces.component.behavior.ClientValidatorBehavior#getValidators(javax.faces.component.behavior.
* ClientBehaviorContext)
*/
- public Collection<FacesObjectDescriptor> getValidators(ClientBehaviorContext context) {
+ public Collection<ValidatorDescriptor> getValidators(ClientBehaviorContext context) {
UIComponent component = context.getComponent();
if (component instanceof EditableValueHolder) {
- ArrayList<FacesObjectDescriptor> validators = Lists.newArrayList();
+ Collection<ValidatorDescriptor> validators = Lists.newArrayList();
EditableValueHolder input = (EditableValueHolder) component;
Validator[] facesValidators = input.getValidators();
FacesContext facesContext = context.getFacesContext();
Modified: branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java 2010-10-28 19:11:02 UTC (rev 19747)
+++ branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -22,7 +22,6 @@
import org.richfaces.application.ServiceTracker;
import org.richfaces.validator.BeanValidatorService;
import org.richfaces.validator.FacesValidatorService;
-import org.richfaces.validator.FacesObjectDescriptor;
import org.richfaces.validator.ValidatorDescriptor;
import com.google.common.collect.Iterables;
@@ -48,7 +47,7 @@
private Validator validator;
@Mock
- private FacesObjectDescriptor beanValidatorDescriptor;
+ private ValidatorDescriptor beanValidatorDescriptor;
@Mock
private BeanValidatorService validatorService;
@@ -89,14 +88,14 @@
controller.verify();
}
- private Collection<FacesObjectDescriptor> checkValidator() {
+ private Collection<ValidatorDescriptor> checkValidator() {
controller.replay();
- Collection<FacesObjectDescriptor> validators = behavior.getValidators(behaviorContext);
+ Collection<ValidatorDescriptor> validators = behavior.getValidators(behaviorContext);
// controller.verify();
return validators;
}
- private void setupBeanValidator(FacesObjectDescriptor... validators) {
+ private void setupBeanValidator(ValidatorDescriptor... validators) {
expect(validatorService.getConstrains(environment.getFacesContext(), expression, DEFAULT_GROUP)).andStubReturn(
Lists.newArrayList(validators));
@@ -124,9 +123,9 @@
public void testComponentValidator() throws Exception {
setupComponentValidator(validator);
setupBeanValidator();
- Collection<FacesObjectDescriptor> validators = checkValidator();
+ Collection<ValidatorDescriptor> validators = checkValidator();
assertEquals(1, validators.size());
- FacesObjectDescriptor validatorDescriptor = Iterables.getOnlyElement(validators);
+ ValidatorDescriptor validatorDescriptor = Iterables.getOnlyElement(validators);
assertSame(validator.getClass(), validatorDescriptor.getImplementationClass());
assertEquals(VALIDATION_ERROR, validatorDescriptor.getMessage());
controller.verify();
@@ -136,9 +135,9 @@
public void testBeanValidators() throws Exception {
setupComponentValidator();
setupBeanValidator(beanValidatorDescriptor);
- Collection<FacesObjectDescriptor> validators = checkValidator();
+ Collection<ValidatorDescriptor> validators = checkValidator();
assertEquals(1, validators.size());
- FacesObjectDescriptor validatorDescriptor = Iterables.getOnlyElement(validators);
+ ValidatorDescriptor validatorDescriptor = Iterables.getOnlyElement(validators);
assertSame(beanValidatorDescriptor, validatorDescriptor);
controller.verify();
}
Modified: branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
===================================================================
--- branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2010-10-28 19:11:02 UTC (rev 19747)
+++ branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2010-10-28 20:31:56 UTC (rev 19748)
@@ -28,11 +28,12 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.validator.ConverterDescriptor;
+import org.richfaces.validator.FacesObjectDescriptor;
+import org.richfaces.validator.LibraryFunction;
import org.richfaces.validator.LibraryResource;
-import org.richfaces.validator.LibraryFunction;
import org.richfaces.validator.LibraryScriptString;
import org.richfaces.validator.ScriptNotFoundException;
-import org.richfaces.validator.FacesObjectDescriptor;
+import org.richfaces.validator.ValidatorDescriptor;
import com.google.common.collect.Lists;
@@ -254,9 +255,9 @@
} else {
expect(mockBehavior.getConverter(behaviorContext)).andStubReturn(null);
}
- ArrayList<FacesObjectDescriptor> validatorDescriptors = new ArrayList<FacesObjectDescriptor>(validators.length);
+ Collection<ValidatorDescriptor> validatorDescriptors = new ArrayList<ValidatorDescriptor>(validators.length);
for (Class<?> validator : validators) {
- FacesObjectDescriptor validatorDescriptor = controller.createNiceMock(FacesObjectDescriptor.class);
+ ValidatorDescriptor validatorDescriptor = controller.createNiceMock(ValidatorDescriptor.class);
setupDescription(validator, validatorDescriptor);
validatorDescriptors.add(validatorDescriptor);
}
13 years, 6 months