You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/02/16 21:32:34 UTC
svn commit: r628376 - in /myfaces/orchestra/trunk/core/src/main:
java/org/apache/myfaces/orchestra/conversation/jsf/components/ConverterTag.java
tld/myfaces_orchestra.tld
Author: skitching
Date: Sat Feb 16 12:32:33 2008
New Revision: 628376
URL: http://svn.apache.org/viewvc?rev=628376&view=rev
Log:
Add converter tag that gets a converter from the managed-bean system rather than calling newInstance on it.
Added:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/ConverterTag.java (with props)
Modified:
myfaces/orchestra/trunk/core/src/main/tld/myfaces_orchestra.tld
Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/ConverterTag.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/ConverterTag.java?rev=628376&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/ConverterTag.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/ConverterTag.java Sat Feb 16 12:32:33 2008
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.orchestra.conversation.jsf.components;
+
+import javax.faces.application.Application;
+import javax.faces.component.UIComponent;
+import javax.faces.component.ValueHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.webapp.UIComponentTag;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.jsp.tagext.TagSupport;
+
+/**
+ * Works like f:converter except that the converter instance is a managed-bean
+ * instance rather than a simple class.
+ * <p>
+ * This is not actually orchestra-specific functionality; this is something
+ * that the core library could offer, or an addon library such as Tomahawk.
+ * But at the current time, no common library offers this feature and it
+ * is important, when writing a Converter that accesses an Orchestra
+ * conversation-scoped persistence context, to pulled the object from the
+ * dependency-injection framework rather than create it via newInstance.
+ * <p>
+ * An alternative to using this tag is simply to use the standard
+ * "converter" attribute available on most JSF component tags.
+ */
+public class ConverterTag extends TagSupport
+{
+ private static final long serialVersionUID = 1L;
+ private String beanName;
+
+ public ConverterTag()
+ {
+ super();
+ }
+
+ public void setBeanName(String beanName)
+ {
+ this.beanName = beanName;
+ }
+
+ public int doStartTag()
+ throws JspException
+ {
+ UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext);
+ if (componentTag == null)
+ {
+ throw new JspException("no parent UIComponentTag found");
+ }
+ if (!componentTag.getCreated())
+ {
+ return Tag.SKIP_BODY;
+ }
+
+ Converter converter = createConverter(beanName);
+
+ UIComponent component = componentTag.getComponentInstance();
+ if (component == null)
+ {
+ throw new JspException("parent UIComponentTag has no UIComponent");
+ }
+ if (!(component instanceof ValueHolder))
+ {
+ throw new JspException("UIComponent is no ValueHolder");
+ }
+ ((ValueHolder)component).setConverter(converter);
+
+ return Tag.SKIP_BODY;
+ }
+
+ public void release()
+ {
+ super.release();
+ beanName = null;
+ }
+
+ protected static Converter createConverter(String beanName)
+ throws JspException
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Application application = facesContext.getApplication();
+ Object converter = application.getVariableResolver().resolveVariable(facesContext, beanName);
+ return (Converter) converter;
+ }
+}
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/ConverterTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/orchestra/trunk/core/src/main/tld/myfaces_orchestra.tld
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/tld/myfaces_orchestra.tld?rev=628376&r1=628375&r2=628376&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/tld/myfaces_orchestra.tld (original)
+++ myfaces/orchestra/trunk/core/src/main/tld/myfaces_orchestra.tld Sat Feb 16 12:32:33 2008
@@ -77,4 +77,22 @@
context
</description>
</tag>
+ <tag>
+ <name>converter</name>
+ <tag-class>org.apache.myfaces.orchestra.conversation.jsf.components.ConverterTag</tag-class>
+ <body-content>empty</body-content>
+ <description>
+ Add the specified managed-bean as a Converter for the parent UIComponent.
+ </description>
+ <attribute>
+ <name>beanName</name>
+ <required>true</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ A literal expression (not an EL expression) containing the name of the
+ managed-bean to use. This managed-bean must implement the Converter
+ interface, and should be of scope 'none'.
+ </description>
+ </attribute>
+ </tag>
</taglib>