Author: jbalunas(a)redhat.com
Date: 2011-02-27 13:30:19 -0500 (Sun, 27 Feb 2011)
New Revision: 21968
Added:
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/ListenerAttributes.java
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/autocomplete/
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/autocomplete/AutoCompleteBean.java
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/autocomplete/AutocompleteBeanConverter.java
branches/4.0.X/examples/input-demo/src/main/webapp/examples/autocompleteConverter.xhtml
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/SelectionChangeActionListenerImpl.java
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/ToggleActionListenerImpl.java
branches/4.0.X/ui/common/ui/src/main/java/org/richfaces/StateHolderArray.java
branches/4.0.X/ui/iteration/ui/src/main/resources/META-INF/cdk/attributes/tree-serverEventListeners-props.xml
branches/4.0.X/ui/iteration/ui/src/main/resources/META-INF/cdk/attributes/treeNode-serverEventListeners-props.xml
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageUpdateScript.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/view/facelets/html/GraphValidatorHandler.java
Removed:
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/AutoCompleteBean.java
Modified:
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/model/AttributeModel.java
branches/4.0.X/core/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java
branches/4.0.X/core/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java
branches/4.0.X/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java
branches/4.0.X/examples/iteration-demo/src/main/webapp/tree.xhtml
branches/4.0.X/examples/richfaces-showcase/src/main/java/org/richfaces/demo/common/navigation/DemoDescriptor.java
branches/4.0.X/examples/richfaces-showcase/src/main/java/org/richfaces/demo/common/navigation/GroupDescriptor.java
branches/4.0.X/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml
branches/4.0.X/examples/richfaces-showcase/src/main/webapp/richfaces/panelMenu/samples/panelMenu-sample.xhtml
branches/4.0.X/examples/richfaces-showcase/src/main/webapp/templates/includes/navigation.xhtml
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/view/facelets/AutocompleteHandler.java
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/view/facelets/FileUploadHandler.java
branches/4.0.X/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
branches/4.0.X/ui/input/ui/src/main/templates/autocomplete.template.xml
branches/4.0.X/ui/input/ui/src/test/resources/org/richfaces/renderkit/autocompleteDivLayoutClientMode.xmlunit.xml
branches/4.0.X/ui/input/ui/src/test/resources/org/richfaces/renderkit/autocompleteListLayoutClientMode.xmlunit.xml
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractCollapsibleSubTable.java
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataGrid.java
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataGridRenderer.java
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractAccordion.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractCollapsiblePanel.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanel.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenu.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuItem.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractTabPanel.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/CollapsiblePanelRenderer.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabPanelRenderer.java
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenu.js
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuGroup.js
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuItem.js
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptNotFoundException.java
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/FacesConverterService.java
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/FacesValidatorService.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/ConverterServiceImpl.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java
branches/4.0.X/ui/validator/ui/src/main/resources/META-INF/csv.xml
branches/4.0.X/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetConverterTest.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/validator/FacesConverterServiceTest.java
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/validator/FacesValidatorServiceTest.java
Log:
Merge from 4.0.0.CR1 branch to 4.0.X branch
Added:
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/ListenerAttributes.java
===================================================================
---
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/ListenerAttributes.java
(rev 0)
+++
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/ListenerAttributes.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,28 @@
+package org.richfaces.cdk.generate.taglib;
+
+import org.richfaces.cdk.model.AttributeModel;
+import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.PropertyBase;
+
+import javax.el.ValueExpression;
+
+/**
+ * User: Gleb Galkin
+ * Date: 23.02.11
+ */
+public enum ListenerAttributes {
+ FOR(new AttributeModel("for", false, ClassName.get(String.class))),
+ BINDING(new AttributeModel("binding", false,
ClassName.get(ValueExpression.class))),
+ LISTENER(new AttributeModel("listener", false,
ClassName.get(ValueExpression.class))),
+ TYPE(new AttributeModel("type", false,
ClassName.get(ValueExpression.class)));
+
+ private PropertyBase attribute;
+
+ ListenerAttributes(PropertyBase attribute) {
+ this.attribute = attribute;
+ }
+
+ public PropertyBase getAttribute() {
+ return attribute;
+ }
+}
Modified:
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
===================================================================
---
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -26,19 +26,7 @@
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.richfaces.cdk.annotations.TagType;
-import org.richfaces.cdk.model.BeanModelBase;
-import org.richfaces.cdk.model.BehaviorModel;
-import org.richfaces.cdk.model.ComponentLibrary;
-import org.richfaces.cdk.model.ComponentModel;
-import org.richfaces.cdk.model.ConverterModel;
-import org.richfaces.cdk.model.DescriptionGroup;
-import org.richfaces.cdk.model.EventModel;
-import org.richfaces.cdk.model.FacesId;
-import org.richfaces.cdk.model.FunctionModel;
-import org.richfaces.cdk.model.PropertyBase;
-import org.richfaces.cdk.model.SimpleVisitor;
-import org.richfaces.cdk.model.TagModel;
-import org.richfaces.cdk.model.ValidatorModel;
+import org.richfaces.cdk.model.*;
import org.richfaces.cdk.util.Strings;
/**
@@ -262,11 +250,18 @@
if (isFaceletsTag(tagModel)) {
Element tag = createTag(tagModel.getName());
addTagHandler(tag, tagModel);
+ appendAttributesForListener(tag);
}
}
return null;
}
+ private void appendAttributesForListener(Element tag) {
+ for (ListenerAttributes attribute : ListenerAttributes.values()) {
+ createAttributeElement(tag, attribute.getAttribute().getName(),
attribute.getAttribute());
+ }
+ }
+
private boolean isFaceletsTag(TagType type) {
return TagType.Facelets.equals(type) || TagType.All.equals(type);
@@ -281,7 +276,7 @@
* Add common description elements.
* </p>
*
- * @param parant
+ * @param parent
* @param model
*/
private void addDescription(Element parent, DescriptionGroup model) {
Modified:
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/model/AttributeModel.java
===================================================================
---
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/model/AttributeModel.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/cdk/generator/src/main/java/org/richfaces/cdk/model/AttributeModel.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -32,4 +32,15 @@
*/
public class AttributeModel extends PropertyBase {
+ public AttributeModel() {
+ super();
+ }
+
+ public AttributeModel(String name, boolean required, ClassName type) {
+ super();
+ setName(name);
+ setRequired(required);
+ setType(type);
+ }
+
}
Modified: branches/4.0.X/core/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java
===================================================================
---
branches/4.0.X/core/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/core/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -35,6 +35,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.MissingResourceException;
+import java.util.SimpleTimeZone;
import javax.faces.FacesException;
import javax.faces.context.ResponseWriter;
@@ -173,7 +174,7 @@
throw new FacesException("Error in conversion Java Object to
JavaScript", e);
}
- boolean ignorePropertyReadException =
obj.getClass().getName().startsWith("java.sql.");
+ boolean ignorePropertyReadException =
obj.getClass().getName().startsWith("java.sql.") ||
obj.getClass().equals(SimpleTimeZone.class);
boolean first = true;
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
Modified:
branches/4.0.X/core/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java
===================================================================
---
branches/4.0.X/core/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/core/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -27,6 +27,7 @@
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.isNull;
+import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -36,6 +37,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TimeZone;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -47,6 +49,7 @@
import org.easymock.CaptureType;
import org.jboss.test.faces.mock.MockFacesEnvironment;
import org.junit.Test;
+import org.junit.internal.matchers.StringContains;
/**
* @author shura
@@ -472,4 +475,27 @@
assertEquals("test\\#",
ScriptUtils.escapeCSSMetachars("test#"));
assertEquals("test\\#\\=",
ScriptUtils.escapeCSSMetachars("test#="));
}
+
+ @Test
+ public void testTimezoneSerialization() throws Exception {
+ TimeZone utcPlusTwoTZ = TimeZone.getTimeZone("GMT+02:00");
+
+ String serializedUTCPlusTwoTZ = dehydrate(ScriptUtils.toScript(utcPlusTwoTZ));
+
+ assertThat(serializedUTCPlusTwoTZ,
StringContains.containsString("\"DSTSavings\":0"));
+ assertThat(serializedUTCPlusTwoTZ,
StringContains.containsString("\"ID\":\"GMT+02:00\""));
+ assertThat(serializedUTCPlusTwoTZ,
StringContains.containsString("\"rawOffset\":7200000"));
+
+ TimeZone pstTimeZone = TimeZone.getTimeZone("PST");
+ String serializedPSTTimeZone = dehydrate(ScriptUtils.toScript(pstTimeZone));
+
+ assertThat(serializedPSTTimeZone,
StringContains.containsString("\"ID\":\"PST\""));
+ assertThat(serializedPSTTimeZone,
StringContains.containsString("\"rawOffset\":-28800000"));
+
+ TimeZone sfTimeZone = TimeZone.getTimeZone("America/New_York");
+ String serializedSFTimeZone = dehydrate(ScriptUtils.toScript(sfTimeZone));
+
+ assertThat(serializedSFTimeZone,
StringContains.containsString("\"ID\":\"America\\/New_York\""));
+ assertThat(serializedSFTimeZone,
StringContains.containsString("\"rawOffset\":-18000000"));
+ }
}
Deleted:
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/AutoCompleteBean.java
===================================================================
---
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/AutoCompleteBean.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/AutoCompleteBean.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -1,110 +0,0 @@
-/*
- * 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.demo;
-
-import java.io.Serializable;
-import java.util.Locale;
-
-import javax.faces.bean.ManagedBean;
-import javax.faces.bean.ManagedProperty;
-import javax.faces.bean.SessionScoped;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-import org.richfaces.component.AutocompleteMode;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-
-/**
- * @author Nick Belaevski
- *
- */
-@ManagedBean
-@SessionScoped
-public class AutoCompleteBean implements Serializable {
-
- private static final long serialVersionUID = 3072125097847582809L;
-
- private class CountryNamePredicate implements Predicate<Country> {
-
- private String countryNamePrefix;
-
- public CountryNamePredicate(String countryNamePrefix) {
- super();
- this.countryNamePrefix = countryNamePrefix;
- }
-
- public boolean apply(Country input) {
- if (countryNamePrefix == null || countryNamePrefix.length() == 0) {
- return true;
- }
-
- return input.getName().toLowerCase(Locale.US).startsWith(countryNamePrefix);
- }
- }
-
- private String value;
-
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
-
- private AutocompleteMode mode = AutocompleteMode.lazyClient;
-
- public AutocompleteMode getMode() {
- return mode;
- }
-
- public void setMode(AutocompleteMode mode) {
- this.mode = mode;
- }
-
- @ManagedProperty(value = "#{countriesBean}")
- private CountriesBean countriesBean;
-
- public void setCountriesBean(CountriesBean countriesBean) {
- this.countriesBean = countriesBean;
- }
-
- public Object autocomplete(FacesContext facesContext, UIComponent component, String
value) {
- // for tests when value does not starts with prefix
- /*String str = value;
- if (str.charAt(0)=='i') {
- str = str.substring(1);
- }*/
-
- AutocompleteMode mode = (AutocompleteMode)
component.getAttributes().get("mode");
- boolean isClient = mode == AutocompleteMode.client || mode ==
AutocompleteMode.lazyClient;
- String v = isClient ? "" : value;
- return Collections2.filter(countriesBean.getCountries(), new
CountryNamePredicate(v.toLowerCase(Locale.US)));
- }
-
- public Object getModes() {
- return AutocompleteMode.values();
- }
-}
Added:
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/autocomplete/AutoCompleteBean.java
===================================================================
---
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/autocomplete/AutoCompleteBean.java
(rev 0)
+++
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/autocomplete/AutoCompleteBean.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,105 @@
+/*
+ * 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.demo.autocomplete;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import org.richfaces.component.AutocompleteMode;
+import org.richfaces.demo.CountriesBean;
+import org.richfaces.demo.Country;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.ManagedProperty;
+import javax.faces.bean.SessionScoped;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.io.Serializable;
+import java.util.Locale;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@ManagedBean
+@SessionScoped
+public class AutoCompleteBean implements Serializable {
+
+ private static final long serialVersionUID = 3072125097847582809L;
+
+ private class CountryNamePredicate implements Predicate<Country> {
+
+ private String countryNamePrefix;
+
+ public CountryNamePredicate(String countryNamePrefix) {
+ super();
+ this.countryNamePrefix = countryNamePrefix;
+ }
+
+ public boolean apply(Country input) {
+ if (countryNamePrefix == null || countryNamePrefix.length() == 0) {
+ return true;
+ }
+
+ return input.getName().toLowerCase(Locale.US).startsWith(countryNamePrefix);
+ }
+ }
+
+ private Object value;
+
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ private AutocompleteMode mode = AutocompleteMode.lazyClient;
+
+ public AutocompleteMode getMode() {
+ return mode;
+ }
+
+ public void setMode(AutocompleteMode mode) {
+ this.mode = mode;
+ }
+
+ @ManagedProperty(value = "#{countriesBean}")
+ private CountriesBean countriesBean;
+
+ public void setCountriesBean(CountriesBean countriesBean) {
+ this.countriesBean = countriesBean;
+ }
+
+ public Object autocomplete(FacesContext facesContext, UIComponent component, String
value) {
+ AutocompleteMode mode = (AutocompleteMode)
component.getAttributes().get("mode");
+ boolean isClient = mode == AutocompleteMode.client || mode ==
AutocompleteMode.lazyClient;
+ String v = isClient || value ==null ? "" : value;
+
+ return Collections2.filter(countriesBean.getCountries(), new
CountryNamePredicate(v.toLowerCase(Locale.US)));
+ }
+
+ public Object getModes() {
+ return AutocompleteMode.values();
+ }
+}
Added:
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/autocomplete/AutocompleteBeanConverter.java
===================================================================
---
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/autocomplete/AutocompleteBeanConverter.java
(rev 0)
+++
branches/4.0.X/examples/input-demo/src/main/java/org/richfaces/demo/autocomplete/AutocompleteBeanConverter.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,47 @@
+package org.richfaces.demo.autocomplete;
+
+import org.richfaces.demo.CountriesBean;
+import org.richfaces.demo.Country;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.FacesConverter;
+import java.io.Serializable;
+
+@FacesConverter(value = "autocompleteBeanConverter")
+public class AutocompleteBeanConverter implements Converter, Serializable {
+
+ public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String
value) {
+ System.out.println("AutocompleteBeanConverter#getAsObject is called");
+ if (value == null || value.equals("")) {
+ return null;
+ } else {
+ CountriesBean countriesBean = (CountriesBean)
FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("countriesBean");
+ for (Country country : countriesBean.getCountries()) {
+ if (country.getName().equals(value)) {
+ return country;
+ }
+ }
+
+ return null;
+ }
+ }
+
+ public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object
value) {
+ System.out.println("AutocompleteBeanConverter#getAsString is called");
+ if (value != null) {
+ Country bean;
+ try {
+ bean = (Country) value;
+ return bean.getName();
+ } catch (ClassCastException e) {
+ System.out.println("Cannot cast " + value + "to
Country");
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
Modified: branches/4.0.X/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml
===================================================================
---
branches/4.0.X/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml 2011-02-27
18:30:19 UTC (rev 21968)
@@ -1,183 +1,294 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:ui="http://java.sun.com/jsf/facelets"
-
xmlns:input="http://richfaces.org/input"
-
xmlns:output="http://richfaces.org/output"
-
xmlns:rich="http://richfaces.org/iteration"
-
xmlns:misc="http://richfaces.org/misc"
-
xmlns:a4j="http://richfaces.org/a4j">
-<f:view contentType="text/html" />
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:input="http://richfaces.org/input"
+
xmlns:output="http://richfaces.org/output"
+
xmlns:rich="http://richfaces.org/iteration"
+
xmlns:misc="http://richfaces.org/misc"
+
xmlns:a4j="http://richfaces.org/a4j">
+<f:view contentType="text/html"/>
<h:head>
- <title>Richfaces Autocomplete</title>
+ <title>Richfaces Autocomplete</title>
</h:head>
<h:body style="margin: 30px;">
<ui:composition template="/templates/template.xhtml">
- <ui:define name="title">Autocomplete Example</ui:define>
- <ui:define name="body_head">Autocomplete Example</ui:define>
+<ui:define name="title">Autocomplete Example</ui:define>
+<ui:define name="body_head">Autocomplete Example</ui:define>
- <ui:define name="body">
-
- <style type="text/css">
- .myPopupClass .rf-au-lst-scrl {
- border: 1px solid red;
- width: 400px;
- }
- </style>
+<ui:define name="body">
+<style type="text/css">
+ .myPopupClass .rf-au-lst-scrl {
+ border: 1px solid red;
+ width: 400px;
+ }
+</style>
- <h:form id="form">
- <h:selectOneMenu value="#{autoCompleteBean.mode}"
onchange="submit()">
- <f:selectItems value="#{autoCompleteBean.modes}" />
- </h:selectOneMenu><br/>
- <div style="height: 300px; width: 300px; overflow: auto;
float:left;">Text
- block text block text block text block text block text block text
- block text block
- <script type="text/javascript">
- function customFilterFunction(subString, value) {
- if(subString.length>1)
- if(value.indexOf(subString)!=-1) return true;
- }
- </script>
+<h:form id="form">
+ <h:selectOneMenu value="#{autoCompleteBean.mode}"
onchange="submit()">
+ <f:selectItems value="#{autoCompleteBean.modes}"/>
+ </h:selectOneMenu><br/>
- <input:autocomplete popupClass="myPopupClass" autofill="false"
id="myAutocomplete" clientFilterFunction="customFilterFunction"
mode="#{autoCompleteBean.mode}" minChars="2"
autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country"
fetchValue="#{country.name}" showButton="true"
- value = "#{autoCompleteBean.value}" layout="list"
- onchange="return onEvent.call(this, event);" onselectitem="return
onEvent.call(this, event);" onblur="return onEvent.call(this, event);"
onfocus="return onEvent.call(this, event);">
- #{country.name} #{country.iso} #{country.domain}
- <a4j:ajax event="change" render="output"/>
- </input:autocomplete>
- <br /><h:outputText value="RF-9835:" /><br />
- <input:autocomplete id="myAutocomplete1" mode="client"
autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country"
fetchValue="#{country.name}" showButton="true"
- value = "#{autoCompleteBean.value}" layout="table">
- <rich:column>
- <h:outputText value="#{country.name}" />
- </rich:column>
- <rich:column>
- <h:outputText value="#{country.iso}" />
- </rich:column>
- <rich:column>
- <h:outputText value="#{country.domain}" />
- </rich:column>
- <a4j:ajax event="change" render="output"/>
- </input:autocomplete>
- <br/><br/>
- Your selection: <h:outputText id="output"
value="#{autoCompleteBean.value}"/>
- <script type="text/javascript">
- onEvent = function(event, element, data){
- RichFaces.log.info("jQuery Event: "+(event instanceof jQuery.Event)+";
event: "+event.type+"; data:"+(data ||
(event['rich']||{})['data'])+"; this.id:"+this.id+";
component:"+
(event['rich']||{})['component']||RichFaces.$(this.id));
- };
- RichFaces.Event.bindById("form:myAutocomplete", "selectitem change blur
focus", onEvent);
- </script>
- <br />
- <select style="width: 200px" name="select">
- <option>option 0</option><option>option
1</option><option>option 2</option><option>option
3</option><option>option 4</option><option>option
5</option><option>option 6</option><option>option
7</option><option>option 8</option><option>option
9</option><option>option 10</option><option>option
11</option><option>option 12</option><option>option
13</option><option>option 14</option><option>option
15</option><option>option 16</option><option>option
17</option><option>option 18</option><option>option
19</option><option>option 20</option><option>option
21</option><option>option 22</option><option>option
23</option><option>option 24</option><option>option
25</option><option>option 26</option><option>option
27</option><option>option 28</option><option>option
29</option><option>option 30</option><option>option
31</option><option>option 32</option><option>option
33</option><option>option 34</option><option>option
35</option><option>option 36</option><option>option
37</option><option!
option 38</option><option>option
39</option><option>option 40</option><option>option
41</option><option>option 42</option><option>option
43</option><option>option 44</option><option>option
45</option><option>option 46</option><option>option
47</option><option>option 48</option><option>option
49</option><option>option 50</option><option>option
51</option><option>option 52</option><option>option
53</option><option>option 54</option><option>option
55</option><option>option 56</option><option>option
57</option><option>option 58</option><option>option
59</option><option>option 60</option><option>option
61</option><option>option 62</option><option>option
63</option><option>option 64</option><option>option
65</option><option>option 66</option><option>option
67</option><option>option 68</option><option>option
69</option><option>option 70</option><option>option
71</option><option>option 72</option><option>option
73</option><option>option 74</option><option>option
75</option><option!
option 76</option><option>option 77</option><option>option 78!
</option
<option>option 79</option><option>option
80</option><option>option 81</option><option>option
82</option><option>option 83</option><option>option
84</option><option>option 85</option><option>option
86</option><option>option 87</option><option>option
88</option><option>option 89</option><option>option
90</option><option>option 91</option><option>option
92</option><option>option 93</option><option>option
94</option><option>option 95</option><option>option
96</option><option>option 97</option><option>option
98</option><option>option 99</option>
- </select>
text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block text block text block text block text
- block text block text block
- </div>
- <div>
- <a4j:log mode="inline"></a4j:log>
- </div>
- </h:form>
- <h:form>
- RF-9567:<br/><br/>
- <a4j:outputPanel ajaxRendered="true"><h:messages
/></a4j:outputPanel>
-
-
- <input:autocomplete mode="ajax" id="autocomplete"
autocompleteMethod="#{autoCompleteBean.autocomplete}"
value="#{autoCompleteBean.value}">
- <f:validateRegex pattern="Alabama" />
- </input:autocomplete>
+ <div style="height: 300px; width: 300px; overflow: auto;
float:left;">Text
+ block text block text block text block text block text block text
+ block text block
+ <script type="text/javascript">
+ function customFilterFunction(subString, value) {
+ if (subString.length > 1)
+ if (value.indexOf(subString) != -1) return true;
+ }
+ </script>
- <a4j:commandButton render="@form" execute="autocomplete" />
- </h:form>
- <h:form>
- <input:autocomplete mode="cachedAjax" tokens=","
minChars="0"
-autofill="true" selectFirst="false" layout="table"
-autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country"
fetchValue="#{country.name}">
-<h:column>
-#{country.name}
-</h:column>
-<h:column>
-#{country.iso}
-</h:column>
-</input:autocomplete>
+ <input:autocomplete popupClass="myPopupClass"
autofill="false" id="myAutocomplete"
+ clientFilterFunction="customFilterFunction"
mode="#{autoCompleteBean.mode}"
+ minChars="2"
autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country"
+ fetchValue="#{country.name}"
showButton="true"
+ value="#{autoCompleteBean.value}"
layout="list"
+ onchange="return onEvent.call(this, event);"
+ onselectitem="return onEvent.call(this, event);"
+ onblur="return onEvent.call(this, event);"
+ onfocus="return onEvent.call(this, event);">
+ #{country.name} #{country.iso} #{country.domain}
+ <a4j:ajax event="change" render="output"/>
+ </input:autocomplete>
+ <br/><h:outputText value="RF-9835:"/><br/>
+ <input:autocomplete id="myAutocomplete1" mode="client"
+
autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country"
+ fetchValue="#{country.name}"
showButton="true"
+ value="#{autoCompleteBean.value}"
layout="table">
+ <rich:column>
+ <h:outputText value="#{country.name}"/>
+ </rich:column>
+ <rich:column>
+ <h:outputText value="#{country.iso}"/>
+ </rich:column>
+ <rich:column>
+ <h:outputText value="#{country.domain}"/>
+ </rich:column>
+ <a4j:ajax event="change" render="output"/>
+ </input:autocomplete>
+ <br/><br/>
+ Your selection: <h:outputText id="output"
value="#{autoCompleteBean.value}"/>
+ <script type="text/javascript">
+ onEvent = function(event, element, data) {
+ RichFaces.log.info("jQuery Event: " + (event instanceof
jQuery.Event) + "; event: " + event.type + "; data:" + (data ||
(event['rich'] || {})['data']) + "; this.id:" + this.id +
"; component:" + (event['rich'] || {})['component'] ||
RichFaces.$(this.id));
+ };
+ RichFaces.Event.bindById("form:myAutocomplete", "selectitem
change blur focus", onEvent);
+ </script>
+ <br/>
+ <select style="width: 200px" name="select">
+ <option>option 0</option>
+ <option>option 1</option>
+ <option>option 2</option>
+ <option>option 3</option>
+ <option>option 4</option>
+ <option>option 5</option>
+ <option>option 6</option>
+ <option>option 7</option>
+ <option>option 8</option>
+ <option>option 9</option>
+ <option>option 10</option>
+ <option>option 11</option>
+ <option>option 12</option>
+ <option>option 13</option>
+ <option>option 14</option>
+ <option>option 15</option>
+ <option>option 16</option>
+ <option>option 17</option>
+ <option>option 18</option>
+ <option>option 19</option>
+ <option>option 20</option>
+ <option>option 21</option>
+ <option>option 22</option>
+ <option>option 23</option>
+ <option>option 24</option>
+ <option>option 25</option>
+ <option>option 26</option>
+ <option>option 27</option>
+ <option>option 28</option>
+ <option>option 29</option>
+ <option>option 30</option>
+ <option>option 31</option>
+ <option>option 32</option>
+ <option>option 33</option>
+ <option>option 34</option>
+ <option>option 35</option>
+ <option>option 36</option>
+ <option>option 37</option>
+ <option>option 38</option>
+ <option>option 39</option>
+ <option>option 40</option>
+ <option>option 41</option>
+ <option>option 42</option>
+ <option>option 43</option>
+ <option>option 44</option>
+ <option>option 45</option>
+ <option>option 46</option>
+ <option>option 47</option>
+ <option>option 48</option>
+ <option>option 49</option>
+ <option>option 50</option>
+ <option>option 51</option>
+ <option>option 52</option>
+ <option>option 53</option>
+ <option>option 54</option>
+ <option>option 55</option>
+ <option>option 56</option>
+ <option>option 57</option>
+ <option>option 58</option>
+ <option>option 59</option>
+ <option>option 60</option>
+ <option>option 61</option>
+ <option>option 62</option>
+ <option>option 63</option>
+ <option>option 64</option>
+ <option>option 65</option>
+ <option>option 66</option>
+ <option>option 67</option>
+ <option>option 68</option>
+ <option>option 69</option>
+ <option>option 70</option>
+ <option>option 71</option>
+ <option>option 72</option>
+ <option>option 73</option>
+ <option>option 74</option>
+ <option>option 75</option>
+ <option>option 76</option>
+ <option>option 77</option>
+ <option>option 78</option>
+ <option>option 79</option>
+ <option>option 80</option>
+ <option>option 81</option>
+ <option>option 82</option>
+ <option>option 83</option>
+ <option>option 84</option>
+ <option>option 85</option>
+ <option>option 86</option>
+ <option>option 87</option>
+ <option>option 88</option>
+ <option>option 89</option>
+ <option>option 90</option>
+ <option>option 91</option>
+ <option>option 92</option>
+ <option>option 93</option>
+ <option>option 94</option>
+ <option>option 95</option>
+ <option>option 96</option>
+ <option>option 97</option>
+ <option>option 98</option>
+ <option>option 99</option>
+ </select> text block text block text block text block text block
text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block text block text block text block text
+ block text block text block
+ </div>
+ <div>
+ <a4j:log mode="inline"></a4j:log>
+ </div>
</h:form>
- <h:form>
- <h:commandButton id="leggTilKontroll" value="Button">
- <misc:componentControl target="popup" operation="show" />
- </h:commandButton>
- </h:form>
- <output:popupPanel id="popup" autosized="true">
- <h:form>
- <input:autocomplete mode="cachedAjax"
autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country"
fetchValue="#{country.name}">
- #{country.name} #{country.iso} #{country.domain}
- </input:autocomplete>
- <input:select id="select" enableManualInput="true"
defaultLabel="Select Value ...">
- <f:selectItem itemLabel="Label#1" itemValue="Value#1"/>
- <f:selectItem itemLabel="Label#2" itemValue="Value#2"/>
- <f:selectItem itemLabel="Label#3" itemValue="Value#3"/>
- <f:selectItem itemLabel="Label#4" itemValue="Value#4"/>
- <f:selectItem itemLabel="Label#5" itemValue="Value#5"/>
- <f:selectItem itemLabel="Label#6" itemValue="Value#6"/>
- <f:selectItem itemLabel="Label#7" itemValue="Value#7"/>
- <f:selectItem itemLabel="Label#8" itemValue="Value#8"/>
- <f:selectItem itemLabel="Label#9" itemValue="Value#9"/>
- <f:selectItem itemLabel="Label#10" itemValue="Value#10"/>
- <f:selectItem itemLabel="Label#11" itemValue="Value#11"/>
- <f:selectItem itemLabel="Label#12" itemValue="Value#12"/>
- <f:selectItem itemLabel="Label#13" itemValue="Value#13"/>
- <f:selectItem itemLabel="Label#14" itemValue="Value#14"/>
- </input:select>
- <input:inplaceSelect defaultLabel="Edit Text"
openOnEdit="true" saveOnSelect="false">
- <f:selectItem itemLabel="Label#1" itemValue="Value#1"/>
- <f:selectItem itemLabel="Label#2" itemValue="Value#2"/>
- <f:selectItem itemLabel="Label#3" itemValue="Value#3"/>
- <f:selectItem itemLabel="Label#4" itemValue="Value#4"/>
- <f:selectItem itemLabel="Label#5" itemValue="Value#5"/>
- <f:selectItem itemLabel="Label#6" itemValue="Value#6"/>
- <f:selectItem itemLabel="Label#7" itemValue="Value#7"/>
- <f:selectItem itemLabel="Label#8" itemValue="Value#8"/>
- <f:selectItem itemLabel="Label#9" itemValue="Value#9"/>
- <f:selectItem itemLabel="Label#10" itemValue="Value#10"/>
- <f:selectItem itemLabel="Label#11" itemValue="Value#11"/>
- <f:selectItem itemLabel="Label#12" itemValue="Value#12"/>
- <f:selectItem itemLabel="Label#13" itemValue="Value#13"/>
- <f:selectItem itemLabel="Label#14" itemValue="Value#14"/>
- </input:inplaceSelect>
- </h:form>
- </output:popupPanel>
- </ui:define>
+<h:form>
+ RF-9567:<br/><br/>
+ <a4j:outputPanel
ajaxRendered="true"><h:messages/></a4j:outputPanel>
+
+
+ <input:autocomplete mode="ajax" id="autocomplete"
autocompleteMethod="#{autoCompleteBean.autocomplete}"
+ value="#{autoCompleteBean.value}">
+ <f:validateRegex pattern="Alabama"/>
+ </input:autocomplete>
+
+ <a4j:commandButton render="@form" execute="autocomplete"/>
+</h:form>
+<h:form>
+ <input:autocomplete mode="cachedAjax" tokens=","
minChars="0"
+ autofill="true" selectFirst="false"
layout="table"
+ autocompleteMethod="#{autoCompleteBean.autocomplete}"
var="country"
+ fetchValue="#{country.name}">
+ <h:column>
+ #{country.name}
+ </h:column>
+ <h:column>
+ #{country.iso}
+ </h:column>
+ </input:autocomplete>
+</h:form>
+<h:form>
+ <h:commandButton id="leggTilKontroll" value="Button">
+ <misc:componentControl target="popup"
operation="show"/>
+ </h:commandButton>
+</h:form>
+<output:popupPanel id="popup" autosized="true">
+ <h:form>
+ <input:autocomplete mode="cachedAjax"
autocompleteMethod="#{autoCompleteBean.autocomplete}"
+ var="country"
fetchValue="#{country.name}">
+ #{country.name} #{country.iso} #{country.domain}
+ </input:autocomplete>
+ <input:select id="select" enableManualInput="true"
defaultLabel="Select Value ...">
+ <f:selectItem itemLabel="Label#1"
itemValue="Value#1"/>
+ <f:selectItem itemLabel="Label#2"
itemValue="Value#2"/>
+ <f:selectItem itemLabel="Label#3"
itemValue="Value#3"/>
+ <f:selectItem itemLabel="Label#4"
itemValue="Value#4"/>
+ <f:selectItem itemLabel="Label#5"
itemValue="Value#5"/>
+ <f:selectItem itemLabel="Label#6"
itemValue="Value#6"/>
+ <f:selectItem itemLabel="Label#7"
itemValue="Value#7"/>
+ <f:selectItem itemLabel="Label#8"
itemValue="Value#8"/>
+ <f:selectItem itemLabel="Label#9"
itemValue="Value#9"/>
+ <f:selectItem itemLabel="Label#10"
itemValue="Value#10"/>
+ <f:selectItem itemLabel="Label#11"
itemValue="Value#11"/>
+ <f:selectItem itemLabel="Label#12"
itemValue="Value#12"/>
+ <f:selectItem itemLabel="Label#13"
itemValue="Value#13"/>
+ <f:selectItem itemLabel="Label#14"
itemValue="Value#14"/>
+ </input:select>
+ <input:inplaceSelect defaultLabel="Edit Text"
openOnEdit="true" saveOnSelect="false">
+ <f:selectItem itemLabel="Label#1"
itemValue="Value#1"/>
+ <f:selectItem itemLabel="Label#2"
itemValue="Value#2"/>
+ <f:selectItem itemLabel="Label#3"
itemValue="Value#3"/>
+ <f:selectItem itemLabel="Label#4"
itemValue="Value#4"/>
+ <f:selectItem itemLabel="Label#5"
itemValue="Value#5"/>
+ <f:selectItem itemLabel="Label#6"
itemValue="Value#6"/>
+ <f:selectItem itemLabel="Label#7"
itemValue="Value#7"/>
+ <f:selectItem itemLabel="Label#8"
itemValue="Value#8"/>
+ <f:selectItem itemLabel="Label#9"
itemValue="Value#9"/>
+ <f:selectItem itemLabel="Label#10"
itemValue="Value#10"/>
+ <f:selectItem itemLabel="Label#11"
itemValue="Value#11"/>
+ <f:selectItem itemLabel="Label#12"
itemValue="Value#12"/>
+ <f:selectItem itemLabel="Label#13"
itemValue="Value#13"/>
+ <f:selectItem itemLabel="Label#14"
itemValue="Value#14"/>
+ </input:inplaceSelect>
+ </h:form>
+</output:popupPanel>
+</ui:define>
</ui:composition>
-
+
</h:body>
</html>
Added:
branches/4.0.X/examples/input-demo/src/main/webapp/examples/autocompleteConverter.xhtml
===================================================================
---
branches/4.0.X/examples/input-demo/src/main/webapp/examples/autocompleteConverter.xhtml
(rev 0)
+++
branches/4.0.X/examples/input-demo/src/main/webapp/examples/autocompleteConverter.xhtml 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,37 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:input="http://richfaces.org/input">
+<f:view contentType="text/html"/>
+
+<h:head>
+ <title>Richfaces Autocomplete</title>
+</h:head>
+
+<h:body style="margin: 30px;">
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="title">Autocomplete Converter
Example</ui:define>
+ <ui:define name="body_head">Autocomplete Converter
Example</ui:define>
+
+ <ui:define name="body">
+ <h:form>
+ <h:outputLabel for="autocompleteConverter">Autocomplete
with converter:</h:outputLabel>
+ <input:autocomplete
autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country"
+ fetchValue="#{country.name}"
+ mode="ajax" layout="list"
+ converter="autocompleteBeanConverter"
value="#{autoCompleteBean.value}"
+ id="autocompleteConverter">
+ #{country.name}
+ </input:autocomplete>
+ <h:commandButton value="Submit Country"/>
+ </h:form>
+ </ui:define>
+ </ui:composition>
+
+</h:body>
+</html>
Added:
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/SelectionChangeActionListenerImpl.java
===================================================================
---
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/SelectionChangeActionListenerImpl.java
(rev 0)
+++
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/SelectionChangeActionListenerImpl.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,17 @@
+package org.richfaces.demo;
+
+import org.richfaces.event.TreeSelectionChangeEvent;
+import org.richfaces.event.TreeSelectionChangeListener;
+
+import javax.faces.event.AbortProcessingException;
+
+/**
+ * User: Gleb Galkin
+ * Date: 23.02.11
+ */
+public class SelectionChangeActionListenerImpl implements TreeSelectionChangeListener {
+
+ public void processSelectionChange(TreeSelectionChangeEvent event) throws
AbortProcessingException {
+ System.out.println("Inside Selection Change Action");
+ }
+}
Added:
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/ToggleActionListenerImpl.java
===================================================================
---
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/ToggleActionListenerImpl.java
(rev 0)
+++
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/ToggleActionListenerImpl.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,14 @@
+package org.richfaces.demo;
+
+import org.richfaces.event.TreeToggleEvent;
+
+/**
+ * User: Gleb Galkin
+ * Date: 23.02.11
+ */
+public class ToggleActionListenerImpl {
+
+ public void processToggleAction(TreeToggleEvent event) {
+ System.out.println("Inside Toggle Action: " + (event.isCollapsed() ?
"collapsed tree" : "expanded tree"));
+ }
+}
Modified:
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java
===================================================================
---
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -21,13 +21,17 @@
*/
package org.richfaces.demo;
-import java.io.Serializable;
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
+import org.richfaces.component.AbstractTree;
+import org.richfaces.component.AbstractTreeNode;
+import org.richfaces.component.SwitchType;
+import org.richfaces.event.TreeSelectionChangeEvent;
+import org.richfaces.event.TreeSelectionChangeListener;
+import org.richfaces.event.TreeToggleEvent;
+import org.richfaces.event.TreeToggleListener;
+import org.richfaces.log.LogFactory;
+import org.richfaces.log.Logger;
+
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
@@ -37,17 +41,13 @@
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.event.FacesEvent;
import javax.swing.tree.TreeNode;
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
-import org.richfaces.component.AbstractTree;
-import org.richfaces.component.AbstractTreeNode;
-import org.richfaces.component.SwitchType;
-import org.richfaces.event.TreeSelectionChangeEvent;
-import org.richfaces.event.TreeSelectionChangeListener;
-import org.richfaces.event.TreeToggleEvent;
-import org.richfaces.event.TreeToggleListener;
-import org.richfaces.log.LogFactory;
-import org.richfaces.log.Logger;
-
/**
* @author Nick Belaevski
*
@@ -114,7 +114,10 @@
private String toggleNodeEvent = "";
private String executeTestText;
-
+
+ private ToggleActionListenerImpl toggleActionListenerImpl = new
ToggleActionListenerImpl();
+ private SelectionChangeActionListenerImpl selectionChangeActionListener;
+
private static Object staticGetNodeData() {
FacesContext facesContext = FacesContext.getCurrentInstance();
return facesContext.getApplication().evaluateExpressionGet(facesContext,
"#{node}", Object.class);
@@ -245,4 +248,20 @@
public String getCurrentTimeAsString() {
return DateFormat.getTimeInstance().format(new Date());
}
+
+ public ToggleActionListenerImpl getToggleActionListenerImpl() {
+ return toggleActionListenerImpl;
+ }
+
+ public void setToggleActionListenerImpl(ToggleActionListenerImpl
toggleActionListenerImpl) {
+ this.toggleActionListenerImpl = toggleActionListenerImpl;
+ }
+
+ public SelectionChangeActionListenerImpl getSelectionChangeActionListener() {
+ return selectionChangeActionListener;
+ }
+
+ public void setSelectionChangeActionListener(SelectionChangeActionListenerImpl
selectionChangeActionListener) {
+ this.selectionChangeActionListener = selectionChangeActionListener;
+ }
}
Modified: branches/4.0.X/examples/iteration-demo/src/main/webapp/tree.xhtml
===================================================================
--- branches/4.0.X/examples/iteration-demo/src/main/webapp/tree.xhtml 2011-02-27 15:05:18
UTC (rev 21967)
+++ branches/4.0.X/examples/iteration-demo/src/main/webapp/tree.xhtml 2011-02-27 18:30:19
UTC (rev 21968)
@@ -107,10 +107,14 @@
<h:form id="form">
Base tree:
- <it:tree id="tree" nodeType="#{node.parent == null ?
'rootNode': 'childNode'}" var="node"
value="#{treeBean.rootNodes}"
+ <it:tree id="tree" nodeType="#{node.parent == null ?
'rootNode': 'childNode'}" var="node"
value="#{treeBean.rootNodes}"
selectionType="#{treeBean.selectionType}"
toggleType="#{treeBean.toggleType}"
selection="#{treeBean.selection}">
- <it:treeNode type="rootNode">
- <h:panelGroup id="rootNodeGroup">
+
+ <it:treeToggleListener
listener="#{treeBean.toggleActionListenerImpl.processToggleAction}" />
+ <it:treeSelectionChangeListener
binding="#{treeBean.selectionChangeActionListener}"
type="org.richfaces.demo.SelectionChangeActionListenerImpl" />
+
+ <it:treeNode type="rootNode">
+ <h:panelGroup id="rootNodeGroup">
Root node: #{node.data} -
<h:commandLink value="link"
action="#{treeBean.clickNode}">
<f:ajax render=":messages" />
Modified:
branches/4.0.X/examples/richfaces-showcase/src/main/java/org/richfaces/demo/common/navigation/DemoDescriptor.java
===================================================================
---
branches/4.0.X/examples/richfaces-showcase/src/main/java/org/richfaces/demo/common/navigation/DemoDescriptor.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/examples/richfaces-showcase/src/main/java/org/richfaces/demo/common/navigation/DemoDescriptor.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -10,9 +10,22 @@
private static final long serialVersionUID = 6822187362271025752L;
private static final String BASE_SAMPLES_DIR = "/richfaces/";
-
+
private List<SampleDescriptor> samples;
+ private boolean containsNewSamples() {
+ for (SampleDescriptor sample : samples) {
+ if (sample.isNewItem()){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean isNewItems() {
+ return (isNewItem() || containsNewSamples());
+ }
+
public SampleDescriptor getSampleById(String id) {
for (SampleDescriptor sample : getSamples()) {
if (sample.getId().equals(id)) {
Modified:
branches/4.0.X/examples/richfaces-showcase/src/main/java/org/richfaces/demo/common/navigation/GroupDescriptor.java
===================================================================
---
branches/4.0.X/examples/richfaces-showcase/src/main/java/org/richfaces/demo/common/navigation/GroupDescriptor.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/examples/richfaces-showcase/src/main/java/org/richfaces/demo/common/navigation/GroupDescriptor.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -11,6 +11,19 @@
private List<DemoDescriptor> demos;
+ private boolean containsNewDemos() {
+ for (DemoDescriptor demo : demos) {
+ if (demo.isNewItems()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean isNewItems() {
+ return isNewItem() || containsNewDemos();
+ }
+
@XmlElementWrapper(name = "demos")
@XmlElement(name = "demo")
public List<DemoDescriptor> getDemos() {
Modified:
branches/4.0.X/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml
===================================================================
---
branches/4.0.X/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml 2011-02-27
18:30:19 UTC (rev 21968)
@@ -172,10 +172,10 @@
</demo>
</demos>
</group>
- <group>
+ <group new="true">
<name>Validation</name>
<demos>
- <demo new="true">
+ <demo>
<id>clientValidation</id>
<name>Client Side Validation</name>
<samples>
@@ -189,7 +189,7 @@
</sample>
</samples>
</demo>
- <demo new="true">
+ <demo>
<id>graphValidator</id>
<name>rich:graphValidator</name>
<samples>
@@ -199,7 +199,7 @@
</sample>
</samples>
</demo>
- <demo new="true">
+ <demo>
<id>message</id>
<name>rich:message</name>
<samples>
@@ -209,7 +209,7 @@
</sample>
</samples>
</demo>
- <demo new="true">
+ <demo>
<id>messages</id>
<name>rich:messages</name>
<samples>
@@ -464,7 +464,7 @@
<group>
<name>Menus</name>
<demos>
- <demo new="true">
+ <demo>
<id>panelMenu</id>
<name>rich:panelMenu</name>
<samples>
@@ -474,7 +474,7 @@
</sample>
</samples>
</demo>
- <demo new="true">
+ <demo>
<id>toolBar</id>
<name>rich:toolBar</name>
<samples>
@@ -488,7 +488,7 @@
</sample>
</samples>
</demo>
- <demo new="true">
+ <demo>
<id>dropDownMenu</id>
<name>rich:dropDownMenu</name>
<samples>
@@ -521,19 +521,19 @@
</sample>
</samples>
</demo>
- <demo new="true">
+ <demo>
<id>calendar</id>
<name>rich:calendar</name>
<samples>
- <sample new="true">
+ <sample>
<id>calendar</id>
<name>Simple Calendar</name>
</sample>
- <sample new="true">
+ <sample>
<id>clientStylingDisablement</id>
<name>Client Side Styling/Disablement</name>
</sample>
- <sample new="true">
+ <sample>
<id>dataModel</id>
<name>Data Model Support</name>
</sample>
@@ -589,7 +589,7 @@
</sample>
</samples>
</demo>
- <demo new="true">
+ <demo>
<id>fileUpload</id>
<name>rich:fileUpload</name>
<samples>
@@ -605,7 +605,7 @@
<name>Drag and Drop</name>
<demos>
<demo new="true">
- <id>dragDrop</id>
+ <id>dragDrop</id>
<name>Drag and Drop</name>
<samples>
<sample>
Modified:
branches/4.0.X/examples/richfaces-showcase/src/main/webapp/richfaces/panelMenu/samples/panelMenu-sample.xhtml
===================================================================
---
branches/4.0.X/examples/richfaces-showcase/src/main/webapp/richfaces/panelMenu/samples/panelMenu-sample.xhtml 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/examples/richfaces-showcase/src/main/webapp/richfaces/panelMenu/samples/panelMenu-sample.xhtml 2011-02-27
18:30:19 UTC (rev 21968)
@@ -12,7 +12,7 @@
</style>
<h:form id="form">
<h:panelGrid columns="2" columnClasses="cols,cols"
width="400">
- <rich:panelMenu style="width:200px" mode="ajax"
groupMode="ajax"
+ <rich:panelMenu style="width:200px" itemMode="ajax"
groupMode="ajax"
groupExpandedLeftIcon="triangleUp"
groupCollapsedLeftIcon="triangleDown"
topGroupExpandedRightIcon="chevronUp"
Modified:
branches/4.0.X/examples/richfaces-showcase/src/main/webapp/templates/includes/navigation.xhtml
===================================================================
---
branches/4.0.X/examples/richfaces-showcase/src/main/webapp/templates/includes/navigation.xhtml 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/examples/richfaces-showcase/src/main/webapp/templates/includes/navigation.xhtml 2011-02-27
18:30:19 UTC (rev 21968)
@@ -7,10 +7,13 @@
xmlns:c="http://java.sun.com/jsp/jstl/core">
<rich:panelMenu activeItem="#{demoNavigator.currentDemo.id}">
<c:forEach items="#{demoNavigator.groups}" var="gr">
- <rich:panelMenuGroup label="#{gr.name}">
+ <rich:panelMenuGroup label="#{gr.name}"
+ rightExpandedIcon="#{gr.newItems ? '/images/icons/new-ic.gif' :
null}"
+ rightCollapsedIcon="#{gr.newItems ? '/images/icons/new-ic.gif' :
null}">
<c:forEach items="#{gr.demos}" var="d">
- <rich:panelMenuItem label="#{d.name}" action="#{d.id}"
rightIcon="none"
+ <rich:panelMenuItem label="#{d.name}" action="#{d.id}"
mode="client" name="#{d.id}"
+ rightIcon="#{(d.newItems || gr.newItem) ?
'/images/icons/new-small-ic.gif' : null}"
onclick="document.location='#{facesContext.externalContext.requestContextPath}/richfaces/component-sample.jsf?demo=#{d.id}&skin=#{skinBean.skin}'">
</rich:panelMenuItem>
</c:forEach>
Added: branches/4.0.X/ui/common/ui/src/main/java/org/richfaces/StateHolderArray.java
===================================================================
--- branches/4.0.X/ui/common/ui/src/main/java/org/richfaces/StateHolderArray.java
(rev 0)
+++
branches/4.0.X/ui/common/ui/src/main/java/org/richfaces/StateHolderArray.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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;
+
+import java.util.ArrayList;
+
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class StateHolderArray implements StateHolder {
+
+ private boolean tranzient = false;
+
+ private ArrayList<Object> backingList = Lists.newArrayListWithCapacity(2);
+
+ public Object saveState(FacesContext context) {
+ Object[] savedState = new Object[backingList.size()];
+
+ boolean hasNonNullState = false;
+
+ for (int i = 0; i < savedState.length; i++) {
+ Object state = UIComponentBase.saveAttachedState(context,
backingList.get(i));
+ savedState[i] = state;
+
+ if (state != null) {
+ hasNonNullState = true;
+ }
+ }
+
+ if (hasNonNullState) {
+ return savedState;
+ } else {
+ return null;
+ }
+ }
+
+ public void restoreState(FacesContext context, Object stateObject) {
+ if (stateObject != null) {
+ Object[] state = (Object[]) stateObject;
+
+ backingList.ensureCapacity(state.length);
+
+ for (int i = 0; i < state.length; i++) {
+ backingList.add(UIComponentBase.restoreAttachedState(context,
state[i]));
+ }
+ }
+ }
+
+ public boolean isTransient() {
+ return tranzient;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ this.tranzient = newTransientValue;
+ }
+
+ public boolean add(Object e) {
+ return backingList.add(e);
+ }
+
+ public Object get(int index) {
+ return backingList.get(index);
+ }
+
+ public boolean isEmpty() {
+ return backingList.isEmpty();
+ }
+
+}
Modified:
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java
===================================================================
---
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractAutocomplete.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -21,7 +21,10 @@
*/
package org.richfaces.component;
-import java.io.IOException;
+import org.richfaces.cdk.annotations.*;
+import org.richfaces.context.ExtendedVisitContext;
+import org.richfaces.context.ExtendedVisitContextMode;
+import org.richfaces.renderkit.MetaComponentRenderer;
import javax.el.MethodExpression;
import javax.faces.component.UIComponent;
@@ -30,19 +33,8 @@
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
+import java.io.IOException;
-import org.richfaces.cdk.annotations.Attribute;
-import org.richfaces.cdk.annotations.EventName;
-import org.richfaces.cdk.annotations.JsfComponent;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.cdk.annotations.Signature;
-import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.cdk.annotations.TagType;
-import org.richfaces.context.ExtendedVisitContext;
-import org.richfaces.context.ExtendedVisitContextMode;
-import org.richfaces.renderkit.MetaComponentRenderer;
-
/**
* @author Nick Belaevski
*
@@ -65,8 +57,6 @@
public abstract void setAutocompleteMethod(MethodExpression expression);
- public abstract void setItemConverter(Converter converter);
-
@Attribute(literal = true)
public abstract String getVar();
@@ -85,6 +75,9 @@
@Attribute()
public abstract String getPopupClass();
+
+ @Attribute()
+ public abstract String getInputClass();
@Attribute
public abstract AutocompleteMode getMode();
@@ -95,9 +88,6 @@
@Attribute
public abstract String getTokens();
- @Attribute
- public abstract Converter getItemConverter();
-
@Attribute(defaultValue = "true")
public abstract boolean isAutofill();
Modified:
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
===================================================================
---
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -275,7 +275,7 @@
@Attribute(events = @EventName("inputblur"))
public abstract String getOninputblur();
- @Attribute(events = @EventName("change"))
+ @Attribute(events = @EventName(value="change", defaultEvent=true))
public abstract String getOnchange();
@Attribute(events = @EventName("dateselect"))
Modified:
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
===================================================================
---
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -44,12 +44,16 @@
* @author Konstantin Mishin
*
*/
-@JsfComponent(tag = @Tag(handler =
"org.richfaces.view.facelets.FileUploadHandler"),
+@JsfComponent(tag = @Tag(generate = false, handler =
"org.richfaces.view.facelets.FileUploadHandler"),
renderer = @JsfRenderer(type = "org.richfaces.FileUploadRenderer"),
attributes = {"events-props.xml", "core-props.xml",
"ajax-props.xml", "i18n-props.xml",
"fileUploadListener-props.xml"})
@ListenerFor(systemEventClass = PostAddToViewEvent.class)
public abstract class AbstractFileUpload extends UIComponentBase {
+ public static final String COMPONENT_TYPE = "org.richfaces.FileUpload";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.FileUpload";
+
@Attribute
public abstract String getAcceptedTypes();
Modified:
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java
===================================================================
---
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -10,8 +10,8 @@
*
*/
@JsfComponent(
- type = AbstractSelectComponent.COMPONENT_TYPE,
- family = AbstractSelectComponent.COMPONENT_FAMILY,
+ type = AbstractSelect.COMPONENT_TYPE,
+ family = AbstractSelect.COMPONENT_FAMILY,
generate = "org.richfaces.component.UISelect",
renderer = @JsfRenderer(type = "org.richfaces.SelectRenderer"),
tag = @Tag(name="select")
Modified:
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
===================================================================
---
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -21,34 +21,6 @@
*/
package org.richfaces.renderkit;
-import java.io.IOException;
-import java.sql.ResultSet;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.el.ELException;
-import javax.el.ExpressionFactory;
-import javax.el.MethodExpression;
-import javax.el.MethodNotFoundException;
-import javax.el.ValueExpression;
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.PartialResponseWriter;
-import javax.faces.context.PartialViewContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
-import javax.faces.model.ArrayDataModel;
-import javax.faces.model.DataModel;
-import javax.faces.model.ListDataModel;
-import javax.faces.model.ResultDataModel;
-import javax.faces.model.ResultSetDataModel;
-import javax.servlet.jsp.jstl.sql.Result;
-
import org.ajax4jsf.javascript.JSObject;
import org.ajax4jsf.javascript.JSReference;
import org.richfaces.application.ServiceTracker;
@@ -62,6 +34,26 @@
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
+import javax.el.*;
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.component.ValueHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.context.PartialResponseWriter;
+import javax.faces.context.PartialViewContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.model.*;
+import javax.servlet.jsp.jstl.sql.Result;
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
/**
* @author Nick Belaevski
*/
@@ -159,42 +151,33 @@
}
}
- protected void encodeItems(FacesContext facesContext, UIComponent component,
List<Object> fetchValues)
- throws IOException {
+ protected void encodeItems(FacesContext facesContext, UIComponent component,
List<Object> fetchValues) throws IOException {
AbstractAutocomplete comboBox = (AbstractAutocomplete) component;
AutocompleteEncodeStrategy strategy = getStrategy(component);
strategy.encodeItemsContainerBegin(facesContext, component);
- boolean hasEncodedElements = false;
-
Object savedVar = saveVar(facesContext, comboBox.getVar());
- DataModel<Object> model = getItems(facesContext, comboBox);
- for (Iterator<Object> items = model.iterator(); items.hasNext();) {
- hasEncodedElements = true;
+ Iterator<Object> itemsIterator = getItems(facesContext,
comboBox).iterator();
- Object nextItem = items.next();
- setVar(facesContext, comboBox.getVar(), nextItem);
+ if (!itemsIterator.hasNext()) {
+ strategy.encodeFakeItem(facesContext, component);
+ } else {
+ while (itemsIterator.hasNext()) {
+ Object item = itemsIterator.next();
- this.encodeItem(facesContext, comboBox, nextItem, strategy);
- if (comboBox.getFetchValue() != null) {
- fetchValues.add(comboBox.getFetchValue().toString());
- } else {
- // TODO use converter
- if (comboBox.getItemConverter() != null) {
- fetchValues.add(comboBox.getItemConverter().getAsString(facesContext,
component, nextItem));
- } else {
- fetchValues.add(nextItem.toString());
- }
+ setVar(facesContext, comboBox.getVar(), item);
+ this.encodeItem(facesContext, comboBox, item, strategy);
+ if (comboBox.getFetchValue() != null) {
+ fetchValues.add(comboBox.getFetchValue().toString());
+ } else if(item != null) {
+ fetchValues.add(item.toString());
+ }
}
}
setVar(facesContext, comboBox.getVar(), savedVar);
- if (!hasEncodedElements) {
- strategy.encodeFakeItem(facesContext, component);
- }
-
strategy.encodeItemsContainerEnd(facesContext, component);
}
@@ -226,26 +209,17 @@
public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox,
Object item,
AutocompleteEncodeStrategy strategy) throws IOException {
- ResponseWriter writer = facesContext.getResponseWriter();
+ ResponseWriter writer = facesContext.getResponseWriter();
if (comboBox.getChildCount() > 0) {
strategy.encodeItem(facesContext, comboBox);
} else {
if (item != null) {
- strategy.encodeItemBegin(facesContext, comboBox);
- writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-itm
rf-au-opt rf-au-fnt rf-au-inp", null);
- // TODO nick - use converter
- String value = null;
- if (comboBox.getItemConverter() != null) {
- value = comboBox.getItemConverter().getAsString(facesContext,
comboBox, item);
- }
- if (value != null) {
- writer.writeText(value, null);
- }
+ strategy.encodeItemBegin(facesContext, comboBox);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-itm
rf-au-opt rf-au-fnt rf-au-inp", null);
writer.writeText(item, null);
strategy.encodeItemEnd(facesContext, comboBox);
}
}
-
}
private AutocompleteEncodeStrategy getStrategy(UIComponent component) {
@@ -271,7 +245,7 @@
return;
}
Map<String, String> requestParameters =
context.getExternalContext().getRequestParameterMap();
- String value = requestParameters.get(component.getClientId(context) +
"Value");
+ String value = requestParameters.get(component.getClientId(context) +
"Input");
if (value != null) {
autocomplete.setSubmittedValue(value);
}
@@ -320,17 +294,18 @@
}
return value;
}
-
+
private Converter getConverterForValue(FacesContext context, UIComponent component)
{
- Converter converter = null;
- ValueExpression expression = component.getValueExpression("value");
+ Converter converter = ((ValueHolder) component).getConverter();
+ if (converter == null) {
+ ValueExpression expression =
component.getValueExpression("value");
- if (expression != null) {
- Class<?> containerClass = ServiceTracker.getService(context,
GenericsIntrospectionService.class).getContainerClass(context, expression);
+ if (expression != null) {
+ Class<?> containerClass = ServiceTracker.getService(context,
GenericsIntrospectionService.class).getContainerClass(context, expression);
- converter = InputUtils.getConverterForType(context, containerClass);
+ converter = InputUtils.getConverterForType(context, containerClass);
+ }
}
-
return converter;
}
Modified:
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/view/facelets/AutocompleteHandler.java
===================================================================
---
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/view/facelets/AutocompleteHandler.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/view/facelets/AutocompleteHandler.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -21,21 +21,14 @@
*/
package org.richfaces.view.facelets;
+import org.richfaces.component.AbstractAutocomplete;
+
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
-import javax.faces.view.facelets.ComponentConfig;
-import javax.faces.view.facelets.ComponentHandler;
-import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.MetaRule;
-import javax.faces.view.facelets.MetaRuleset;
-import javax.faces.view.facelets.Metadata;
-import javax.faces.view.facelets.MetadataTarget;
-import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.*;
-import org.richfaces.component.AbstractAutocomplete;
-
/**
* @author Nick Belaevski
*/
@@ -66,17 +59,6 @@
}
};
}
-
- if ("itemConverter".equals(name)) {
- return new ConverterMetadata(attribute) {
- public void applyMetadata(FaceletContext ctx, Object instance) {
- ((AbstractAutocomplete)
instance).setItemConverter(this.getConverter(ctx,
- (AbstractAutocomplete) instance,
- this.getAttr().getValueExpression(ctx,
Converter.class)));
- }
- };
- }
-
}
return null;
Modified:
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/view/facelets/FileUploadHandler.java
===================================================================
---
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/view/facelets/FileUploadHandler.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/input/ui/src/main/java/org/richfaces/view/facelets/FileUploadHandler.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -22,6 +22,7 @@
package org.richfaces.view.facelets;
import javax.el.MethodExpression;
+import javax.faces.event.AbortProcessingException;
import javax.faces.view.facelets.ComponentConfig;
import javax.faces.view.facelets.ComponentHandler;
import javax.faces.view.facelets.FaceletContext;
@@ -32,8 +33,9 @@
import javax.faces.view.facelets.TagAttribute;
import org.richfaces.component.AbstractFileUpload;
+import org.richfaces.event.FileUploadEvent;
import org.richfaces.event.FileUploadListener;
-import org.richfaces.event.FileUploadEvent;
+import org.richfaces.event.MethodExpressionEventListener;
/**
* @author Konstantin Mishin
@@ -41,6 +43,21 @@
*/
public class FileUploadHandler extends ComponentHandler {
+ public static final class FileUploadListenerImpl extends
MethodExpressionEventListener implements FileUploadListener {
+
+ public FileUploadListenerImpl() {
+ super();
+ }
+
+ public FileUploadListenerImpl(MethodExpression expression) {
+ super(expression);
+ }
+
+ public void processUpload(FileUploadEvent event) throws AbortProcessingException
{
+ processEvent(event);
+ }
+ }
+
public FileUploadHandler(ComponentConfig config) {
super(config);
}
@@ -58,11 +75,7 @@
@Override
public void applyMetadata(final FaceletContext ctx, Object
instance) {
final MethodExpression expression =
getMethodExpression(ctx);
- ((AbstractFileUpload) instance).addFileUploadListener(new
FileUploadListener(){
- public void processUpload(FileUploadEvent event) {
-
expression.invoke(ctx.getFacesContext().getELContext(), new Object[] {event});
- }
- });
+ ((AbstractFileUpload) instance).addFileUploadListener(new
FileUploadListenerImpl(expression));
}
};
}
Modified:
branches/4.0.X/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
===================================================================
---
branches/4.0.X/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js 2011-02-27
18:30:19 UTC (rev 21968)
@@ -164,7 +164,8 @@
var originalEncoding = this.form.attr("encoding");
var originalEnctype = this.form.attr("enctype");
try {
- this.form.attr("action", originalAction + "?" + UID +
"=" + this.loadableItem.uid);
+ var delimiter = originalAction.indexOf("?") == -1 ? "?" :
"&";
+ this.form.attr("action", originalAction + delimiter + UID +
"=" + this.loadableItem.uid);
this.form.attr("encoding", "multipart/form-data");
this.form.attr("enctype", "multipart/form-data");
richfaces.submitForm(this.form, {"org.richfaces.ajax.component":
this.id}, this.id);
Modified: branches/4.0.X/ui/input/ui/src/main/templates/autocomplete.template.xml
===================================================================
--- branches/4.0.X/ui/input/ui/src/main/templates/autocomplete.template.xml 2011-02-27
15:05:18 UTC (rev 21967)
+++ branches/4.0.X/ui/input/ui/src/main/templates/autocomplete.template.xml 2011-02-27
18:30:19 UTC (rev 21968)
@@ -17,7 +17,7 @@
<cc:implementation>
<cdk:object type="java.lang.Object" name="disabled"
value="#{component.attributes['disabled']}" />
- <div id="#{clientId}" class="rf-au-fld">
+ <span id="#{clientId}" class="rf-au-fld">
<input id="#{clientId}Value" name="#{clientId}Value"
type="hidden"/>
<span class="#{component.attributes['showButton'] ?
'rf-au-fld-btn' : ''}">
<input onclick="#{component.attributes['onclick']}"
@@ -29,7 +29,12 @@
onmouseout="#{component.attributes['onmouseout']}"
onkeyup="#{component.attributes['onkeyup']}"
onkeydown="#{component.attributes['onkeydown']}"
- onkeypress="#{component.attributes['onkeypress']}"
id="#{clientId}Input" value="#{component.attributes['value']}"
disabled="#{disabled}" name="#{clientId}Input" type="text"
class="rf-au-fnt rf-au-inp" autocomplete="off"/>
+ onkeypress="#{component.attributes['onkeypress']}"
+ id="#{clientId}Input" value="#{getInputValue(facesContext,
component)}"
+ disabled="#{disabled}" name="#{clientId}Input"
+ type="text"
+ class="rf-au-fnt rf-au-inp #{component.attributes['inputClass']}"
+ autocomplete="off"/>
<c:if
test="#{component.attributes['showButton']}">
<span id="#{clientId}Button"
class="rf-au-btn">
<span
class="rf-au-btn-arrow#{component.attributes['disabled'] ? '-dis' :
''}"></span>
@@ -82,7 +87,7 @@
);
</script>
</c:if>
- </div>
+ </span>
</cc:implementation>
</cdk:root>
Modified:
branches/4.0.X/ui/input/ui/src/test/resources/org/richfaces/renderkit/autocompleteDivLayoutClientMode.xmlunit.xml
===================================================================
---
branches/4.0.X/ui/input/ui/src/test/resources/org/richfaces/renderkit/autocompleteDivLayoutClientMode.xmlunit.xml 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/input/ui/src/test/resources/org/richfaces/renderkit/autocompleteDivLayoutClientMode.xmlunit.xml 2011-02-27
18:30:19 UTC (rev 21968)
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
- <div class="rf-au-fld" id="form:myAutocomplete">
+ <span class="rf-au-fld" id="form:myAutocomplete">
<input id="form:myAutocompleteValue"
name="form:myAutocompleteValue" type="hidden"/>
<span class="rf-au-fld-btn">
<input autocomplete="off" class="rf-au-fnt rf-au-inp"
id="form:myAutocompleteInput" name="form:myAutocomplete"
type="text"/>
@@ -188,4 +188,4 @@
);
//]]>
</script>
- </div>
+ </span>
Modified:
branches/4.0.X/ui/input/ui/src/test/resources/org/richfaces/renderkit/autocompleteListLayoutClientMode.xmlunit.xml
===================================================================
---
branches/4.0.X/ui/input/ui/src/test/resources/org/richfaces/renderkit/autocompleteListLayoutClientMode.xmlunit.xml 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/input/ui/src/test/resources/org/richfaces/renderkit/autocompleteListLayoutClientMode.xmlunit.xml 2011-02-27
18:30:19 UTC (rev 21968)
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<div class="rf-au-fld" id="form:myAutocomplete">
+<span class="rf-au-fld" id="form:myAutocomplete">
<input id="form:myAutocompleteValue"
name="form:myAutocompleteValue" type="hidden"/>
<span class="rf-au-fld-btn">
<input autocomplete="off" class="rf-au-fnt rf-au-inp"
id="form:myAutocompleteInput" name="form:myAutocomplete"
type="text"/>
@@ -188,4 +188,4 @@
);
//]]>
</script>
-</div>
\ No newline at end of file
+</span>
\ No newline at end of file
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractCollapsibleSubTable.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractCollapsibleSubTable.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractCollapsibleSubTable.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -28,6 +28,7 @@
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
+import org.richfaces.StateHolderArray;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
@@ -141,10 +142,11 @@
}
public void setIterationState(Object stateObject) {
- Object[] state = (Object[]) stateObject;
- if (state != null) {
- super.setIterationState(state[0]);
- getStateHelper().put(PropertyKeys.expanded, state[1]);
+ StateHolderArray stateHolderList = (StateHolderArray) stateObject;
+
+ if (stateHolderList != null && !stateHolderList.isEmpty()) {
+ super.setIterationState(stateHolderList.get(0));
+ getStateHelper().put(PropertyKeys.expanded, (Boolean)
stateHolderList.get(1));
} else {
super.setIterationState(null);
getStateHelper().put(PropertyKeys.expanded, null);
@@ -152,9 +154,11 @@
}
public Object getIterationState() {
- Object [] state = new Object[2];
- state[0] = super.getIterationState();
- state[1] = getStateHelper().get(PropertyKeys.expanded);
- return state;
+ StateHolderArray holderList = new StateHolderArray();
+
+ holderList.add(super.getIterationState());
+ holderList.add(getStateHelper().get(PropertyKeys.expanded));
+
+ return holderList;
}
}
\ No newline at end of file
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataGrid.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataGrid.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataGrid.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -58,7 +58,7 @@
generate = "org.richfaces.component.UIDataGrid",
renderer = @JsfRenderer(type = "org.richfaces.DataGridRenderer"),
tag = @Tag(name="dataGrid",
handler="org.richfaces.taglib.DataGridHandler", type=TagType.Facelets),
- attributes = {"dataGrid-rows-props.xml",
"rowKeyConverter-prop.xml"}
+ attributes = {"core-props.xml", "dataGrid-rows-props.xml",
"rowKeyConverter-prop.xml"}
)
public abstract class AbstractDataGrid extends UISequence implements Row,
MetaComponentResolver, MetaComponentEncoder {
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -30,7 +30,6 @@
import javax.el.ELContext;
import javax.el.ELException;
-import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
@@ -57,7 +56,6 @@
import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.cdk.annotations.Signature;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.component.util.MessageUtil;
import org.richfaces.context.ExtendedVisitContext;
@@ -92,7 +90,8 @@
family = AbstractTree.COMPONENT_FAMILY,
tag = @Tag(name = "tree", handler =
"org.richfaces.view.facelets.TreeHandler"),
renderer = @JsfRenderer(type = "org.richfaces.TreeRenderer"),
- attributes = {"ajax-props.xml", "events-props.xml",
"core-props.xml", "i18n-props.xml", "tree-common-props.xml",
"rowKeyConverter-prop.xml"}
+ attributes = {"ajax-props.xml", "events-props.xml",
"core-props.xml", "i18n-props.xml", "tree-common-props.xml",
+ "rowKeyConverter-prop.xml",
"tree-serverEventListeners-props.xml"}
)
//TODO add rowData caching for wrapper events
public abstract class AbstractTree extends UIDataAdaptor implements
MetaComponentResolver, MetaComponentEncoder, TreeSelectionChangeSource, TreeToggleSource
{
@@ -138,14 +137,6 @@
selection
}
- @SuppressWarnings("unused")
- @Attribute(generate = false, signature = @Signature(returnType = Void.class,
parameters = TreeSelectionChangeEvent.class))
- private MethodExpression selectionChangeListener;
-
- @SuppressWarnings("unused")
- @Attribute(generate = false, signature = @Signature(returnType = Void.class,
parameters = TreeToggleListener.class))
- private MethodExpression toggleListener;
-
private transient TreeRange treeRange;
private transient UIComponent currentComponent = this;
@@ -203,6 +194,7 @@
return COMPONENT_FAMILY;
}
+ @Attribute
public Collection<Object> getSelection() {
@SuppressWarnings("unchecked")
Collection<Object> selection = (Collection<Object>)
getStateHelper().eval(PropertyKeys.selection);
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -23,7 +23,6 @@
import java.io.IOException;
-import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
@@ -40,7 +39,6 @@
import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.cdk.annotations.Signature;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.context.ExtendedVisitContext;
import org.richfaces.context.ExtendedVisitContextMode;
@@ -58,7 +56,7 @@
family = AbstractTreeNode.COMPONENT_FAMILY,
tag = @Tag(name = "treeNode", handler =
"org.richfaces.view.facelets.TreeNodeHandler"),
renderer = @JsfRenderer(type = "org.richfaces.TreeNodeRenderer"),
- attributes = {"events-props.xml", "core-props.xml",
"i18n-props.xml", "tree-common-props.xml"}
+ attributes = {"events-props.xml", "core-props.xml",
"i18n-props.xml", "tree-common-props.xml",
"treeNode-serverEventListeners-props.xml"}
)
public abstract class AbstractTreeNode extends UIComponentBase implements
MetaComponentResolver, MetaComponentEncoder, IterationStateHolder, TreeToggleSource {
@@ -72,9 +70,6 @@
expanded
}
- @Attribute(generate = false, signature = @Signature(returnType = Void.class,
parameters = TreeToggleEvent.class))
- private MethodExpression toggleListener;
-
public AbstractTreeNode() {
setRendererType("org.richfaces.TreeNodeRenderer");
}
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataGridRenderer.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataGridRenderer.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataGridRenderer.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -23,6 +23,7 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.util.Map;
import javax.faces.FacesException;
import javax.faces.application.ResourceDependencies;
@@ -240,8 +241,10 @@
AbstractDataGrid dataGrid = (AbstractDataGrid)component;
writer.startElement(HtmlConstants.TABLE_ELEMENT, dataGrid);
writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
dataGrid.getClientId(facesContext), null);
- writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-dg", null);
-
+ Map<String, Object> attributes = dataGrid.getAttributes();
+ String classes = concatClasses("rf-dg",
attributes.get(HtmlConstants.STYLE_CLASS_ATTR));
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, classes, null);
+ RenderKitUtils.renderAttribute(facesContext, "style",
attributes.get(HtmlConstants.STYLE_ATTRIBUTE));
encodeCaption(writer, facesContext, dataGrid);
encodeHeader(writer, facesContext, dataGrid, false);
encodeFooter(writer, facesContext, dataGrid, false);
@@ -288,14 +291,12 @@
int columns = dataGrid.getColumns();
int rest = columns - cell;
- if(rest != 0) {
- for (int i = 0; i < rest; i++) {
- writer.startElement(HtmlConstants.TD_ELEM, dataGrid);
- writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-dg-c",
null);
- writer.endElement(HtmlConstants.TD_ELEM);
- }
- writer.endElement(HtmlConstants.TR_ELEMENT);
+ for (int i = 0; i < rest; i++) {
+ writer.startElement(HtmlConstants.TD_ELEM, dataGrid);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-dg-c",
null);
+ writer.endElement(HtmlConstants.TD_ELEM);
}
+ writer.endElement(HtmlConstants.TR_ELEMENT);
}
public DataVisitResult process(FacesContext facesContext, Object rowKey, Object
argument) {
Modified:
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -806,10 +806,17 @@
if (column.isRendered()) {
writer.startElement(HtmlConstants.TD_ELEM, table);
- String columnClass = getColumnClass(rowHolder, columnNumber);
+ String columnClass = concatClasses(getColumnClass(rowHolder,
columnNumber),
+ column.getAttributes().get(HtmlConstants.STYLE_CLASS_ATTR));
if (!"".equals(columnClass)) {
writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, columnClass,
null);
}
+
+ String columnStyle =
(String)column.getAttributes().get(HtmlConstants.STYLE_ATTRIBUTE);
+ if (!"".equals(columnStyle)) {
+ writer.writeAttribute(HtmlConstants.STYLE_ATTRIBUTE, columnStyle,
null);
+ }
+
columnNumber++;
writer.startElement(HtmlConstants.DIV_ELEM, table);
Added:
branches/4.0.X/ui/iteration/ui/src/main/resources/META-INF/cdk/attributes/tree-serverEventListeners-props.xml
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/resources/META-INF/cdk/attributes/tree-serverEventListeners-props.xml
(rev 0)
+++
branches/4.0.X/ui/iteration/ui/src/main/resources/META-INF/cdk/attributes/tree-serverEventListeners-props.xml 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- JBoss, Home of Professional Open Source Copyright ${year}, 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. -->
+<cdk:properties
xmlns:xi="http://www.w3.org/2001/XInclude"
+
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/extensions"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee">
+
+ <property>
+ <property-name>selectionChangeListener</property-name>
+ <property-class>javax.el.MethodExpression</property-class>
+ <property-extension>
+ <cdk:generate>false</cdk:generate>
+ </property-extension>
+ </property>
+ <property>
+ <property-name>toggleListener</property-name>
+ <property-class>javax.el.MethodExpression</property-class>
+ <property-extension>
+ <cdk:generate>false</cdk:generate>
+ </property-extension>
+ </property>
+
+</cdk:properties>
Added:
branches/4.0.X/ui/iteration/ui/src/main/resources/META-INF/cdk/attributes/treeNode-serverEventListeners-props.xml
===================================================================
---
branches/4.0.X/ui/iteration/ui/src/main/resources/META-INF/cdk/attributes/treeNode-serverEventListeners-props.xml
(rev 0)
+++
branches/4.0.X/ui/iteration/ui/src/main/resources/META-INF/cdk/attributes/treeNode-serverEventListeners-props.xml 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- JBoss, Home of Professional Open Source Copyright ${year}, 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. -->
+<cdk:properties
xmlns:xi="http://www.w3.org/2001/XInclude"
+
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/extensions"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee">
+
+ <property>
+ <property-name>toggleListener</property-name>
+ <property-class>javax.el.MethodExpression</property-class>
+ <property-extension>
+ <cdk:generate>false</cdk:generate>
+ </property-extension>
+ </property>
+
+</cdk:properties>
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractAccordion.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractAccordion.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractAccordion.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -23,7 +23,12 @@
package org.richfaces.component;
-import org.richfaces.cdk.annotations.*;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
/**
* @author akolonitsky
@@ -52,6 +57,12 @@
String res = super.getActiveItem();
if (res == null) {
res = getFirstItem().getName();
+ } else {
+ AbstractTogglePanelTitledItem item =
+ (AbstractTogglePanelTitledItem)
super.getItemByIndex(super.getChildIndex(res));
+ if (item.isDisabled()) {
+ res = getFirstItem().getName();
+ }
}
return res;
}
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractCollapsiblePanel.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractCollapsiblePanel.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractCollapsiblePanel.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -27,6 +27,7 @@
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.EventName;
@@ -212,11 +213,13 @@
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
+ if (event instanceof PanelToggleEvent) {
+ setExpanded(((PanelToggleEvent)event).getExpanded());
+ setSubmittedActiveItem(null);
+ if (event.getPhaseId() != PhaseId.UPDATE_MODEL_VALUES) {
+ FacesContext.getCurrentInstance().renderResponse();
+ }
+ }
super.broadcast(event);
-
- if (event instanceof PanelToggleEvent
- && (isBypassUpdates() || isImmediate())) {
- FacesContext.getCurrentInstance().renderResponse();
- }
}
}
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanel.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanel.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanel.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -23,11 +23,11 @@
import javax.faces.component.UIComponentBase;
+import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
-import org.richfaces.cdk.annotations.Attribute;
/**
* JSF component class
*
@@ -38,7 +38,9 @@
)
public abstract class AbstractPanel extends UIComponentBase {
- private static final String COMPONENT_FAMILY = "org.richfaces.Panel";
+ public static final String COMPONENT_TYPE = "org.richfaces.Panel";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.Panel";
@Attribute
public abstract String getHeader();
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenu.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenu.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenu.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -75,58 +75,66 @@
//TODO nick - is component immediate = true only?
//TODO nick - processValue should be executed in context of component, i.e. when
'component' EL variable is set
- processValue(context);
+ ItemChangeEvent event = createItemChangeEvent(context);
+ if (event != null) {
+ event.queue();
+ }
}
-
- private void processValue(FacesContext context) {
- try {
- if (context == null) {
- throw new NullPointerException();
+
+ public void queueEvent(FacesEvent event) {
+ if ((event instanceof ItemChangeEvent) && (event.getComponent() == this))
{
+ setEventPhase((ItemChangeEvent)event);
+ }
+ super.queueEvent(event);
+ }
+
+ public void setEventPhase(FacesEvent event) {
+ if (event instanceof ItemChangeEvent) {
+ AbstractPanelMenuItem actItm = (AbstractPanelMenuItem)
((ItemChangeEvent)event).getNewItem();
+ if (isImmediate() || (actItm != null && actItm.isImmediate())) {
+ event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+ } else if (actItm!= null && actItm.isBypassUpdates()) {
+ event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
+ } else {
+ event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
}
+ }
+ }
- // Submitted value == null means "the component was not submitted at
all".
- String activeItem = getSubmittedActiveItem();
- if (activeItem == null) {
- return;
- }
+ private ItemChangeEvent createItemChangeEvent(FacesContext context) {
- String previous = (String) getValue();
- setActiveItem(activeItem);
- setSubmittedActiveItem(null);
+ // Submitted value == null means "the component was not submitted at
all".
+ String activeItem = getSubmittedActiveItem();
+ if (activeItem == null) {
+ return null;
+ }
- if (previous == null || !previous.equalsIgnoreCase(activeItem)) {
- AbstractPanelMenuItem prevItm = null;
- AbstractPanelMenuItem actItm = null;
- if (previous != null) {
- prevItm = getItem(previous);
- }
- if (activeItem != null) {
- actItm = getItem(activeItem);
- }
-
- ItemChangeEvent event = new ItemChangeEvent(this, previous,prevItm,
activeItem, actItm);
- if (isImmediate() || (actItm != null && actItm.isImmediate())) {
- event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
- } else if (actItm!= null && actItm.isBypassUpdates()) {
- event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
- } else {
- event.setPhaseId(PhaseId.INVOKE_APPLICATION);
- }
- event.queue();
+ String previous = (String) getValue();
+ if (previous == null || !previous.equalsIgnoreCase(activeItem)) {
+ AbstractPanelMenuItem prevItm = null;
+ AbstractPanelMenuItem actItm = null;
+ if (previous != null) {
+ prevItm = getItem(previous);
}
- } catch (RuntimeException e) {
- context.renderResponse();
- throw e;
+ if (activeItem != null) {
+ actItm = getItem(activeItem);
+ }
+
+ return new ItemChangeEvent(this, previous, prevItm, activeItem, actItm);
}
+ return null;
}
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
- super.broadcast(event);
-
if (event instanceof ItemChangeEvent) {
- getFacesContext().renderResponse();
+ setValue(((ItemChangeEvent) event).getNewItemName());
+ setSubmittedActiveItem(null);
+ if (event.getPhaseId() != PhaseId.UPDATE_MODEL_VALUES) {
+ FacesContext.getCurrentInstance().renderResponse();
+ }
}
+ super.broadcast(event);
}
public String getSubmittedActiveItem() {
@@ -155,6 +163,7 @@
}
}
+ @Attribute(generate = false)
public boolean isImmediate() {
return (Boolean) getStateHelper().eval(PropertyKeys.immediate, false);
}
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -30,6 +30,7 @@
import javax.el.MethodExpression;
import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
@@ -126,8 +127,8 @@
}
@Attribute
- public boolean isExpanded() {
- return getValue() == null ? false : (Boolean) getValue();
+ public Boolean isExpanded() {
+ return (Boolean) getValue();
}
public void setExpanded(boolean expanded) {
@@ -323,4 +324,46 @@
@Attribute(events = @EventName("beforeselect"))
public abstract String getOnbeforeselect();
+
+ public boolean hasActiveItem(UIComponent component, String activeItem) {
+ if (activeItem == null) {
+ return false;
+ }
+ if (component instanceof AbstractPanelMenuItem) {
+ AbstractPanelMenuItem item = (AbstractPanelMenuItem) component;
+ if (activeItem.equals(item.getName())) {
+ return true;
+ }
+ }
+
+ if (component instanceof AbstractPanelMenuGroup) {
+ AbstractPanelMenuGroup group = (AbstractPanelMenuGroup) component;
+ if (!group.getPanelMenu().isBubbleSelection()) {
+ return false;
+ }
+ }
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ if (!child.isRendered()) {
+ continue;
+ }
+
+ if (!(child instanceof AbstractPanelMenuItem)) {
+ continue;
+ }
+
+ if (hasActiveItem(child, activeItem)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public boolean getState() {
+ Boolean flag = this.isExpanded();
+ return (flag == null ? this.hasActiveItem(this,
this.getPanelMenu().getActiveItem()) : flag);
+ }
}
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuItem.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuItem.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuItem.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -45,6 +45,10 @@
protected AbstractPanelMenuItem() {
setRendererType("org.richfaces.PanelMenuItemRenderer");
}
+
+ public boolean isActiveItem() {
+ return this.getName().equals(this.getPanelMenu().getActiveItem());
+ }
public boolean isTopItem() {
return getParentItem() instanceof AbstractPanelMenu;
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractTabPanel.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractTabPanel.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractTabPanel.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -25,7 +25,11 @@
import org.richfaces.HeaderAlignment;
import org.richfaces.HeaderPosition;
-import org.richfaces.cdk.annotations.*;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
/**
* @author akolonitsky
@@ -54,6 +58,12 @@
String res = super.getActiveItem();
if (res == null) {
res = getFirstItem().getName();
+ } else {
+ AbstractTogglePanelTitledItem item =
+ (AbstractTogglePanelTitledItem)
super.getItemByIndex(super.getChildIndex(res));
+ if (item.isDisabled()) {
+ res = getFirstItem().getName();
+ }
}
return res;
}
@@ -82,9 +92,6 @@
public abstract String getTabHeaderClass();
@Attribute(hidden = true)
- public abstract boolean isBypassUpdates();
-
- @Attribute(hidden = true)
public abstract boolean isLimitRender();
@Attribute(hidden = true)
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -22,16 +22,10 @@
package org.richfaces.component;
-import com.google.common.base.Strings;
-import org.richfaces.application.MessageFactory;
-import org.richfaces.application.ServiceTracker;
-import org.richfaces.appplication.FacesMessages;
-import org.richfaces.cdk.annotations.*;
-import org.richfaces.component.util.MessageUtil;
-import org.richfaces.event.ItemChangeEvent;
-import org.richfaces.event.ItemChangeListener;
-import org.richfaces.event.ItemChangeSource;
-import org.richfaces.renderkit.util.RendererUtils;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import javax.el.ELException;
import javax.el.MethodExpression;
@@ -41,21 +35,48 @@
import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
import javax.faces.component.UpdateModelException;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
-import javax.faces.event.*;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ExceptionQueuedEvent;
+import javax.faces.event.ExceptionQueuedEventContext;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PostValidateEvent;
+import javax.faces.event.PreValidateEvent;
+import org.richfaces.application.MessageFactory;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.appplication.FacesMessages;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.component.util.MessageUtil;
+import org.richfaces.context.ExtendedVisitContext;
+import org.richfaces.context.ExtendedVisitContextMode;
+import org.richfaces.event.ItemChangeEvent;
+import org.richfaces.event.ItemChangeListener;
+import org.richfaces.event.ItemChangeSource;
+import org.richfaces.renderkit.MetaComponentRenderer;
+import org.richfaces.renderkit.util.RendererUtils;
+
+import com.google.common.base.Strings;
+
/**
* @author akolonitsky
* @version 1.0
*/
@JsfComponent(tag = @Tag(type = TagType.Facelets, handler =
"org.richfaces.view.facelets.html.TogglePanelTagHandler"),
renderer = @JsfRenderer(type = "org.richfaces.TogglePanelRenderer"))
-public abstract class AbstractTogglePanel extends UIOutput implements AbstractDivPanel,
ItemChangeSource {
+public abstract class AbstractTogglePanel extends UIOutput implements AbstractDivPanel,
ItemChangeSource, MetaComponentResolver, MetaComponentEncoder {
+ public static final String ACTIVE_ITEM_META_COMPONENT = "activeItem";
+
public static final String COMPONENT_TYPE = "org.richfaces.TogglePanel";
public static final String COMPONENT_FAMILY = "org.richfaces.TogglePanel";
@@ -204,7 +225,10 @@
popComponentFromEL(context);
}
- createItemChangeEvent(context);
+ ItemChangeEvent event = createItemChangeEvent(context);
+ if (event != null) {
+ event.queue();
+ }
}
/**
@@ -372,7 +396,7 @@
}
}
- private void createItemChangeEvent(FacesContext context) {
+ private ItemChangeEvent createItemChangeEvent(FacesContext context) {
if (context == null) {
throw new NullPointerException();
}
@@ -380,12 +404,10 @@
// Submitted value == null means "the component was not submitted at
all".
String activeItem = getSubmittedActiveItem();
if (activeItem == null) {
- return;
+ return null;
}
String previous = (String) getValue();
- setValue(activeItem);
- setSubmittedActiveItem(null);
if (previous == null || !previous.equalsIgnoreCase(activeItem)) {
UIComponent prevComp = null;
UIComponent actvComp = null;
@@ -397,8 +419,9 @@
actvComp = (UIComponent)getItem(activeItem);
}
- new ItemChangeEvent(this, previous, prevComp, activeItem, actvComp).queue();
+ return new ItemChangeEvent(this, previous, prevComp, activeItem, actvComp);
}
+ return null;
}
@Override
@@ -413,19 +436,14 @@
if (isImmediate() || (event.getNewItem() != null &&
RendererUtils.getInstance().isBooleanAttribute(event.getNewItem(),
"immediate"))) {
event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
- } else if (isBypassUpdates() || (event.getNewItem() != null &&
- RendererUtils.getInstance().isBooleanAttribute(event.getNewItem(),
"bypassUpdates"))) {
- event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
} else {
- event.setPhaseId(PhaseId.INVOKE_APPLICATION);
+ event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
}
}
-
+
protected void setEventPhase(FacesEvent event) {
if (isImmediate()) {
event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
- } else if (isBypassUpdates()) {
- event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
} else {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
}
@@ -433,11 +451,14 @@
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
- super.broadcast(event);
-
if (event instanceof ItemChangeEvent) {
- FacesContext.getCurrentInstance().renderResponse();
+ setValue(((ItemChangeEvent) event).getNewItemName());
+ setSubmittedActiveItem(null);
+ if (event.getPhaseId() != PhaseId.UPDATE_MODEL_VALUES) {
+ FacesContext.getCurrentInstance().renderResponse();
+ }
}
+ super.broadcast(event);
}
// -------------------------------------------------- Panel Items Managing
@@ -618,9 +639,6 @@
getStateHelper().put(PropertyKeys.switchType, switchType);
}
- @Attribute
- public abstract boolean isBypassUpdates();
-
@Attribute(hidden = true)
public abstract boolean isLimitRender();
@@ -665,4 +683,66 @@
removeFacesListener(listener);
}
+ public String resolveClientId(FacesContext facesContext, UIComponent
contextComponent, String metaComponentId) {
+ if (ACTIVE_ITEM_META_COMPONENT.equals(metaComponentId)) {
+ return getClientId(facesContext) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
+ }
+ return null;
+ }
+
+ public String substituteUnresolvedClientId(FacesContext facesContext, UIComponent
contextComponent,
+ String metaComponentId) {
+ return null;
+ }
+
+ public void encodeMetaComponent(FacesContext context, String metaComponentId) throws
IOException {
+ ((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this,
metaComponentId);
+ }
+
+ @Override
+ public boolean visitTree(VisitContext context, VisitCallback callback) {
+ if (!isVisitable(context)) {
+ return false;
+ }
+
+ FacesContext facesContext = context.getFacesContext();
+ pushComponentToEL(facesContext, null);
+
+ try {
+ VisitResult result = context.invokeVisitCallback(this, callback);
+
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ }
+
+ if (result == VisitResult.ACCEPT) {
+ if (context instanceof ExtendedVisitContext) {
+ ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext)
context;
+ if (extendedVisitContext.getVisitMode() ==
ExtendedVisitContextMode.RENDER) {
+
+ result =
extendedVisitContext.invokeMetaComponentVisitCallback(this, callback,
ACTIVE_ITEM_META_COMPONENT);
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ }
+ }
+ }
+ }
+
+ if (result == VisitResult.ACCEPT) {
+ Iterator<UIComponent> kids = this.getFacetsAndChildren();
+
+ while(kids.hasNext()) {
+ boolean done = kids.next().visitTree(context, callback);
+
+ if (done) {
+ return true;
+ }
+ }
+ }
+ } finally {
+ popComponentFromEL(facesContext);
+ }
+
+ return false;
+ }
}
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/CollapsiblePanelRenderer.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/CollapsiblePanelRenderer.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/CollapsiblePanelRenderer.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -102,29 +102,6 @@
};
@Override
- protected void doDecode(FacesContext context, UIComponent component) {
- AbstractTogglePanel panel = (AbstractTogglePanel) component;
-
- Map<String, String> requestMap =
- context.getExternalContext().getRequestParameterMap();
-
- // Don't overwrite the value unless you have to!
- String newValue = requestMap.get(getValueRequestParamName(context, component));
- if (newValue != null) {
- panel.setSubmittedActiveItem(newValue);
- }
-
- String compClientId = component.getClientId(context);
- String clientId = requestMap.get(compClientId);
- if (clientId != null && clientId.equals(compClientId)) {
- context.getPartialViewContext().getRenderIds().add(clientId);
-
- //TODO nick - this should be done on encode, not on decode
- addOnCompleteParam(context, newValue, panel.getClientId(context));
- }
- }
-
- @Override
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
super.doEncodeBegin(writer, context, component);
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -43,14 +43,11 @@
import javax.faces.context.ResponseWriter;
import javax.faces.event.ActionEvent;
-import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSObject;
-import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.PanelMenuMode;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractPanelMenuGroup;
import org.richfaces.component.AbstractPanelMenuItem;
-import org.richfaces.renderkit.HtmlConstants;
import com.google.common.base.Strings;
@@ -117,7 +114,7 @@
writer.writeAttribute(ID_ATTRIBUTE, expanded, null);
writer.writeAttribute(NAME_ATTRIBUTE, expanded, null);
writer.writeAttribute(TYPE_ATTR, INPUT_TYPE_HIDDEN, null);
- writer.writeAttribute(VALUE_ATTRIBUTE, String.valueOf(menuGroup.isExpanded()),
null);
+ writer.writeAttribute(VALUE_ATTRIBUTE, String.valueOf(menuGroup.getState()),
null);
writer.endElement(INPUT_ELEM);
encodeHeader(writer, context, menuGroup);
@@ -128,7 +125,8 @@
writer.startElement(DIV_ELEM, null);
writer.writeAttribute(ID_ATTRIBUTE, menuGroup.getClientId(context) +
":hdr", null);
writer.writeAttribute(CLASS_ATTRIBUTE, concatClasses(getCssClass(menuGroup,
"-hdr"),
- "rf-pm-hdr-" + (menuGroup.isExpanded() ? "exp" :
"colps"),
+ "rf-pm-hdr-" + (menuGroup.getState() ? "exp" :
"colps"),
+ (menuGroup.getPanelMenu().isBubbleSelection() &&
menuGroup.hasActiveItem(menuGroup, menuGroup.getPanelMenu().getActiveItem()) ?
getCssClass(menuGroup, "-sel") : ""),
PanelMenuItemRenderer.isParentPanelMenuDisabled(menuGroup) ||
menuGroup.isDisabled() ? getCssClass(menuGroup, "-hdr-dis") : null), null);
(menuGroup.isTopItem() ? topHeaderRenderer : headerRenderer).encodeHeader(writer,
context, menuGroup);
@@ -143,7 +141,7 @@
private void encodeContentBegin(ResponseWriter writer, FacesContext context,
AbstractPanelMenuGroup menuGroup) throws IOException {
writer.startElement(DIV_ELEM, null);
writer.writeAttribute(ID_ATTRIBUTE, menuGroup.getClientId(context) +
":cnt", null);
- writer.writeAttribute(CLASS_ATTRIBUTE, concatClasses(getCssClass(menuGroup,
"-cnt"), menuGroup.isExpanded() ? "rf-pm-exp" :
"rf-pm-colps"), null);
+ writer.writeAttribute(CLASS_ATTRIBUTE, concatClasses(getCssClass(menuGroup,
"-cnt"), menuGroup.getState() ? "rf-pm-exp" :
"rf-pm-colps"), null);
writeJavaScript(writer, context, menuGroup);
}
@@ -202,9 +200,10 @@
options.put("disabled",
PanelMenuItemRenderer.isParentPanelMenuDisabled(panelMenuGroup) ||
panelMenuGroup.isDisabled());
options.put("expandEvent", getExpandEvent(panelMenuGroup));
options.put("collapseEvent", getCollapseEvent(panelMenuGroup));
- options.put("expanded", panelMenuGroup.isExpanded());
+ options.put("expanded", panelMenuGroup.getState());
options.put("selectable", panelMenuGroup.isSelectable());
options.put("unselectable", panelMenuGroup.isUnselectable());
+ options.put("stylePrefix", getCssClass(panelMenuGroup, ""));
addEventOption(context, panelMenuGroup, options, COLLAPSE);
addEventOption(context, panelMenuGroup, options, EXPAND);
@@ -235,40 +234,6 @@
return true;
}
- private boolean containsActiveItem(UIComponent component, String activeItem) {
- if (component instanceof AbstractPanelMenuItem) {
- AbstractPanelMenuItem item = (AbstractPanelMenuItem) component;
- if (activeItem.equals(item.getName())) {
- return true;
- }
- }
-
- if (component instanceof AbstractPanelMenuGroup) {
- AbstractPanelMenuGroup group = (AbstractPanelMenuGroup) component;
- if (!group.getPanelMenu().isBubbleSelection()) {
- return false;
- }
- }
-
- if (component.getChildCount() > 0) {
- for (UIComponent child : component.getChildren()) {
- if (!child.isRendered()) {
- continue;
- }
-
- if (!(child instanceof AbstractPanelMenuItem)) {
- continue;
- }
-
- if (containsActiveItem(child, activeItem)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
@Override
protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component)
throws IOException {
@@ -277,16 +242,8 @@
boolean isClientMode = group.getMode() == PanelMenuMode.client;
- if (isClientMode || group.isExpanded()) {
+ if (isClientMode || group.getState()) {
renderChildren(context, component);
- } else {
- String activeItem = group.getPanelMenu().getActiveItem();
- if (!Strings.isNullOrEmpty(activeItem) &&
containsActiveItem(component, activeItem)) {
- writer.startElement(HtmlConstants.SCRIPT_ELEM, component);
- writer.writeAttribute(HtmlConstants.TYPE_ATTR,
HtmlConstants.TEXT_JAVASCRIPT_TYPE, null);
- writer.writeText(ScriptUtils.toScript(new
JSFunction("RichFaces.$", component.getClientId(context))) +
".__restoreSelection();", null);
- writer.endElement(HtmlConstants.SCRIPT_ELEM);
- }
}
}
}
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -189,13 +189,14 @@
writer.endElement(TD_ELEM);
}
-
+
@Override
protected String getStyleClass(UIComponent component) {
AbstractPanelMenuItem menuItem = (AbstractPanelMenuItem) component;
return concatClasses(getCssClass(menuItem, ""),
attributeAsString(component, "styleClass"),
PanelMenuItemRenderer.isParentPanelMenuDisabled(menuItem) ||
menuItem.isDisabled() ? getCssClass(menuItem, "-dis") : "",
+ (menuItem.isActiveItem() ? getCssClass(menuItem, "-sel") :
""),
PanelMenuItemRenderer.isParentPanelMenuDisabled(menuItem) ||
menuItem.isDisabled() ? attributeAsString(component, "disabledClass") :
"");
}
@@ -221,6 +222,7 @@
options.put("name", panelMenuItem.getName());
options.put("selectable", panelMenuItem.isSelectable());
options.put("unselectable", panelMenuItem.isUnselectable());
+ options.put("stylePrefix", getCssClass(panelMenuItem, ""));
addEventOption(context, panelMenuItem, options, UNSELECT);
addEventOption(context, panelMenuItem, options, SELECT);
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -23,23 +23,24 @@
package org.richfaces.renderkit.html;
-import org.ajax4jsf.javascript.JSObject;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.component.AbstractPanelMenu;
-import org.richfaces.component.util.HtmlUtil;
-import org.richfaces.renderkit.HtmlConstants;
+import static org.richfaces.renderkit.html.TogglePanelRenderer.getAjaxOptions;
+import static org.richfaces.renderkit.html.TogglePanelRenderer.getValueRequestParamName;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import static org.richfaces.renderkit.html.TogglePanelRenderer.getAjaxOptions;
-import static org.richfaces.renderkit.html.TogglePanelRenderer.getValueRequestParamName;
+import org.ajax4jsf.javascript.JSObject;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.component.AbstractPanelMenu;
+import org.richfaces.component.util.HtmlUtil;
+import org.richfaces.renderkit.HtmlConstants;
/**
* @author akolonitsky
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabPanelRenderer.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabPanelRenderer.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabPanelRenderer.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -22,25 +22,39 @@
package org.richfaces.renderkit.html;
-import org.ajax4jsf.javascript.JSObject;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.component.*;
-import org.richfaces.component.util.HtmlUtil;
-import org.richfaces.context.ExtendedPartialViewContext;
-import org.richfaces.renderkit.HtmlConstants;
-import org.richfaces.renderkit.RenderKitUtils;
+import static org.richfaces.component.AbstractTogglePanelTitledItem.HeaderStates.active;
+import static
org.richfaces.component.AbstractTogglePanelTitledItem.HeaderStates.disabled;
+import static
org.richfaces.component.AbstractTogglePanelTitledItem.HeaderStates.inactive;
+import static org.richfaces.renderkit.HtmlConstants.CLASS_ATTRIBUTE;
+import static org.richfaces.renderkit.HtmlConstants.DIV_ELEM;
+import static org.richfaces.renderkit.HtmlConstants.ID_ATTRIBUTE;
+import static org.richfaces.renderkit.HtmlConstants.SPAN_ELEM;
+import static org.richfaces.renderkit.HtmlConstants.STYLE_ATTRIBUTE;
+import static org.richfaces.renderkit.HtmlConstants.TBODY_ELEMENT;
+import static org.richfaces.renderkit.HtmlConstants.TD_ELEM;
+import static org.richfaces.renderkit.HtmlConstants.TR_ELEMENT;
+import static org.richfaces.renderkit.RenderKitUtils.renderPassThroughAttributes;
+import java.io.IOException;
+import java.util.Map;
+
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.util.Map;
-import static org.richfaces.component.AbstractTogglePanelTitledItem.HeaderStates.*;
-import static org.richfaces.renderkit.HtmlConstants.*;
-import static org.richfaces.renderkit.RenderKitUtils.renderPassThroughAttributes;
+import org.ajax4jsf.javascript.JSObject;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.component.AbstractTab;
+import org.richfaces.component.AbstractTabPanel;
+import org.richfaces.component.AbstractTogglePanel;
+import org.richfaces.component.AbstractTogglePanelItemInterface;
+import org.richfaces.component.AbstractTogglePanelTitledItem;
+import org.richfaces.component.util.HtmlUtil;
+import org.richfaces.context.ExtendedPartialViewContext;
+import org.richfaces.renderkit.HtmlConstants;
+import org.richfaces.renderkit.RenderKitUtils;
/**
* @author akolonitsky
@@ -70,33 +84,6 @@
private static final String STYLE = STYLE_ATTRIBUTE;
private static final String CLASS = CLASS_ATTRIBUTE;
-// @Override
-// protected void doDecode(FacesContext context, UIComponent component) {
-// AbstractTogglePanel panel = (AbstractTogglePanel) component;
-//
-// Map<String, String> requestMap =
-// context.getExternalContext().getRequestParameterMap();
-//
-// // Don't overwrite the value unless you have to!
-// String newValue = requestMap.get(getValueRequestParamName(context,
component));
-// if (newValue != null) {
-// panel.setSubmittedActiveItem(newValue);
-// }
-//
-// String tabClientId = component.getClientId(context);
-// if (requestMap.get(tabClientId) != null) {
-// new ActionEvent(component).queue();
-//
-// if (context.getPartialViewContext().isPartialRequest()) {
-// //TODO nick - why render item by default?
-// context.getPartialViewContext().getRenderIds().add(tabClientId);
-//
-// //TODO nick - this should be done on encode, not on decode
-// AbstractTab tab = (AbstractTab) component;
-// addOnCompleteParam(context, tab.getName(),
tab.getTabPanel().getClientId(context));
-// }
-// }
-// }
protected static void addOnCompleteParam(FacesContext context, String newValue,
String panelId) {
StringBuilder onComplete = new StringBuilder();
Modified:
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -22,29 +22,33 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.PartialViewContext;
+import javax.faces.context.ResponseWriter;
+
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSObject;
import org.ajax4jsf.javascript.JSReference;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractTogglePanel;
import org.richfaces.component.AbstractTogglePanelItemInterface;
+import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.util.HtmlUtil;
import org.richfaces.context.ExtendedPartialViewContext;
import org.richfaces.renderkit.AjaxOptions;
import org.richfaces.renderkit.HtmlConstants;
+import org.richfaces.renderkit.MetaComponentRenderer;
import org.richfaces.renderkit.util.AjaxRendererUtils;
import org.richfaces.renderkit.util.FormUtil;
import org.richfaces.renderkit.util.HandlersChain;
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* @author akolonitsky
*/
@@ -56,7 +60,7 @@
@ResourceDependency(name = "richfaces-base-component.js"),
@ResourceDependency(library = "org.richfaces", name =
"togglePanel.js")})
@JsfRenderer(type = "org.richfaces.TogglePanelRenderer", family =
AbstractTogglePanel.COMPONENT_FAMILY)
-public class TogglePanelRenderer extends DivPanelRenderer {
+public class TogglePanelRenderer extends DivPanelRenderer implements
MetaComponentRenderer {
public static final String VALUE_POSTFIX = "-value";
@@ -76,17 +80,14 @@
String newValue = requestMap.get(getValueRequestParamName(context, component));
if (newValue != null) {
panel.setSubmittedActiveItem(newValue);
-
- //Retrieve the child item from the panel
- AbstractTogglePanelItemInterface panelItem = panel.getItem(newValue);
- if (panelItem != null) {
- //Set the active panel to be rendered
- context.getPartialViewContext().getRenderIds().add(((UIComponent)
panelItem).getClientId(context));
-
- //TODO nick - this should be done on encode, not on decode
- addOnCompleteParam(context, newValue, panel.getClientId(context));
- }
}
+
+ if (requestMap.get("javax.faces.partial.ajax") != null) {
+ PartialViewContext pvc = context.getPartialViewContext();
+ pvc.getRenderIds().add(
+ component.getClientId(context) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR
+ + AbstractTogglePanel.ACTIVE_ITEM_META_COMPONENT);
+ }
}
protected static void addOnCompleteParam(FacesContext context, String newValue,
String panelId) {
@@ -100,7 +101,7 @@
static String getValueRequestParamName(FacesContext context, UIComponent component)
{
return component.getClientId(context) + VALUE_POSTFIX;
}
-
+
@Override
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
FormUtil.throwEnclFormReqExceptionIfNeed(context, component);
@@ -114,7 +115,7 @@
writer.writeAttribute(HtmlConstants.TYPE_ATTR, HtmlConstants.INPUT_TYPE_HIDDEN,
null);
writer.writeAttribute(HtmlConstants.VALUE_ATTRIBUTE, panel.getActiveItem(),
null);
writer.endElement(HtmlConstants.INPUT_ELEM);
-
+
writeJavaScript(writer, context, component);
}
@@ -179,5 +180,39 @@
protected Class<? extends UIComponent> getComponentClass() {
return AbstractTogglePanel.class;
}
+
+ public void encodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId)
+ throws IOException {
+ if (AbstractTogglePanel.ACTIVE_ITEM_META_COMPONENT.equals(metaComponentId)) {
+ AbstractTogglePanel panel = (AbstractTogglePanel)component;
+ AbstractTogglePanelItemInterface item =
panel.getItem(panel.getActiveItem());
+
+ if (item != null) {
+ partialStart(context, ((UIComponent)item).getClientId(context));
+ ((UIComponent)item).encodeAll(context);
+ partialEnd(context);
+ addOnCompleteParam(context, item.getName(), panel.getClientId(context));
+ } else {
+ partialStart(context, component.getClientId(context));
+ component.encodeAll(context);
+ partialEnd(context);
+ addOnCompleteParam(context, panel.getActiveItem(),
panel.getClientId(context));
+ }
+ } else {
+ throw new IllegalArgumentException(metaComponentId);
+ }
+ }
+
+ public void decodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId) {
+ // TODO Auto-generated method stub
+ }
+
+ protected void partialStart(FacesContext facesContext, String id) throws IOException
{
+ facesContext.getPartialViewContext().getPartialResponseWriter().startUpdate(id);
+ }
+
+ protected void partialEnd(FacesContext facesContext) throws IOException {
+ facesContext.getPartialViewContext().getPartialResponseWriter().endUpdate();
+ }
}
Modified:
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenu.js
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenu.js 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenu.js 2011-02-27
18:30:19 UTC (rev 21968)
@@ -107,7 +107,7 @@
* @return {String} TODO ...
*/
selectedItem: function (id) {
- if (id != undefined) {
+ if (typeof id != "undefined") {
var valueInput = this.__getValueInput();
var prevActiveItem = valueInput.value;
Modified:
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuGroup.js
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuGroup.js 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuGroup.js 2011-02-27
18:30:19 UTC (rev 21968)
@@ -221,12 +221,12 @@
});
}
- this.__addUserEventHandler("beforecollapse");
+ /*this.__addUserEventHandler("beforecollapse");
this.__addUserEventHandler("collapse");
this.__addUserEventHandler("beforeexpand");
this.__addUserEventHandler("expand");
this.__addUserEventHandler("beforeswitch");
- this.__addUserEventHandler("switch");
+ this.__addUserEventHandler("switch");*/
}
},
@@ -403,11 +403,6 @@
__isMyEvent: function (event) {
return this.id == event.target.id;
},
-
- __fireEvent: function(eventName) {
- var data = {id: this.id};
- return rf.Event.fireById(this.id, eventName, data);
- },
destroy: function () {
rf.Event.unbindById(this.id, "."+this.namespace);
Modified:
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuItem.js
===================================================================
---
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuItem.js 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/panelMenuItem.js 2011-02-27
18:30:19 UTC (rev 21968)
@@ -161,10 +161,6 @@
// todo move it
this.selectionClass = this.options.stylePrefix + "-sel";
- if (panelMenu.__isActiveItem(this)) {
- rootElt.ready($.proxy(this.__restoreSelection, this));
- }
-
if (!this.options.disabled) {
var item = this;
@@ -207,7 +203,7 @@
* @return {void} TODO ...
*/
select: function () {
- var continueProcess = this.__fireBeforeSelect();
+ var continueProcess = this.__fireEvent("beforeSelect");
if (!continueProcess) {
return false;
}
@@ -292,11 +288,6 @@
__header : function () {
return this.__item();
},
-
- __restoreSelection: function() {
- this.__select();
- //this.__fireSelect();
- },
__isSelected: function() {
return this.__header().hasClass(this.selectionClass);
@@ -309,13 +300,7 @@
__unselect: function () {
this.__header().removeClass(this.selectionClass);
},
-
- __fireBeforeSelect : function () {
- return rf.Event.fireById(this.id, "beforeselect", {
- item: this
- });
- },
-
+
__fireSelect : function () {
return rf.Event.fireById(this.id, "select", {
item: this
@@ -327,6 +312,10 @@
item: this
});
},
+
+ __fireEvent : function (eventType, event) {
+ return this.invokeEvent(eventType, rf.getDomElement(this.id), event, {id:
this.id, item: this});
+ },
/**
* @private
Modified:
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptNotFoundException.java
===================================================================
---
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptNotFoundException.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptNotFoundException.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -1,24 +1,21 @@
package org.richfaces.javascript;
-public class ScriptNotFoundException extends Exception {
+public class ScriptNotFoundException extends RuntimeException {
public ScriptNotFoundException() {
- // TODO Auto-generated constructor stub
+ super();
}
public ScriptNotFoundException(String message) {
super(message);
- // TODO Auto-generated constructor stub
}
public ScriptNotFoundException(Throwable cause) {
super(cause);
- // TODO Auto-generated constructor stub
}
public ScriptNotFoundException(String message, Throwable cause) {
super(message, cause);
- // TODO Auto-generated constructor stub
}
}
Modified:
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/FacesConverterService.java
===================================================================
---
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/FacesConverterService.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/FacesConverterService.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -1,5 +1,6 @@
package org.richfaces.validator;
+import javax.faces.component.EditableValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
@@ -11,6 +12,6 @@
*/
public interface FacesConverterService {
- ConverterDescriptor getConverterDescription(FacesContext context,Converter
converter);
+ ConverterDescriptor getConverterDescription(FacesContext context,EditableValueHolder
input, Converter converter);
}
Modified:
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/FacesValidatorService.java
===================================================================
---
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/FacesValidatorService.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/api/src/main/java/org/richfaces/validator/FacesValidatorService.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -1,10 +1,11 @@
package org.richfaces.validator;
+import javax.faces.component.EditableValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
public interface FacesValidatorService {
- ValidatorDescriptor getValidatorDescription(FacesContext context,Validator
validator);
+ ValidatorDescriptor getValidatorDescription(FacesContext context,EditableValueHolder
component, Validator validator);
}
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -20,43 +20,44 @@
*/
package org.richfaces.component;
-import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
-import java.util.Iterator;
import javax.el.ELContext;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
+import org.richfaces.application.ServiceTracker;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
import org.richfaces.el.CapturingELResolver;
import org.richfaces.el.ELContextWrapper;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.validator.BeanValidatorService;
import org.richfaces.validator.FacesBeanValidator;
-import org.richfaces.validator.GraphValidator;
import org.richfaces.validator.GraphValidatorState;
/**
* JSF component class
*
*/
-@JsfComponent(tag=(a)Tag(name="graphValidator",type=TagType.Facelets))
+@JsfComponent(tag=(a)Tag(name="graphValidator",type=TagType.Facelets, handler =
"org.richfaces.view.facelets.html.GraphValidatorHandler"))
public abstract class AbstractGraphValidator extends UIComponentBase {
public static final String COMPONENT_TYPE =
"org.richfaces.GraphValidator";
public static final String COMPONENT_FAMILY =
"org.richfaces.GraphValidator";
+
+ private static final Logger LOG = RichfacesLogger.COMPONENTS.getLogger();
/**
* Get object for validation
@@ -208,32 +209,23 @@
private void validateObject(FacesContext context, Object value) {
if (null != value) {
- Validator validator = context.getApplication().createValidator(getType());
- if (validator instanceof GraphValidator) {
- GraphValidator graphValidator = (GraphValidator) validator;
- Collection<String> messages = graphValidator.validateGraph(context,
this, value, getGroups());
- if (null != messages) {
- context.renderResponse();
- // send all validation messages.
- String clientId = getClientId(context);
- for (String msg : messages) {
- // TODO - create Summary message ?
- String summary = null != getSummary() ? getSummary() + msg :
msg;
- context.addMessage(clientId, new
FacesMessage(FacesMessage.SEVERITY_ERROR, summary, msg));
- }
+ Collection<String> messages;
+ BeanValidatorService validatorService =
ServiceTracker.getService(BeanValidatorService.class);
+ messages = validatorService.validateObject(context, value, getGroups());
+ if (!messages.isEmpty()) {
+ context.renderResponse();
+ // send all validation messages.
+ String clientId = getClientId(context);
+ for (String msg : messages) {
+ String summary = null != getSummary() ? getSummary() : msg;
+ context.addMessage(clientId, new
FacesMessage(FacesMessage.SEVERITY_ERROR, summary, msg));
}
-
- } else {
- throw new FacesException("Validator " +
FacesBeanValidator.BEAN_VALIDATOR_TYPE
- + " does not implement GraphValidator");
}
}
}
- @Override
- public void encodeBegin(FacesContext context) throws IOException {
- super.encodeBegin(context);
+ public Validator createChildrenValidator(FacesContext context) {
FacesBeanValidator validator = (FacesBeanValidator)
context.getApplication().createValidator(getType());
validator.setSummary(getSummary());
ValueExpression expression = getValueExpression("groups");
@@ -242,48 +234,7 @@
} else {
validator.setGroups(getGroups());
}
- setupValidators(this, validator);
+ return validator;
}
-
- @Override
- public void encodeChildren(FacesContext context) throws IOException {
- if (isRendered()) {
- for (UIComponent child : getChildren()) {
- if (child.isRendered()) {
- child.encodeAll(context);
- }
- }
- }
- }
-
- private void setupValidators(UIComponent component, Validator validator) {
- Iterator<UIComponent> facetsAndChildren =
component.getFacetsAndChildren();
- while (facetsAndChildren.hasNext()) {
- UIComponent child = facetsAndChildren.next();
- if (child instanceof EditableValueHolder) {
- EditableValueHolder input = (EditableValueHolder) child;
- setupValidator(input, validator);
- }
- setupValidators(child, validator);
- }
- }
-
- /**
- * @param input
- */
- private void setupValidator(EditableValueHolder input, Validator validator) {
- Validator[] validators = input.getValidators();
- for (int i = 0; i < validators.length; i++) {
- if (validators[i].getClass().equals(validator.getClass())) {
- return;
- }
- }
- input.addValidator(validator);
- }
-
- @Override
- public boolean getRendersChildren() {
- return true;
- }
-
+
}
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -31,6 +31,7 @@
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
import javax.faces.component.ActionSource;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.NamingContainer;
@@ -54,6 +55,7 @@
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
import org.richfaces.component.ClientSideMessage;
+import org.richfaces.javascript.JavaScriptService;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.renderkit.html.ClientValidatorRenderer;
@@ -116,12 +118,10 @@
if(partialViewContext.isAjaxRequest()){
UIComponent component = event.getComponent();
if(component instanceof EditableValueHolder){
- EditableValueHolder input = (EditableValueHolder) component;
- Set<UIComponent> messages = getMessages(facesContext, component);
- Collection<String> renderIds = partialViewContext.getRenderIds();
- for (UIComponent uiComponent : messages) {
- renderIds.add(uiComponent.getClientId(facesContext));
- }
+ String clientId = component.getClientId(facesContext);
+ Iterator<FacesMessage> messages =
facesContext.getMessages(clientId);
+ JavaScriptService javaScriptService =
ServiceTracker.getService(JavaScriptService.class);
+ javaScriptService.addPageReadyScript(facesContext, new
MessageUpdateScript(clientId,messages));
}
}
super.broadcast(event);
@@ -245,7 +245,7 @@
}
if(null != converter){
FacesConverterService converterService =
ServiceTracker.getService(facesContext, FacesConverterService.class);
- return converterService.getConverterDescription(facesContext,
converter);
+ return converterService.getConverterDescription(facesContext, input,
converter);
} else {
return null;
}
@@ -282,18 +282,20 @@
Validator[] facesValidators = input.getValidators();
FacesContext facesContext = context.getFacesContext();
if (facesValidators.length > 0) {
+ boolean beanValidatorsProcessed = false;
FacesValidatorService facesValidatorService =
ServiceTracker.getService(facesContext,
FacesValidatorService.class);
for (Validator validator : facesValidators) {
if (validator instanceof BeanValidator || validator instanceof
FacesBeanValidator) {
ValueExpression valueExpression =
component.getValueExpression(VALUE);
- if (null != valueExpression) {
+ if (null != valueExpression && !beanValidatorsProcessed)
{
BeanValidatorService beanValidatorService =
ServiceTracker.getService(facesContext,
BeanValidatorService.class);
validators.addAll(beanValidatorService.getConstrains(facesContext, valueExpression,
getGroups()));
+ beanValidatorsProcessed = true;
}
} else {
-
validators.add(facesValidatorService.getValidatorDescription(facesContext, validator));
+
validators.add(facesValidatorService.getValidatorDescription(facesContext, input,
validator));
}
}
}
Added:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageUpdateScript.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageUpdateScript.java
(rev 0)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/component/behavior/MessageUpdateScript.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,45 @@
+package org.richfaces.component.behavior;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.faces.application.FacesMessage;
+
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.ScriptString;
+import org.ajax4jsf.javascript.ScriptStringBase;
+import org.richfaces.javascript.Message;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterators;
+
+public class MessageUpdateScript extends ScriptStringBase implements ScriptString {
+
+ private static final Function<? super FacesMessage, Message>
MESSAGES_TRANSFORMER = new Function<FacesMessage, Message>() {
+
+ public Message apply(FacesMessage msg) {
+ return new Message(msg);
+ }
+ };
+ private final ImmutableList<Message> messages;
+ private final String clientId;
+
+ public MessageUpdateScript(String clientId,Iterator<FacesMessage> messages) {
+ this.clientId = clientId;
+ this.messages = ImmutableList.copyOf(Iterators.transform(messages,
MESSAGES_TRANSFORMER));
+ }
+
+ public void appendScript(Appendable target) throws IOException {
+ JSFunction resetMessages = new
JSFunction("RichFaces.csv.clearMessage",clientId);
+ resetMessages.appendScript(target);
+ target.append(';');
+ for (Message message : messages) {
+ JSFunction sendMessage = new
JSFunction("RichFaces.csv.sendMessage",clientId,message);
+ sendMessage.appendScript(target);
+ target.append(';');
+ }
+ }
+
+}
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientScriptServiceImpl.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
import javax.faces.application.Resource;
import javax.faces.application.ResourceDependency;
@@ -14,7 +15,10 @@
import org.richfaces.component.util.Strings;
import org.richfaces.resource.ResourceKey;
+import com.google.common.base.Function;
+import com.google.common.collect.ComputationException;
import com.google.common.collect.Lists;
+import com.google.common.collect.MapMaker;
/**
* @author asmirnov
@@ -26,10 +30,30 @@
private static final String ORG_RICHFACES_CSV = "org.richfaces.csv";
+ private static final Function<Class<?>, ? extends LibraryFunction>
RESOURCE_SCRIPT_FUNCTION = new Function<Class<?>, LibraryFunction>() {
+
+ public LibraryFunction apply(Class<?> arg0) {
+ return getScriptResource(FacesContext.getCurrentInstance(), arg0);
+ }
+ };
+
+ private static final Function<Class<?>, ? extends LibraryFunction>
ANNOTATION_SCRIPT_FUNCTION = new Function<Class<?>, LibraryFunction>() {
+
+ public LibraryFunction apply(Class<?> arg0) {
+ return getScriptFromAnnotation(arg0);
+ }
+ };
+
+ private final ConcurrentMap<Class<?>, LibraryFunction> resourcesMapping;
+
+ private final ConcurrentMap<Class<?>, LibraryFunction>
annotationsMapping;
+
private final Map<Class<?>, LibraryFunction> defaultMapping;
public ClientScriptServiceImpl(Map<Class<?>, LibraryFunction>
defaultMapping) {
this.defaultMapping = defaultMapping;
+ resourcesMapping = new
MapMaker().initialCapacity(10).makeComputingMap(RESOURCE_SCRIPT_FUNCTION);
+ annotationsMapping = new
MapMaker().initialCapacity(10).makeComputingMap(ANNOTATION_SCRIPT_FUNCTION);
}
/*
@@ -43,18 +67,31 @@
}
LibraryFunction function;
try {
- function = getScriptResource(facesContext, javaClass);
+ function = getFromComputationMap(resourcesMapping, javaClass);
} catch (ScriptNotFoundException e) {
if (defaultMapping.containsKey(javaClass)) {
function = defaultMapping.get(javaClass);
} else {
- function = getScriptFromAnnotation(javaClass);
+ function = getFromComputationMap(annotationsMapping, javaClass);
}
}
return function;
}
+
+ private LibraryFunction getFromComputationMap(ConcurrentMap<Class<?>,
LibraryFunction> map, Class<?> clazz) throws ScriptNotFoundException {
+ try {
+ return map.get(clazz);
+ } catch (ComputationException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof ScriptNotFoundException) {
+ ScriptNotFoundException snfe = (ScriptNotFoundException) cause;
+ throw snfe;
+ }
+ throw e;
+ }
+ }
- private LibraryFunction getScriptFromAnnotation(Class<?> javaClass) throws
ScriptNotFoundException {
+ private static LibraryFunction getScriptFromAnnotation(Class<?> javaClass)
throws ScriptNotFoundException {
if (javaClass.isAnnotationPresent(ClientSideScript.class)) {
ClientSideScript clientSideScript =
javaClass.getAnnotation(ClientSideScript.class);
List<ResourceKey> resources = Lists.newArrayList();
@@ -67,7 +104,7 @@
}
}
- private LibraryFunction getScriptResource(FacesContext facesContext, Class<?>
javaClass)
+ private static LibraryFunction getScriptResource(FacesContext facesContext,
Class<?> javaClass)
throws ScriptNotFoundException {
ResourceHandler resourceHandler =
facesContext.getApplication().getResourceHandler();
String resourceName = javaClass.getSimpleName() + ".js";
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -1,15 +1,18 @@
package org.richfaces.renderkit.html;
import java.io.IOException;
-import java.util.Collections;
import org.richfaces.resource.ResourceKey;
+import com.google.common.collect.ImmutableSet;
+
public class AjaxOnlyScript extends ValidatorScriptBase {
- public static final Iterable<ResourceKey> AJAX_LIBRARIES =
Collections.singleton(ResourceKey.create("ajax.reslib",
- "org.richfaces"));
+ public static final ResourceKey AJAX_RESOURCE =
ResourceKey.create("ajax.reslib",
+ "org.richfaces");
+ public static final Iterable<ResourceKey> AJAX_LIBRARIES =
ImmutableSet.of(AJAX_RESOURCE,ClientOnlyScript.CSV_RESOURCE);
+
private final String ajaxScript;
public AjaxOnlyScript(String ajaxScript) {
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -5,7 +5,8 @@
import org.richfaces.resource.ResourceKey;
-import com.google.common.collect.Iterables;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
public class ClientAndAjaxScript extends ClientOnlyScript{
@@ -19,7 +20,10 @@
Collection<? extends LibraryScriptFunction> validatorScripts, String
ajaxScript) {
super(clientSideConverterScript,validatorScripts);
this.ajaxScript = ajaxScript;
- resources =
Iterables.concat(AjaxOnlyScript.AJAX_LIBRARIES,super.getResources());
+ Builder<ResourceKey> builder = ImmutableSet.<ResourceKey>builder();
+ builder.add(AjaxOnlyScript.AJAX_RESOURCE);
+ builder.addAll(super.getResources());
+ resources = builder.build();
}
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -15,7 +15,7 @@
public class ClientOnlyScript extends ValidatorScriptBase {
- private static final ResourceKey CSV_RESOURCE =
ResourceKey.create("csv.reslib", "org.richfaces");
+ public static final ResourceKey CSV_RESOURCE =
ResourceKey.create("csv.reslib", "org.richfaces");
protected final LibraryScriptFunction converter;
protected final ImmutableList<? extends LibraryScriptFunction> validators;
private final ImmutableSet<ResourceKey> resources;
@@ -26,13 +26,13 @@
this.converter = clientSideConverterScript;
this.validators = ImmutableList.copyOf(validatorScripts);
LinkedHashSet<ResourceKey> resources = Sets.newLinkedHashSet();
+ resources.add(CSV_RESOURCE);
if (null != converter) {
Iterables.addAll(resources, converter.getResources());
}
for (LibraryScriptFunction scriptString : validators) {
Iterables.addAll(resources, scriptString.getResources());
}
- resources.add(CSV_RESOURCE);
this.resources = ImmutableSet.copyOf(resources);
}
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -450,13 +450,15 @@
}
private Collection<String>
extractMessages(Set<ConstraintViolation<Object>> violations) {
- Collection<String> messages = null;
+ Collection<String> messages;
if (null != violations && violations.size() > 0) {
messages = new ArrayList<String>(violations.size());
for (ConstraintViolation<? extends Object> constraintViolation :
violations) {
messages.add(constraintViolation.getMessage());
}
+ } else {
+ messages = Collections.emptySet();
}
return messages;
}
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/ConverterServiceImpl.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/ConverterServiceImpl.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/ConverterServiceImpl.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -5,6 +5,7 @@
import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.convert.BigDecimalConverter;
@@ -37,9 +38,9 @@
* @see
org.richfaces.validator.FacesConverterService#getConverterDescription(javax.faces.context.FacesContext,
* javax.faces.convert.Converter)
*/
- public ConverterDescriptor getConverterDescription(FacesContext context, Converter
converter) {
+ public ConverterDescriptor getConverterDescription(FacesContext context,
EditableValueHolder input, Converter converter) {
// determine converter message.
- FacesMessage message = getMessage(context, converter);
+ FacesMessage message = getMessage(context, converter, input);
ConverterDescriptorImpl descriptor = new
ConverterDescriptorImpl(converter.getClass(), message);
fillParameters(descriptor, converter);
descriptor.makeImmutable();
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -37,8 +37,6 @@
import org.richfaces.application.ServiceTracker;
import org.richfaces.cdk.annotations.JsfValidator;
-import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.cdk.annotations.TagType;
import com.google.common.base.Strings;
@@ -48,7 +46,7 @@
* @author asmirnov
*
*/
-@JsfValidator(id=FacesBeanValidator.BEAN_VALIDATOR_TYPE,tag=(a)Tag(name="beanValidator",type=TagType.Facelets))
+(a)JsfValidator(id=FacesBeanValidator.BEAN_VALIDATOR_TYPE)
public class FacesBeanValidator implements Serializable, Validator, GraphValidator {
public static final String BEAN_VALIDATOR_TYPE =
"org.richfaces.BeanValidator";
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -7,6 +7,8 @@
import java.lang.reflect.InvocationTargetException;
import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import com.google.common.collect.ImmutableSet;
@@ -50,11 +52,23 @@
*
* @param context
* @param component
+ * @param input TODO
* @return
*/
- public FacesMessage getMessage(FacesContext context, T component) {
+ public FacesMessage getMessage(FacesContext context, T component, EditableValueHolder
input) {
String messageId = getMessageId(component);
return MessageFactory.createMessage(context, messageId);
}
+
+ protected void setLabelParameter(EditableValueHolder input, FacesValidatorDescriptor
descriptor) {
+ if (input instanceof UIComponent) {
+ UIComponent component = (UIComponent) input;
+ Object label = component.getAttributes().get("label");
+ if(null!=label){
+ descriptor.addParameter("label", label);
+ }
+ }
+ }
+
}
\ No newline at end of file
Modified:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -4,6 +4,7 @@
package org.richfaces.validator;
import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.DoubleRangeValidator;
@@ -19,15 +20,20 @@
*/
public class FacesValidatorServiceImpl extends FacesServiceBase<Validator>
implements FacesValidatorService {
+ private static final String PATTERN = "pattern";
+ private static final String MINIMUM = "min";
+ private static final String MAXIMUM = "max";
+
/*
* (non-Javadoc)
*
* @see
org.richfaces.validator.FacesValidatorService#getValidatorDescription(javax.faces.context.FacesContext,
* javax.faces.validator.Validator)
*/
- public ValidatorDescriptor getValidatorDescription(FacesContext context, Validator
validator) {
- FacesMessage message = getMessage(context, validator);
+ public ValidatorDescriptor getValidatorDescription(FacesContext context,
EditableValueHolder input, Validator validator) {
+ FacesMessage message = getMessage(context, validator, input);
FacesValidatorDescriptor descriptor = new
FacesValidatorDescriptor(validator.getClass(), message);
+ setLabelParameter(input, descriptor);
fillParameters(descriptor, validator);
descriptor.makeImmutable();
return descriptor;
@@ -39,7 +45,7 @@
String messageId;
if (component instanceof DoubleRangeValidator) {
DoubleRangeValidator validator = (DoubleRangeValidator) component;
- if(validator.getMaximum() > Double.MIN_VALUE){
+ if(validator.getMaximum() < Double.MAX_VALUE){
if(validator.getMinimum()> Double.MIN_VALUE){
messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
} else {
@@ -65,13 +71,13 @@
}
} else if (component instanceof LongRangeValidator) {
LongRangeValidator validator = (LongRangeValidator) component;
- if(validator.getMaximum() >0){
- if(validator.getMinimum()>0){
+ if(validator.getMaximum() !=0){
+ if(validator.getMinimum()!=0){
messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
} else {
messageId = LongRangeValidator.MAXIMUM_MESSAGE_ID;
}
- } else if( validator.getMinimum()>0){
+ } else if( validator.getMinimum()!=0){
messageId = LongRangeValidator.MINIMUM_MESSAGE_ID;
} else {
messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use
for that case ( no min/max set, validator always pass ).
@@ -86,4 +92,40 @@
return messageId;
}
+ @Override
+ protected void fillParameters(BaseFacesObjectDescriptor<Validator> descriptor,
Validator component) {
+ if (component instanceof DoubleRangeValidator) {
+ DoubleRangeValidator validator = (DoubleRangeValidator) component;
+ if(validator.getMaximum() < Double.MAX_VALUE){
+ descriptor.addParameter(MAXIMUM, validator.getMaximum());
+ }
+ if( validator.getMinimum()>Double.MIN_VALUE){
+ descriptor.addParameter(MINIMUM, validator.getMinimum());
+ }
+ } else if (component instanceof LengthValidator) {
+ LengthValidator validator = (LengthValidator) component;
+ if(validator.getMaximum() >0){
+ descriptor.addParameter(MAXIMUM, validator.getMaximum());
+ }
+ if( validator.getMinimum()>0){
+ descriptor.addParameter(MINIMUM, validator.getMinimum());
+ }
+ } else if (component instanceof LongRangeValidator) {
+ LongRangeValidator validator = (LongRangeValidator) component;
+ if(validator.getMaximum() !=0){
+ descriptor.addParameter(MAXIMUM, validator.getMaximum());
+ }
+ if( validator.getMinimum()!=0){
+ descriptor.addParameter(MINIMUM, validator.getMinimum());
+ }
+ } else if (component instanceof RegexValidator) {
+ RegexValidator validator = (RegexValidator) component;
+ descriptor.addParameter(PATTERN, validator.getPattern());
+ } else if (component instanceof RequiredValidator) {
+ // do nothing.
+ } else {
+ super.fillParameters(descriptor, component);
+ }
+
+ }
}
Added:
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/view/facelets/html/GraphValidatorHandler.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/view/facelets/html/GraphValidatorHandler.java
(rev 0)
+++
branches/4.0.X/ui/validator/ui/src/main/java/org/richfaces/view/facelets/html/GraphValidatorHandler.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.view.facelets.html;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ComponentSystemEvent;
+import javax.faces.event.ComponentSystemEventListener;
+import javax.faces.event.PostAddToViewEvent;
+import javax.faces.validator.BeanValidator;
+import javax.faces.validator.Validator;
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
+
+import org.richfaces.component.AbstractGraphValidator;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class GraphValidatorHandler extends ComponentHandler {
+
+ private static final String BUILT_IN_BEAN_VALIDATOR_ATTRIBUTE_NAME =
GraphValidatorHandler.class.getName()
+ + ":BUILT_IN_BEAN_VALIDATOR_ATTRIBUTE_NAME";
+
+ private class FacesBeanValidatorAddListener implements ComponentSystemEventListener,
StateHolder {
+
+ public void processEvent(ComponentSystemEvent event) throws
AbortProcessingException {
+ FacesContext context = FacesContext.getCurrentInstance();
+ Validator childrenValidator = createChildrenValidator(context,
event.getComponent());
+ setupValidators(context, event.getComponent(), childrenValidator);
+ }
+
+ public Object saveState(FacesContext context) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isTransient() {
+ return true;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public GraphValidatorHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ private Validator getBuiltInBeanValidator(FacesContext context) {
+ Validator result = (Validator)
context.getAttributes().get(BUILT_IN_BEAN_VALIDATOR_ATTRIBUTE_NAME);
+
+ if (result == null) {
+ result =
context.getApplication().createValidator(BeanValidator.VALIDATOR_ID);
+ context.getAttributes().put(BUILT_IN_BEAN_VALIDATOR_ATTRIBUTE_NAME, result);
+ }
+
+ return result;
+ }
+
+ private void setupValidators(FacesContext context, UIComponent component, Validator
validator) {
+ if (component.getChildCount() == 0 && component.getFacetCount() == 0) {
+ return;
+ }
+
+ Iterator<UIComponent> facetsAndChildren =
component.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = facetsAndChildren.next();
+ if (child instanceof EditableValueHolder) {
+ EditableValueHolder input = (EditableValueHolder) child;
+ setupValidator(context, input, validator);
+ }
+
+ if (!(child instanceof AbstractGraphValidator)) {
+ //don't setup validators for nested GVs
+ setupValidators(context, child, validator);
+ }
+
+ }
+ }
+
+ /**
+ * @param context TODO
+ * @param input
+ */
+ private void setupValidator(FacesContext context, EditableValueHolder input,
Validator beanValidator) {
+ boolean addBeanValidator = true;
+ Class<?> validatorToRemoveClass =
getBuiltInBeanValidator(context).getClass();
+ Validator validatorToRemove = null;
+
+ Validator[] validators = input.getValidators();
+ for (int i = 0; i < validators.length; i++) {
+ Validator nextValidator = validators[i];
+ if (nextValidator.getClass().equals(beanValidator.getClass())) {
+ addBeanValidator = false;
+ continue;
+ }
+
+ if (nextValidator.getClass().equals(validatorToRemoveClass)) {
+ validatorToRemove = nextValidator;
+ }
+ }
+
+ if (validatorToRemove != null) {
+ input.removeValidator(validatorToRemove);
+ }
+
+ if (addBeanValidator) {
+ input.addValidator(beanValidator);
+ }
+ }
+
+ private Validator createChildrenValidator(FacesContext context, UIComponent c) {
+ AbstractGraphValidator graphValidator = (AbstractGraphValidator) c;
+
+ return graphValidator.createChildrenValidator(context);
+ }
+
+ @Override
+ public void applyNextHandler(FaceletContext ctx, UIComponent c) throws IOException,
FacesException, ELException {
+ super.applyNextHandler(ctx, c);
+
+ if (c.isInView()) {
+ setupValidators(ctx.getFacesContext(), c,
createChildrenValidator(ctx.getFacesContext(), c));
+ } else {
+ c.subscribeToEvent(PostAddToViewEvent.class, new
FacesBeanValidatorAddListener());
+ }
+ }
+}
Modified: branches/4.0.X/ui/validator/ui/src/main/resources/META-INF/csv.xml
===================================================================
--- branches/4.0.X/ui/validator/ui/src/main/resources/META-INF/csv.xml 2011-02-27 15:05:18
UTC (rev 21967)
+++ branches/4.0.X/ui/validator/ui/src/main/resources/META-INF/csv.xml 2011-02-27 18:30:19
UTC (rev 21968)
@@ -176,4 +176,20 @@
</resource>
<function>RichFaces.csv.validateMax</function>
</component>
+ <component>
+ <type>javax.validation.constraints.AssertTrue</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateTrue</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.AssertFalse</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateFalse</function>
+ </component>
</scripts>
\ No newline at end of file
Modified:
branches/4.0.X/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
branches/4.0.X/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-02-27
18:30:19 UTC (rev 21968)
@@ -36,6 +36,12 @@
return value;
}
+ var getLabel = function(component,id){
+ if(component.p){
+ return component.p.label || id;
+ }
+ return id;
+ }
$.extend(rf.csv, {
RE_DIGITS: /^-?\d+$/,
@@ -63,9 +69,10 @@
var converter = params.c;
rf.csv.clearMessage(id);
if (converter) {
+ var label=getLabel(converter,id);
try {
if (converter.f)
- convertedValue = converter.f(value,id,converter.p,converter.m);
+ convertedValue = converter.f(value,id,getLabel(converter,id),converter.m);
} catch (e){
e.severity=2;
rf.csv.sendMessage(id, e);
@@ -74,30 +81,33 @@
} else {
convertedValue = value;
}
+ var result = true
var validators = params.v;
if (validators) {
- var validatorFunction;
- try {
+ var validatorFunction,validator;
for (i=0;i<validators.length;i++) {
- validatorFunction = validators[i].f;
- if (validatorFunction) {
- validatorFunction(convertedValue,id, validators[i].p,validators[i].m);
+ try {
+ validator=validators[i];
+ validatorFunction = validator.f;
+ if (validatorFunction) {
+ validatorFunction(convertedValue,getLabel(validator,id),
validator.p,validator.m);
+ }
+ } catch (e) {
+ e.severity=2;
+ rf.csv.sendMessage(id, e);
+ result = false;
}
}
- } catch (e) {
- e.severity=2;
- rf.csv.sendMessage(id, e);
- return false;
- }
}
- if(!params.da && params.a){
+ if(!result && !params.da && params.a){
params.a.call(element,event,id);
}
- return true;
+ return result;
},
});
- /* convert all natural number formats
+ /*
+ * convert all natural number formats
*
*/
var _convertNatural = function(value,label,msg,min,max,sample){
@@ -164,14 +174,14 @@
});
var validateRange = function(value,label,params,msg) {
- var isMinSet = typeof params.minimum === "number" ;//&&
params.minimum >0;
- var isMaxSet = typeof params.maximum === "number" ;//&&
params.maximum >0;
+ var isMinSet = typeof params.min === "number" ;// && params.min
>0;
+ var isMaxSet = typeof params.max === "number" ;// && params.max
>0;
- if (isMaxSet && value > params.maximum) {
- throw
rf.csv.interpolateMessage(msg,isMinSet?[params.minimum,params.maximum,label]:[params.maximum,label]);
+ if (isMaxSet && value > params.max) {
+ throw
rf.csv.interpolateMessage(msg,isMinSet?[params.min,params.max,label]:[params.max,label]);
}
- if (isMinSet && value < params.minimum) {
- throw
rf.csv.interpolateMessage(msg,isMaxSet?[params.minimum,params.maximum,label]:[params.minimum,label]);
+ if (isMinSet && value < params.min) {
+ throw
rf.csv.interpolateMessage(msg,isMaxSet?[params.min,params.max,label]:[params.min,label]);
}
};
@@ -231,7 +241,7 @@
},
"validateSize": function (value,label,params,msg) {
var length = value?value.length:0;
- validateRange(length,label,{maximum:params.max,minimum:params.min},msg);
+ validateRange(length,label,params,msg);
},
"validateRegex": function (value,label,params,msg) {
validateRegex(value,label,params.pattern,msg);
@@ -244,6 +254,16 @@
throw rf.csv.interpolateMessage(msg, [label]);
}
},
+ "validateTrue": function (value,label,params,msg) {
+ if (!value ) {
+ throw msg;
+ }
+ },
+ "validateFalse": function (value,label,params,msg) {
+ if (value ) {
+ throw msg;
+ }
+ },
"validateMax": function (value,label,params,msg) {
if (value > params.value ) {
throw msg;
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetConverterTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetConverterTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetConverterTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -45,7 +45,7 @@
public void setupService() {
expect(factory.getInstance(FacesConverterService.class)).andStubReturn(converterService);
converterCapture = new Capture<Converter>();
-
expect(converterService.getConverterDescription(eq(environment.getFacesContext()),
capture(converterCapture)))
+
expect(converterService.getConverterDescription(same(environment.getFacesContext()),
same(input), capture(converterCapture)))
.andStubReturn(descriptor);
ServiceTracker.setFactory(factory);
}
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorGetValidatorTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -107,7 +107,7 @@
ValidatorDescriptor validatorDescriptor =
environment.createMock(ValidatorDescriptor.class);
expect((Class)
validatorDescriptor.getImplementationClass()).andStubReturn(validator.getClass());
expect(validatorDescriptor.getMessage()).andStubReturn(VALIDATION_ERROR);
-
expect(facesValidatorService.getValidatorDescription(environment.getFacesContext(),
validator))
+
expect(facesValidatorService.getValidatorDescription(environment.getFacesContext(), input,
validator))
.andStubReturn(validatorDescriptor);
}
}
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -7,7 +7,7 @@
import java.util.Locale;
import java.util.Map;
-import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
import javax.faces.component.UIViewRoot;
import org.jboss.test.faces.mock.MockFacesEnvironment;
@@ -32,7 +32,7 @@
protected final RunParameters criteria;
protected MockFacesEnvironment facesEnvironment;
- protected UIComponent component;
+ protected UIInput input;
public MockTestBase(RunParameters criteria) {
this.criteria = criteria;
@@ -42,7 +42,7 @@
@Before
public void setUp() {
this.facesEnvironment =
MockFacesEnvironment.createEnvironment().withApplication().resetToNice();
- component = facesEnvironment.createMock(UIComponent.class);
+ input = facesEnvironment.createMock(UIInput.class);
recordMocks();
facesEnvironment.replay();
}
@@ -51,8 +51,8 @@
UIViewRoot viewRoot = facesEnvironment.createMock(UIViewRoot.class);
expect(viewRoot.getLocale()).andStubReturn(Locale.ENGLISH);
expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(viewRoot);
- expect(component.getAttributes()).andStubReturn(Collections.EMPTY_MAP);
-
expect(component.getClientId(facesEnvironment.getFacesContext())).andStubReturn(TEST_COMPONENT_ID);
+ expect(input.getAttributes()).andStubReturn(Collections.EMPTY_MAP);
+
expect(input.getClientId(facesEnvironment.getFacesContext())).andStubReturn(TEST_COMPONENT_ID);
}
@After
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -5,7 +5,6 @@
import java.util.List;
-import javax.faces.convert.BooleanConverter;
import javax.faces.convert.ByteConverter;
import javax.faces.convert.Converter;
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -1,13 +1,10 @@
package org.richfaces.javascript.client.converter;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.*;
import javax.faces.application.FacesMessage;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
-import javax.faces.validator.Validator;
import net.sourceforge.htmlunit.corejs.javascript.JavaScriptException;
import net.sourceforge.htmlunit.corejs.javascript.NativeObject;
@@ -33,7 +30,7 @@
Converter converter = createConverter();
try {
Object convertedValue =
- converter.getAsObject(facesEnvironment.getFacesContext(), component,
criteria.getValue().toString());
+ converter.getAsObject(facesEnvironment.getFacesContext(), input,
criteria.getValue().toString());
Object jsConvertedValue =
convertOnClient(converter);
if(null != convertedValue || null != jsConvertedValue){
@@ -66,7 +63,7 @@
private Object getErrorMessage(Converter converter) {
ConverterServiceImpl converterService = new ConverterServiceImpl();
- FacesMessage message =
converterService.getMessage(facesEnvironment.getFacesContext(), converter);
+ FacesMessage message =
converterService.getMessage(facesEnvironment.getFacesContext(), converter, input);
return new Message(message);
}
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -4,7 +4,6 @@
import java.util.List;
import java.util.Map;
-import javax.faces.convert.BooleanConverter;
import javax.faces.convert.NumberConverter;
import javax.faces.convert.Converter;
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -1,11 +1,8 @@
package org.richfaces.javascript.client.converter;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
import java.util.List;
-import javax.faces.convert.BooleanConverter;
import javax.faces.convert.ShortConverter;
import javax.faces.convert.Converter;
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -18,8 +18,8 @@
*/
public class DoubleRangeValidatorTest extends ValidatorTestBase {
- private static final String MINIMUM = "minimum";
- private static final String MAXIMUM = "maximum";
+ private static final String MINIMUM = "min";
+ private static final String MAXIMUM = "max";
/**
* @param criteria
*/
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -18,8 +18,8 @@
*/
public class LengthValidatorTest extends ValidatorTestBase {
- private static final String MINIMUM = "minimum";
- private static final String MAXIMUM = "maximum";
+ private static final String MINIMUM = "min";
+ private static final String MAXIMUM = "max";
/**
* @param criteria
*/
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -18,8 +18,8 @@
*/
public class LongRangeValidatorTest extends ValidatorTestBase {
- private static final String MINIMUM = "minimum";
- private static final String MAXIMUM = "maximum";
+ private static final String MINIMUM = "min";
+ private static final String MAXIMUM = "max";
/**
* @param criteria
*/
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -4,10 +4,7 @@
package org.richfaces.javascript.client.validator;
import java.util.List;
-import java.util.Map;
-import javax.faces.validator.LengthValidator;
-import javax.faces.validator.Validator;
import javax.validation.constraints.Max;
import org.junit.runners.Parameterized.Parameters;
@@ -38,9 +35,8 @@
@Parameters
public static List<RunParameters[]> parameters() {
- return options(
-
pass(0,PROP,"number",MAXIMUM,2),pass(2,PROP,"number",MAXIMUM,2),pass(123,PROP,"number",MAXIMUM,2)
- );
+ return options(pass(0, PROP, "number", MAXIMUM, 2), pass(2, PROP,
"number", MAXIMUM, 2),
+ pass(123, PROP, "number", MAXIMUM, 2));
}
public static final class Bean {
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -49,7 +49,7 @@
public void testValidator() throws Exception {
Validator validator = createValidator();
try {
- validator.validate(facesEnvironment.getFacesContext(), component,
criteria.getValue());
+ validator.validate(facesEnvironment.getFacesContext(), input,
criteria.getValue());
validateOnClient(validator);
} catch (ValidatorException e) {
// client-side script has to throw exception too.
@@ -80,7 +80,7 @@
private Object getErrorMessage(Validator validator) {
FacesValidatorServiceImpl validatorService = new FacesValidatorServiceImpl();
- FacesMessage message =
validatorService.getMessage(facesEnvironment.getFacesContext(), validator);
+ FacesMessage message =
validatorService.getMessage(facesEnvironment.getFacesContext(), validator, input);
return new Message(message);
}
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/validator/FacesConverterServiceTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/validator/FacesConverterServiceTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/validator/FacesConverterServiceTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -70,7 +70,7 @@
public void getConverterClass() throws Exception {
converter = new BooleanConverter();
controller.replay();
- ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), converter);
+ ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), input, converter);
assertEquals(converter.getClass(),
converterDescription.getImplementationClass());
}
@@ -85,7 +85,7 @@
facesMessage = e.getFacesMessage();
}
assertNotNull(facesMessage);
- ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), converter);
+ ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), input, converter);
String summary = converterDescription.getMessage().getSummary();
summary = summary.replace("{2}", "foo");
summary = summary.replace("'{0}'", "abc");
@@ -102,7 +102,7 @@
converter.setType("both");
converter.setTimeZone(TimeZone.getTimeZone("EST"));
controller.replay();
- ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), converter);
+ ConverterDescriptor converterDescription =
serviceImpl.getConverterDescription(environment.getFacesContext(), input, converter);
Map<String, ? extends Object> additionalParameters =
converterDescription.getAdditionalParameters();
assertEquals("short",
additionalParameters.get("dateStyle"));
assertEquals("MM/DD/YYYY",
additionalParameters.get("pattern"));
Modified:
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/validator/FacesValidatorServiceTest.java
===================================================================
---
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/validator/FacesValidatorServiceTest.java 2011-02-27
15:05:18 UTC (rev 21967)
+++
branches/4.0.X/ui/validator/ui/src/test/java/org/richfaces/validator/FacesValidatorServiceTest.java 2011-02-27
18:30:19 UTC (rev 21968)
@@ -65,7 +65,7 @@
public void getConverterClass() throws Exception {
validator = new LengthValidator();
controller.replay();
- ValidatorDescriptor validatorDescription =
serviceImpl.getValidatorDescription(environment.getFacesContext(), validator);
+ ValidatorDescriptor validatorDescription =
serviceImpl.getValidatorDescription(environment.getFacesContext(), input, validator);
assertEquals(validator.getClass(),
validatorDescription.getImplementationClass());
}
@@ -80,7 +80,7 @@
facesMessage = e.getFacesMessage();
}
assertNotNull(facesMessage);
- ValidatorDescriptor validatorDescription =
serviceImpl.getValidatorDescription(environment.getFacesContext(), validator);
+ ValidatorDescriptor validatorDescription =
serviceImpl.getValidatorDescription(environment.getFacesContext(), input, validator);
String summary = validatorDescription.getMessage().getSummary();
summary = summary.replace("{0}", "foo");
assertEquals(facesMessage.getSummary(), summary);