myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svieu...@apache.org
Subject cvs commit: incubator-myfaces/webapps/examples/web aliasBean.jsp
Date Thu, 27 Jan 2005 01:59:45 GMT
svieujot    2005/01/26 17:59:45

  Modified:    tlds     myfaces_ext.tld
               src/components/org/apache/myfaces/custom/aliasbean
                        AliasBeanTag.java AliasBean.java
               webapps/examples/web aliasBean.jsp
  Log:
  AliasBean : Change sourceBean attribute for value.
  Make it work with both beans references ( #{myBean} ), and fix strings as value.
  Document tld.
  
  Revision  Changes    Path
  1.158     +14 -2     incubator-myfaces/tlds/myfaces_ext.tld
  
  Index: myfaces_ext.tld
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/tlds/myfaces_ext.tld,v
  retrieving revision 1.157
  retrieving revision 1.158
  diff -u -r1.157 -r1.158
  --- myfaces_ext.tld	26 Jan 2005 12:50:15 -0000	1.157
  +++ myfaces_ext.tld	27 Jan 2005 01:59:44 -0000	1.158
  @@ -1771,20 +1771,32 @@
           <name>aliasBean</name>
           <tag-class>org.apache.myfaces.custom.aliasbean.AliasBeanTag</tag-class>
           <body-content>JSP</body-content>
  +        <description>
  +            A tage that defines a new bean (alias) with a given value.<br/>
  +            This allows you to design a subform with a fictive bean and to include it in
all the pages where you use it.
  +			You just need to make an alias to the real bean named after the fictive bean before
including the subform.
  +        </description>
           <attribute>
               <name>id</name>
               <required>false</required>
               <rtexprvalue>false</rtexprvalue>
           </attribute>
           <attribute>
  -            <name>sourceBean</name>
  +            <name>alias</name>
               <required>true</required>
               <rtexprvalue>false</rtexprvalue>
  +            <description>
  +                The name of the bean that will be set to the given value.
  +            </description>
           </attribute>
           <attribute>
  -            <name>alias</name>
  +            <name>value</name>
               <required>true</required>
               <rtexprvalue>false</rtexprvalue>
  +            <description>
  +                The value that the alias can be set to.<br/>
  +				This can be a string (like <code>"toto"</code>) or a reference to an existing
bean (like <code>"#{myBean.member1}"</code>).
  +            </description>
           </attribute>
       </tag>
       
  
  
  
  1.4       +11 -8     incubator-myfaces/src/components/org/apache/myfaces/custom/aliasbean/AliasBeanTag.java
  
  Index: AliasBeanTag.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/aliasbean/AliasBeanTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AliasBeanTag.java	23 Nov 2004 11:03:35 -0000	1.3
  +++ AliasBeanTag.java	27 Jan 2005 01:59:45 -0000	1.4
  @@ -23,6 +23,11 @@
    * @author Sylvain Vieujot (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.4  2005/01/27 01:59:45  svieujot
  + * AliasBean : Change sourceBean attribute for value.
  + * Make it work with both beans references ( #{myBean} ), and fix strings as value.
  + * Document tld.
  + *
    * Revision 1.3  2004/11/23 11:03:35  svieujot
    * Get ride of the x:aliasBean "permanent" attribute.
    *
  @@ -34,15 +39,15 @@
    *
    */
   public class AliasBeanTag extends UIComponentTagBase {
  -    
  -    private String _sourceBean;
  +
       private String _alias;
  +    private String _valueExpression;
       
       protected void setProperties(UIComponent component) {
           super.setProperties(component);
   
  -        setStringProperty(component, "sourceBean", _sourceBean);
           setStringProperty(component, "alias", _alias);
  +        setStringProperty(component, "value", _valueExpression);
       }
       
       public String getComponentType() {
  @@ -53,11 +58,11 @@
           return null;
       }
       
  -    public void setSourceBean(String sourceBean){
  -        _sourceBean = sourceBean;
  -    }
  -    
       public void setAlias(String alias){
           _alias = alias;
       }
  +    
  +    public void setValue(String valueExpression){
  +        _valueExpression = valueExpression;
  +    }
   }
  \ No newline at end of file
  
  
  
  1.6       +42 -19    incubator-myfaces/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.java
  
  Index: AliasBean.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AliasBean.java	4 Jan 2005 15:41:06 -0000	1.5
  +++ AliasBean.java	27 Jan 2005 01:59:45 -0000	1.6
  @@ -44,15 +44,21 @@
    * generic subforms.
    * 
    * @author Sylvain Vieujot (latest modification by $Author$)
  - * @version $Revision$ $Date$ $Log$
  - * @version $Revision: 1.4 $ $Date: 2004/11/23 11:03:35 $ Revision 1.5  2005/01/04 15:41:06
 svieujot
  - * @version $Revision: 1.4 $ $Date: 2004/11/23 11:03:35 $ new x:buffer component.
  - * @version $Revision: 1.4 $ $Date: 2004/11/23 11:03:35 $
  - * @version $Revision$ $Date$ Revision 1.4  2004/11/23 11:03:35  svieujot
  - * @version $Revision$ $Date$ Get ride of the x:aliasBean "permanent" attribute.
    * @version $Revision$ $Date$
  - *          Revision 1.3 2004/11/23 04:46:40 svieujot Add an ugly "permanent"
  - *          tag to x:aliasBean to handle children events.
  + * $Log$
  + * Revision 1.6  2005/01/27 01:59:45  svieujot
  + * AliasBean : Change sourceBean attribute for value.
  + * Make it work with both beans references ( #{myBean} ), and fix strings as value.
  + * Document tld.
  + *
  + * Revision 1.5  2005/01/04 15:41:06  svieujot
  + * new x:buffer component.
  + *
  + * Revision 1.4  2004/11/23 11:03:35  svieujot
  + * Get ride of the x:aliasBean "permanent" attribute.
  + * 
  + * Revision 1.3 2004/11/23 04:46:40 svieujot Add an ugly "permanent"
  + * tag to x:aliasBean to handle children events.
    * 
    * Revision 1.2 2004/11/14 15:06:36 svieujot Improve AliasBean to make the alias
    * effective only within the tag body
  @@ -67,7 +73,7 @@
       public static final String COMPONENT_FAMILY = "javax.faces.Data";
       private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.AliasBean";
   
  -    private String _sourceBeanExpression = null;
  +    private String _valueExpression = null;
   
       private String _aliasBeanExpression = null;
   
  @@ -80,6 +86,16 @@
       public String getFamily() {
           return COMPONENT_FAMILY;
       }
  +    
  +    public String getValue(){
  +        if (_valueExpression != null)
  +            return _valueExpression;
  +        ValueBinding vb = getValueBinding("value");
  +        return vb != null ? (String)vb.getValue(getFacesContext()) : null;
  +    }
  +    public void setValue(String valueExpression){
  +        this._valueExpression = valueExpression;
  +    }
   
       public Object saveState(FacesContext context) {
           log.debug("saveState");
  @@ -88,7 +104,7 @@
   
           Object values[] = new Object[3];
           values[0] = super.saveState(context);
  -        values[1] = _sourceBeanExpression;
  +        values[1] = _valueExpression;
           values[2] = _aliasBeanExpression;
           return values;
       }
  @@ -100,7 +116,7 @@
   
           Object values[] = (Object[]) state;
           super.restoreState(context, values[0]);
  -        _sourceBeanExpression = (String) values[1];
  +        _valueExpression = (String) values[1];
           _aliasBeanExpression = (String) values[2];
       }
   
  @@ -212,15 +228,24 @@
       }
   
       private void makeAlias() {
  -        ValueBinding sourceBeanVB;
  -        if (_sourceBeanExpression == null) {
  -            sourceBeanVB = getValueBinding("sourceBean");
  -            _sourceBeanExpression = sourceBeanVB.getExpressionString();
  -        } else {
  -            sourceBeanVB = _context.getApplication().createValueBinding(_sourceBeanExpression);
  +        Object value;
  +        
  +        ValueBinding valueVB = null;
  +        if (_valueExpression == null) {
  +            valueVB = getValueBinding("value");
  +            _valueExpression = valueVB.getExpressionString();
           }
   
  -        Object _sourceBean = sourceBeanVB.getValue(_context);
  +        if( valueVB == null ){
  +            if( _valueExpression.startsWith("#{") ){
  +                valueVB = _context.getApplication().createValueBinding(_valueExpression);
  +                value = valueVB.getValue(_context);
  +            }else{
  +                value = _valueExpression;
  +            }
  +        }else{
  +            value = valueVB.getValue(_context);
  +        }
   
           ValueBinding aliasVB;
           if (_aliasBeanExpression == null) {
  @@ -230,9 +255,9 @@
               aliasVB = _context.getApplication().createValueBinding(_aliasBeanExpression);
           }
   
  -        aliasVB.setValue(_context, _sourceBean);
  +        aliasVB.setValue(_context, value);
   
  -        log.debug("makeAlias: " + _sourceBeanExpression + " = " + _aliasBeanExpression);
  +        log.debug("makeAlias: " + _valueExpression + " = " + _aliasBeanExpression);
       }
   
       void removeAlias(FacesContext context) {
  @@ -241,7 +266,7 @@
       }
   
       private void removeAlias() {
  -        log.debug("removeAlias: " + _sourceBeanExpression + " != " + _aliasBeanExpression);
  +        log.debug("removeAlias: " + _valueExpression + " != " + _aliasBeanExpression);
   
           ValueBinding aliasVB = getValueBinding("alias");
           aliasVB.setValue(_context, null);
  
  
  
  1.5       +11 -2     incubator-myfaces/webapps/examples/web/aliasBean.jsp
  
  Index: aliasBean.jsp
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/webapps/examples/web/aliasBean.jsp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- aliasBean.jsp	23 Nov 2004 11:03:35 -0000	1.4
  +++ aliasBean.jsp	27 Jan 2005 01:59:45 -0000	1.5
  @@ -67,7 +67,7 @@
   
   				<h:form>
   					<f:verbatim><h2>aliasTest1</h2></f:verbatim>
  -					<x:aliasBean sourceBean="#{aliasTest1}" alias="#{holder}">
  +					<x:aliasBean alias="#{holder}" value="#{aliasTest1}" >
   						<f:subview id="simulatedIncludedSubform1">
   							<%-- The next tags could be inserted by an %@ include or jsp:include --%>
   							<h:outputLabel for="name" value="Name :"/>
  @@ -76,7 +76,7 @@
   					</x:aliasBean>
   
   					<f:verbatim><h2>aliasTest2</h2></f:verbatim>
  -					<x:aliasBean sourceBean="#{aliasTest2}" alias="#{holder}">
  +					<x:aliasBean alias="#{holder}" value="#{aliasTest2}" >
   						<f:subview id="simulatedIncludedSubform2">
   							<%-- The next tags could be inserted by an %@ include or jsp:include --%>
   							<h:outputLabel for="name" value="Name :"/>
  @@ -84,6 +84,15 @@
   							<h:commandButton value="toUpperCase" action="#{holder.toUpperCase}"/>
   						</f:subview>
   					</x:aliasBean>
  +					
  +					<f:verbatim><h2>aliasTest with fixed string</h2></f:verbatim>
  +					<x:aliasBean alias="#{holder}" value="myFixedString" >
  +						<f:subview id="simulatedIncludedSubform3">
  +							<%-- The next tags could be inserted by an %@ include or jsp:include --%>
  +							<h:outputLabel for="string" value="Fixed value :"/>
  +	    	                <h:outputText id="string" value="#{holder}"/>
  +						</f:subview>
  +					</x:aliasBean>
   
   					<f:verbatim><br/><br/></f:verbatim>
   
  
  
  

Mime
View raw message