You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/08/04 01:18:06 UTC
svn commit: r800616 - in
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets:
impl/ tag/jsf/ tag/jsf/core/
Author: lu4242
Date: Mon Aug 3 23:18:06 2009
New Revision: 800616
URL: http://svn.apache.org/viewvc?rev=800616&view=rev
Log:
MYFACES-2299 Add AttachedObjectHandler implementation when it is necessary
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ConverterTagHandlerDelegate.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValidatorTagHandlerDelegate.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ActionListenerHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ValueChangeListenerHandler.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java?rev=800616&r1=800615&r2=800616&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java Mon Aug 3 23:18:06 2009
@@ -90,6 +90,10 @@
_faceletHierarchy.addAll(ctx._faceletHierarchy);
_faceletHierarchy.add(facelet);
_facelet = facelet;
+
+ //Update FACELET_CONTEXT_KEY on FacesContext attribute map, to
+ //reflect the current facelet context instance
+ ctx.getFacesContext().getAttributes().put(FaceletContext.FACELET_CONTEXT_KEY, this);
}
public DefaultFaceletContext(FacesContext faces, DefaultFacelet facelet)
@@ -108,6 +112,10 @@
_varMapper = new DefaultVariableMapper();
}
_fnMapper = _ctx.getFunctionMapper();
+
+ //Set FACELET_CONTEXT_KEY on FacesContext attribute map, to
+ //reflect the current facelet context instance
+ faces.getAttributes().put(FaceletContext.FACELET_CONTEXT_KEY, this);
}
/**
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ConverterTagHandlerDelegate.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ConverterTagHandlerDelegate.java?rev=800616&r1=800615&r2=800616&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ConverterTagHandlerDelegate.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ConverterTagHandlerDelegate.java Mon Aug 3 23:18:06 2009
@@ -82,35 +82,7 @@
// only process if it's been created
if (parent.getParent() == null)
{
- // cast to a ValueHolder
- ValueHolder vh = (ValueHolder) parent;
- ValueExpression ve = null;
- Converter c = null;
- if (_delegate.getBinding() != null)
- {
- ve = _delegate.getBinding().getValueExpression(ctx, Converter.class);
- c = (Converter) ve.getValue(ctx);
- }
- if (c == null)
- {
- c = this.createConverter(ctx);
- if (ve != null)
- {
- ve.setValue(ctx, c);
- }
- }
- if (c == null)
- {
- throw new TagException(_delegate.getTag(), "No Converter was created");
- }
- _delegate.setAttributes(ctx, c);
- vh.setConverter(c);
- Object lv = vh.getLocalValue();
- FacesContext faces = ctx.getFacesContext();
- if (lv instanceof String)
- {
- vh.setValue(c.getAsObject(faces, parent, (String) lv));
- }
+ applyAttachedObject(ctx.getFacesContext(), parent);
}
}
@@ -141,14 +113,53 @@
@Override
public void applyAttachedObject(FacesContext context, UIComponent parent)
{
- // TODO Auto-generated method stub
+ // Retrieve the current FaceletContext from FacesContext object
+ FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(
+ FaceletContext.FACELET_CONTEXT_KEY);
+ // cast to a ValueHolder
+ ValueHolder vh = (ValueHolder) parent;
+ ValueExpression ve = null;
+ Converter c = null;
+ if (_delegate.getBinding() != null)
+ {
+ ve = _delegate.getBinding().getValueExpression(faceletContext, Converter.class);
+ c = (Converter) ve.getValue(faceletContext);
+ }
+ if (c == null)
+ {
+ c = this.createConverter(faceletContext);
+ if (ve != null)
+ {
+ ve.setValue(faceletContext, c);
+ }
+ }
+ if (c == null)
+ {
+ throw new TagException(_delegate.getTag(), "No Converter was created");
+ }
+ _delegate.setAttributes(faceletContext, c);
+ vh.setConverter(c);
+ Object lv = vh.getLocalValue();
+ FacesContext faces = faceletContext.getFacesContext();
+ if (lv instanceof String)
+ {
+ vh.setValue(c.getAsObject(faces, parent, (String) lv));
+ }
}
@Override
public String getFor()
{
- // TODO Auto-generated method stub
- return null;
+ TagAttribute forAttribute = _delegate.getTagAttribute("for");
+
+ if (forAttribute == null)
+ {
+ return null;
+ }
+ else
+ {
+ return forAttribute.getValue();
+ }
}
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValidatorTagHandlerDelegate.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValidatorTagHandlerDelegate.java?rev=800616&r1=800615&r2=800616&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValidatorTagHandlerDelegate.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValidatorTagHandlerDelegate.java Mon Aug 3 23:18:06 2009
@@ -67,29 +67,7 @@
// only process if it's been created
if (parent.getParent() == null)
{
- // cast to a ValueHolder
- EditableValueHolder evh = (EditableValueHolder) parent;
- ValueExpression ve = null;
- Validator v = null;
- if (_delegate.getBinding() != null)
- {
- ve = _delegate.getBinding().getValueExpression(ctx, Validator.class);
- v = (Validator) ve.getValue(ctx);
- }
- if (v == null)
- {
- v = this.createValidator(ctx);
- if (ve != null)
- {
- ve.setValue(ctx, v);
- }
- }
- if (v == null)
- {
- throw new TagException(_delegate.getTag(), "No Validator was created");
- }
- _delegate.setAttributes(ctx, v);
- evh.addValidator(v);
+ applyAttachedObject(ctx.getFacesContext(), parent);
}
}
@@ -120,15 +98,48 @@
@Override
public void applyAttachedObject(FacesContext context, UIComponent parent)
{
- // TODO Auto-generated method stub
+ // Retrieve the current FaceletContext from FacesContext object
+ FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(
+ FaceletContext.FACELET_CONTEXT_KEY);
+ // cast to a ValueHolder
+ EditableValueHolder evh = (EditableValueHolder) parent;
+ ValueExpression ve = null;
+ Validator v = null;
+ if (_delegate.getBinding() != null)
+ {
+ ve = _delegate.getBinding().getValueExpression(faceletContext, Validator.class);
+ v = (Validator) ve.getValue(faceletContext);
+ }
+ if (v == null)
+ {
+ v = this.createValidator(faceletContext);
+ if (ve != null)
+ {
+ ve.setValue(faceletContext, v);
+ }
+ }
+ if (v == null)
+ {
+ throw new TagException(_delegate.getTag(), "No Validator was created");
+ }
+ _delegate.setAttributes(faceletContext, v);
+ evh.addValidator(v);
}
@Override
public String getFor()
{
- // TODO Auto-generated method stub
- return null;
+ TagAttribute forAttribute = _delegate.getTagAttribute("for");
+
+ if (forAttribute == null)
+ {
+ return null;
+ }
+ else
+ {
+ return forAttribute.getValue();
+ }
}
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ActionListenerHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ActionListenerHandler.java?rev=800616&r1=800615&r2=800616&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ActionListenerHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ActionListenerHandler.java Mon Aug 3 23:18:06 2009
@@ -30,6 +30,7 @@
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
+import javax.faces.view.ActionSource2AttachedObjectHandler;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
import javax.faces.view.facelets.TagAttribute;
@@ -52,6 +53,7 @@
* @version $Id: ActionListenerHandler.java,v 1.7 2008/07/13 19:01:44 rlubke Exp $
*/
public final class ActionListenerHandler extends TagHandler
+ implements ActionSource2AttachedObjectHandler
{
private final static class LazyActionListener implements ActionListener, Serializable
@@ -152,14 +154,7 @@
{
if (ComponentSupport.isNew(parent))
{
- ActionSource as = (ActionSource) parent;
- ValueExpression b = null;
- if (this.binding != null)
- {
- b = this.binding.getValueExpression(ctx, ActionListener.class);
- }
- ActionListener listener = new LazyActionListener(this.listenerType, b);
- as.addActionListener(listener);
+ applyAttachedObject(ctx.getFacesContext(), parent);
}
}
else
@@ -167,4 +162,36 @@
throw new TagException(this.tag, "Parent is not of type ActionSource, type is: " + parent);
}
}
+
+ @Override
+ public void applyAttachedObject(FacesContext context, UIComponent parent)
+ {
+ // Retrieve the current FaceletContext from FacesContext object
+ FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(
+ FaceletContext.FACELET_CONTEXT_KEY);
+
+ ActionSource as = (ActionSource) parent;
+ ValueExpression b = null;
+ if (this.binding != null)
+ {
+ b = this.binding.getValueExpression(faceletContext, ActionListener.class);
+ }
+ ActionListener listener = new LazyActionListener(this.listenerType, b);
+ as.addActionListener(listener);
+ }
+
+ @Override
+ public String getFor()
+ {
+ TagAttribute forAttribute = getAttribute("for");
+
+ if (forAttribute == null)
+ {
+ return null;
+ }
+ else
+ {
+ return forAttribute.getValue();
+ }
+ }
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java?rev=800616&r1=800615&r2=800616&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SetPropertyActionListenerHandler.java Mon Aug 3 23:18:06 2009
@@ -31,6 +31,7 @@
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
+import javax.faces.view.ActionSource2AttachedObjectHandler;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
import javax.faces.view.facelets.TagAttribute;
@@ -41,6 +42,7 @@
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
public class SetPropertyActionListenerHandler extends TagHandler
+ implements ActionSource2AttachedObjectHandler
{
private final TagAttribute _target;
private final TagAttribute _value;
@@ -57,13 +59,9 @@
{
if (parent instanceof ActionSource)
{
- ActionSource src = (ActionSource) parent;
if (ComponentSupport.isNew(parent))
{
- ValueExpression valueExpr = _value.getValueExpression(ctx, Object.class);
- ValueExpression targetExpr = _target.getValueExpression(ctx, Object.class);
-
- src.addActionListener(new SetPropertyListener(valueExpr, targetExpr));
+ applyAttachedObject(ctx.getFacesContext(), parent);
}
}
else
@@ -98,4 +96,33 @@
_target.setValue(el, valueObj);
}
}
+
+ @Override
+ public void applyAttachedObject(FacesContext context, UIComponent parent)
+ {
+ // Retrieve the current FaceletContext from FacesContext object
+ FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(
+ FaceletContext.FACELET_CONTEXT_KEY);
+
+ ActionSource src = (ActionSource) parent;
+ ValueExpression valueExpr = _value.getValueExpression(faceletContext, Object.class);
+ ValueExpression targetExpr = _target.getValueExpression(faceletContext, Object.class);
+
+ src.addActionListener(new SetPropertyListener(valueExpr, targetExpr));
+ }
+
+ @Override
+ public String getFor()
+ {
+ TagAttribute forAttribute = getAttribute("for");
+
+ if (forAttribute == null)
+ {
+ return null;
+ }
+ else
+ {
+ return forAttribute.getValue();
+ }
+ }
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ValueChangeListenerHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ValueChangeListenerHandler.java?rev=800616&r1=800615&r2=800616&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ValueChangeListenerHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ValueChangeListenerHandler.java Mon Aug 3 23:18:06 2009
@@ -30,6 +30,7 @@
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;
+import javax.faces.view.EditableValueHolderAttachedObjectHandler;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
import javax.faces.view.facelets.TagAttribute;
@@ -50,6 +51,7 @@
* @version $Id: ValueChangeListenerHandler.java,v 1.2 2005/08/24 04:38:50 jhook Exp $
*/
public final class ValueChangeListenerHandler extends TagHandler
+ implements EditableValueHolderAttachedObjectHandler
{
private static class LazyValueChangeListener implements ValueChangeListener, Serializable
@@ -148,14 +150,7 @@
{
if (ComponentSupport.isNew(parent))
{
- EditableValueHolder evh = (EditableValueHolder) parent;
- ValueExpression b = null;
- if (this.binding != null)
- {
- b = this.binding.getValueExpression(ctx, ValueChangeListener.class);
- }
- ValueChangeListener listener = new LazyValueChangeListener(this.listenerType, b);
- evh.addValueChangeListener(listener);
+ applyAttachedObject(ctx.getFacesContext(), parent);
}
}
else
@@ -164,4 +159,36 @@
}
}
+ @Override
+ public void applyAttachedObject(FacesContext context, UIComponent parent)
+ {
+ // Retrieve the current FaceletContext from FacesContext object
+ FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(
+ FaceletContext.FACELET_CONTEXT_KEY);
+
+ EditableValueHolder evh = (EditableValueHolder) parent;
+ ValueExpression b = null;
+ if (this.binding != null)
+ {
+ b = this.binding.getValueExpression(faceletContext, ValueChangeListener.class);
+ }
+ ValueChangeListener listener = new LazyValueChangeListener(this.listenerType, b);
+ evh.addValueChangeListener(listener);
+ }
+
+ @Override
+ public String getFor()
+ {
+ TagAttribute forAttribute = getAttribute("for");
+
+ if (forAttribute == null)
+ {
+ return null;
+ }
+ else
+ {
+ return forAttribute.getValue();
+ }
+ }
+
}