Jsf Utility : JavaServer Faces « J2EE « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » J2EE » JavaServer Faces 




Jsf Utility
 
/*
 * BEGIN_HEADER - DO NOT EDIT
 
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the "License").  You may not use this file except
 * in compliance with the License.
 *
 * You can obtain a copy of the license at
 * https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL
 * HEADER in each file and include the License file at
 * https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
 * If applicable add the following below this CDDL HEADER,
 * with the fields enclosed by brackets "[]" replaced with
 * your own identifying information: Portions Copyright
 * [year] [name of copyright owner]
 */

/*
 * @(#)JsfUtility.java 
 *
 * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
 
 * END_HEADER - DO NOT EDIT
 */


import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;
import javax.faces.component.UIComponent;


public class JsfUtility {

    protected JsfUtility() {
        super();
    }

    /**
     * Helper method to set value expression property.
     *
     @param component The UIComponent to set a value expression for.
     @param name The name of the value expression property.
     @param expression The expresion for the value expression.
     */
    public static void setValueExpression(UIComponent component, String name, 
            String expression) {
        if (expression == null) {
            return;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        component.setValueExpression(name, createValueExpression(
    context, expression, Object.class));
    }
    
    /**
     * Helper method to set a method expression property.
     * Create a method expression that returns String and has no
     * input paramaters.
     *   
     @param component The UIComponent to set a value binding for.     
     @param name The name of the method expression property
     @param expression The expression to create.
     */
    public static void setMethodExpression(UIComponent component,
      String name, String expression) {
  setMethodExpression(component, name, expression,
    Object.class, new Class[0]);
    }
    /**
     * Helper method to set a method expression property.
     *   
     @param component The UIComponent to set a value binding for.     
     @param name The name of the method expression property
     @param expression The expression to create.
     */
    public static void setMethodExpression(UIComponent component,
      String name, String expression, Class out, Class[] in) {
        if (expression == null) {
            return;
        }
        FacesContext context = FacesContext.getCurrentInstance();
        component.getAttributes().put(name, 
      createMethodExpression(context, expression, out, in));
    }

    public static MethodExpression createMethodExpression(
      FacesContext context, String expr, Class out, Class[] in) {

  return context.getApplication().getExpressionFactory().
      createMethodExpression(context.getELContext(), expr, out, in);
    }

    public static ValueExpression createValueExpression(
      FacesContext context, String expr, Class value) {

  return context.getApplication().getExpressionFactory().
      createValueExpression(context.getELContext(), expr, value);
    }
}

   
  














Related examples in the same category
1.Change Bean Property
2.Hello World JSF
3.JavaServer Faces
4.jsf jpa war
5.Gathers all select items from specified component's children
6.Converts UISelectMany submitted value to converted value
7.Simple utility class for CSS style formatting
8.Common static utility methods that help in implementing JSF tags
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.