Source Code Cross Referenced for JsfUtils.java in  » Development » JValidate » nl » knowlogy » validation » jsf » utils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » JValidate » nl.knowlogy.validation.jsf.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package nl.knowlogy.validation.jsf.utils;
002:
003:        import java.util.List;
004:
005:        import javax.faces.component.NamingContainer;
006:        import javax.faces.component.UIComponent;
007:        import javax.faces.context.FacesContext;
008:        import javax.faces.el.ValueBinding;
009:
010:        import org.apache.commons.lang.StringUtils;
011:
012:        public class JsfUtils {
013:
014:            public static String getObjectPartFromValueExpression(
015:                    String valueExpression) {
016:                int indexOfLastPoint = StringUtils.lastIndexOf(valueExpression,
017:                        '.');
018:                int indexOfLastParenthesis = StringUtils.lastIndexOf(
019:                        valueExpression, '}');
020:                return StringUtils.substring(valueExpression, 0,
021:                        indexOfLastPoint)
022:                        + "}";
023:            }
024:
025:            public static String getObjectPart(UIComponent uiComponent) {
026:                String valueExpression = uiComponent.getValueBinding("value")
027:                        .getExpressionString();
028:                return getObjectPartFromValueExpression(valueExpression);
029:            }
030:
031:            public static String getPropertyNameFromValueExpression(
032:                    String valueExpression) {
033:                int indexOfLastPoint = StringUtils.lastIndexOf(valueExpression,
034:                        '.');
035:                int indexOfLastParenthesis = StringUtils.lastIndexOf(
036:                        valueExpression, '}');
037:
038:                return StringUtils.substring(valueExpression,
039:                        indexOfLastPoint + 1, indexOfLastParenthesis);
040:
041:            }
042:
043:            public static String getPropertyNamePart(UIComponent uiComponent) {
044:                String valueExpression = uiComponent.getValueBinding("value")
045:                        .getExpressionString();
046:                return getPropertyNameFromValueExpression(valueExpression);
047:            }
048:
049:            public static Object getBindedObject(String objectExpression) {
050:                FacesContext context = FacesContext.getCurrentInstance();
051:                return getBindedObject(context, objectExpression);
052:            }
053:
054:            public static Object getBindedObject(FacesContext context,
055:                    String objectExpression) {
056:                return context.getApplication().createValueBinding(
057:                        objectExpression).getValue(context);
058:            }
059:
060:            public static Object getContainingObject(UIComponent uiComponent) {
061:                String containingObjectExpression = getObjectPart(uiComponent);
062:                FacesContext context = FacesContext.getCurrentInstance();
063:                return context.getApplication().createValueBinding(
064:                        containingObjectExpression).getValue(context);
065:            }
066:
067:            /**
068:             * Locates the component identified by <code>forComponent</code>
069:             * 
070:             * @param forComponent -
071:             *            the component to search for
072:             * @param component -
073:             *            the starting point in which to begin the search
074:             * @return the component with the the <code>id</code that matches
075:             *         <code>forComponent</code> otheriwse null if no match is found.
076:             */
077:            public static UIComponent getForComponent(FacesContext context,
078:                    String forComponent, UIComponent component) {
079:                if (null == forComponent || forComponent.length() == 0) {
080:                    return null;
081:                }
082:
083:                UIComponent result = null;
084:                UIComponent currentParent = component;
085:                try {
086:                    // Check the naming container of the current
087:                    // component for component identified by
088:                    // 'forComponent'
089:                    while (currentParent != null) {
090:                        // If the current component is a NamingContainer,
091:                        // see if it contains what we're looking for.
092:                        result = currentParent.findComponent(forComponent);
093:                        if (result != null)
094:                            break;
095:                        // if not, start checking further up in the view
096:                        currentParent = currentParent.getParent();
097:                    }
098:
099:                    // no hit from above, scan for a NamingContainer
100:                    // that contains the component we're looking for from the root.
101:                    if (result == null) {
102:                        result = findUIComponentBelow(context.getViewRoot(),
103:                                forComponent);
104:                    }
105:                } catch (Throwable t) {
106:                    // Object[] params = { forComponent };
107:                    throw new RuntimeException(""
108:                    // Util.getExceptionMessageString(Util.COMPONENT_NOT_FOUND_ERROR_MESSAGE_ID,
109:                    // params)
110:                    );
111:                }
112:
113:                return result;
114:            }
115:
116:            /**
117:             * <p>
118:             * Recursively searches for {@link NamingContainer}s from the given start
119:             * point looking for the component with the <code>id</code> specified by
120:             * <code>forComponent</code>.
121:             * 
122:             * @param startPoint -
123:             *            the starting point in which to begin the search
124:             * @param forComponent -
125:             *            the component to search for
126:             * @return the component with the the <code>id</code that matches
127:             *         <code>forComponent</code> otheriwse null if no match is found.
128:             */
129:            private static UIComponent findUIComponentBelow(
130:                    UIComponent startPoint, String forComponent) {
131:                UIComponent retComp = null;
132:                List children = startPoint.getChildren();
133:                for (int i = 0, size = children.size(); i < size; i++) {
134:                    UIComponent comp = (UIComponent) children.get(i);
135:
136:                    if (comp instanceof  NamingContainer) {
137:                        retComp = comp.findComponent(forComponent);
138:                    }
139:
140:                    if (retComp == null) {
141:                        if (comp.getChildCount() > 0) {
142:                            retComp = findUIComponentBelow(comp, forComponent);
143:                        }
144:                    }
145:
146:                    if (retComp != null)
147:                        break;
148:                }
149:                return retComp;
150:            }
151:
152:            public static boolean getBooleanAttribute(UIComponent component,
153:                    String attrName, boolean defaultValue) {
154:                Boolean b = (Boolean) component.getAttributes().get(attrName);
155:                return b != null ? b.booleanValue() : defaultValue;
156:            }
157:
158:            public static String getStringValue(FacesContext context,
159:                    ValueBinding vb) {
160:                Object value = vb.getValue(context);
161:                if (value == null) {
162:                    return null;
163:                }
164:                return value.toString();
165:            }
166:
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.