Author: alexsmirnov
Date: 2008-07-09 13:50:32 -0400 (Wed, 09 Jul 2008)
New Revision: 9499
Added:
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java
trunk/sandbox/ui/beanValidator/src/main/config/component/beanValidator.xml
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/component/UIBeanValidator.java
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/renderkit/html/BeanValidatorRenderer.java
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/validator/FacesBeanValidator.java
Log:
Flash mime-type was added to a resources builder.
bean validator setup moved from component to a tags.
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java 2008-07-09
17:45:16 UTC (rev 9498)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java 2008-07-09
17:50:32 UTC (rev 9499)
@@ -105,6 +105,7 @@
renderers.put(".xhtml", new
MimeRenderer("application/xhtml+xml"));
renderers.put(".xml", new MimeRenderer("text/xml"));
renderers.put(".xcss", new TemplateCSSRenderer());
+ renderers.put(".swf", new
MimeRenderer("application/x-shockwave-flash"));
// renderers.put(".htc",new BehaviorRenderer());
// set in-memory caching ImageIO
ImageIO.setUseCache(false);
Modified: trunk/sandbox/ui/beanValidator/src/main/config/component/beanValidator.xml
===================================================================
--- trunk/sandbox/ui/beanValidator/src/main/config/component/beanValidator.xml 2008-07-09
17:45:16 UTC (rev 9498)
+++ trunk/sandbox/ui/beanValidator/src/main/config/component/beanValidator.xml 2008-07-09
17:50:32 UTC (rev 9499)
@@ -18,14 +18,12 @@
<name>ajaxValidator</name>
<classname>org.richfaces.taglib.AjaxValidatorTag</classname>
<superclass>
- org.ajax4jsf.webapp.taglib.HtmlComponentTagBase
+ org.richfaces.taglib.AjaxValidatorTagBase
</superclass>
</tag>
- <!--
- <taghandler>
- <classname>org.ajax4jsf.tag.TestHandler</classname>
- </taghandler>
- -->
+ <taghandler>
+ <classname>org.richfaces.taglib.AjaxValidatorHandler</classname>
+ </taghandler>
&ui_component_attributes;
&ajax_component_attributes;
<property el="false">
Modified:
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/component/UIBeanValidator.java
===================================================================
---
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/component/UIBeanValidator.java 2008-07-09
17:45:16 UTC (rev 9498)
+++
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/component/UIBeanValidator.java 2008-07-09
17:50:32 UTC (rev 9499)
@@ -35,6 +35,8 @@
public static final String COMPONENT_TYPE = "org.richfaces.BeanValidator";
public static final String COMPONENT_FAMILY =
"org.richfaces.BeanValidator";
+
+ public static final String BEAN_VALIDATOR_FACET =
"org.richfaces.validator.";
@Override
public void setParent(UIComponent parent) {
@@ -55,23 +57,6 @@
throw new FaceletException("Parent component must be an
EditableValueHolder");
}
- Validator[] validators = ((EditableValueHolder) parent).getValidators();
-
- boolean isFacesValidatorPresent = false;
- for (Validator validator : validators) {
- if (validator instanceof FacesBeanValidator) {
- isFacesValidatorPresent = true;
- break;
- }
- }
-
- if (!isFacesValidatorPresent) {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- FacesBeanValidator validator = (FacesBeanValidator)
facesContext.getApplication().createValidator(
- "org.richfaces.BeanValidator");
- ((EditableValueHolder) parent).addValidator(validator);
- }
-
if (null != getEvent()) {
ValueExpression binding = new EventValueExpression(this);
parent.setValueExpression(getEvent(), binding);
Modified:
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/renderkit/html/BeanValidatorRenderer.java
===================================================================
---
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/renderkit/html/BeanValidatorRenderer.java 2008-07-09
17:45:16 UTC (rev 9498)
+++
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/renderkit/html/BeanValidatorRenderer.java 2008-07-09
17:50:32 UTC (rev 9499)
@@ -53,6 +53,7 @@
public class BeanValidatorRenderer extends AjaxComponentRendererBase {
+ public static final String RENDERER_TYPE =
"org.richfaces.BeanValidatorRenderer";
public BeanValidatorRenderer () {
super();
}
Added:
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
===================================================================
---
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
(rev 0)
+++
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java 2008-07-09
17:50:32 UTC (rev 9499)
@@ -0,0 +1,96 @@
+/**
+ *
+ */
+package org.richfaces.taglib;
+
+import java.io.IOException;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.webapp.taglib.AjaxComponentHandler;
+import org.richfaces.component.UIBeanValidator;
+import org.richfaces.validator.FacesBeanValidator;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.FaceletException;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.TagException;
+import com.sun.facelets.tag.TagHandler;
+import com.sun.facelets.tag.jsf.ComponentConfig;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxValidatorHandler extends TagHandler {
+
+ /**
+ * A UIComponent for capturing a child UIComponent, representative of the
+ * desired Facet
+ *
+ * @author Jacob Hookom
+ *
+ */
+ private final static class UIFacet extends UIComponentBase {
+ public String getFamily() {
+ return null;
+ }
+ }
+
+ private TagAttribute _event;
+ private AjaxComponentHandler _validatorHandler;
+
+ /**
+ * @param config
+ */
+ public AjaxValidatorHandler(ComponentConfig config) {
+ super(config);
+ _event = getAttribute("event");
+ _validatorHandler = new AjaxComponentHandler(config);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void apply(FaceletContext ctx, UIComponent parent)
+ throws IOException, FacesException, FaceletException, ELException {
+ if (parent == null || !(parent instanceof EditableValueHolder)) {
+ throw new TagException(this.tag,
+ "Parent not an instance of EditableValueHolder: " + parent);
+ }
+ if (null == parent.getParent()) {
+ // New created component, add validator.
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ FacesBeanValidator validator = (FacesBeanValidator) facesContext
+ .getApplication().createValidator(
+ FacesBeanValidator.BEAN_VALIDATOR_TYPE);
+ ((EditableValueHolder) parent).addValidator(validator);
+ }
+ if (null != this._event) {
+ UIComponent c;
+ UIFacet facet = new UIFacet();
+ // Find facet for client validation component
+ String eventName = _event.getValue();
+ String facetName = UIBeanValidator.BEAN_VALIDATOR_FACET + eventName;
+ c = parent.getFacet(facetName);
+ if (null != c) {
+ parent.getFacets().remove(facetName);
+ facet.getChildren().add(c);
+ }
+ this._validatorHandler.apply(ctx, facet);
+ c = (UIComponent) facet.getChildren().get(0);
+ parent.getFacets().put(facetName, c);
+
+ }
+ }
+
+}
Property changes on:
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
===================================================================
---
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
(rev 0)
+++
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java 2008-07-09
17:50:32 UTC (rev 9499)
@@ -0,0 +1,96 @@
+/**
+ *
+ */
+package org.richfaces.taglib;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.webapp.UIComponentClassicTagBase;
+import javax.servlet.jsp.JspException;
+
+import org.ajax4jsf.webapp.taglib.UIComponentTagBase;
+import org.richfaces.component.UIBeanValidator;
+import org.richfaces.renderkit.html.BeanValidatorRenderer;
+import org.richfaces.validator.FacesBeanValidator;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxValidatorTagBase extends UIComponentTagBase {
+
+ /**
+ * Generate script for given event ( onclick, onenter ... )
+ */
+ private String event = null;
+
+ /* (non-Javadoc)
+ * @see javax.faces.webapp.UIComponentTagBase#getComponentType()
+ */
+ @Override
+ public String getComponentType() {
+ return UIBeanValidator.COMPONENT_TYPE;
+ }
+
+ /**
+ * @param event the event to set
+ */
+ public void setEvent(String event) {
+ this.event = event;
+ }
+
+ @Override
+ public int doStartTag() throws JspException {
+ // Locate our parent UIComponentTag
+ UIComponentClassicTagBase tag =
+ UIComponentClassicTagBase.getParentUIComponentClassicTagBase(pageContext);
+ if (tag == null) {
+ //PENDING i18n
+ throw new JspException("Not nested in a UIComponentTag Error for tag
with handler class:"+
+ this.getClass().getName());
+ }
+ UIComponent component = tag.getComponentInstance();
+ if( !(component instanceof EditableValueHolder)){
+ //PENDING i18n
+ throw new JspException("Not nested in a UIInput component. Error for
tag with handler class:"+
+ this.getClass().getName());
+
+ }
+ // Nothing to do unless this tag created a component
+ if (tag.getCreated()) {
+ // New created component, add validator.
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ FacesBeanValidator validator = (FacesBeanValidator) facesContext
+ .getApplication().createValidator(
+ FacesBeanValidator.BEAN_VALIDATOR_TYPE);
+ ((EditableValueHolder) component).addValidator(validator);
+
+ }
+ return super.doStartTag();
+ }
+
+ @Override
+ protected void setProperties(UIComponent component) {
+ super.setProperties(component);
+ setStringProperty(component, "event", event);
+ }
+
+ @Override
+ public void release() {
+ super.release();
+ event = null;
+ }
+ /* (non-Javadoc)
+ * @see javax.faces.webapp.UIComponentTagBase#getRendererType()
+ */
+ @Override
+ public String getRendererType() {
+ return BeanValidatorRenderer.RENDERER_TYPE;
+ }
+
+ @Override
+ protected String getFacetName() {
+ return UIBeanValidator.BEAN_VALIDATOR_FACET + (null == event?"":event);
+ }
+}
Property changes on:
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/validator/FacesBeanValidator.java
===================================================================
---
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2008-07-09
17:45:16 UTC (rev 9498)
+++
trunk/sandbox/ui/beanValidator/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2008-07-09
17:50:32 UTC (rev 9499)
@@ -8,7 +8,7 @@
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIInput;
+import javax.faces.component.EditableValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
@@ -22,6 +22,8 @@
*/
public class FacesBeanValidator implements Validator {
+ public static final String BEAN_VALIDATOR_TYPE =
"org.richfaces.BeanValidator";
+
/*
* (non-Javadoc)
*
@@ -30,11 +32,11 @@
*/
public void validate(FacesContext context, UIComponent component,
Object convertedValue) throws ValidatorException {
- if (component instanceof UIInput) {
+ if (component instanceof EditableValueHolder) {
// Validate input component
- UIInput input = (UIInput) component;
+ EditableValueHolder input = (EditableValueHolder) component;
try {
- ValueExpression valueExpression = input
+ ValueExpression valueExpression = component
.getValueExpression("value");
if (null != valueExpression) {
// TODO - check EL Exceptions ?
@@ -44,7 +46,7 @@
input.setValid(false);
// send all validation messages.
for (String msg : messages) {
- context.addMessage(input.getClientId(context), new FacesMessage(
+ context.addMessage(component.getClientId(context), new FacesMessage(
FacesMessage.SEVERITY_ERROR, msg, ""));
}
}