Source Code Cross Referenced for InputValue.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » webapp » pseudotag » 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 » ERP CRM Financial » ofbiz » org.ofbiz.webapp.pseudotag 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         *******************************************************************************/package org.ofbiz.webapp.pseudotag;
019:
020:        import java.io.IOException;
021:        import java.util.Map;
022:        import javax.servlet.jsp.PageContext;
023:
024:        import org.ofbiz.base.util.UtilFormatOut;
025:        import org.ofbiz.entity.GenericValue;
026:
027:        /**
028:         * InputValue Pseudo-Tag
029:         * Outputs a string for an input box from either an entity field or
030:         *  a request parameter. Decides which to use by checking to see if the entityattr exist and
031:         *  using the specified field if it does. If the Boolean object referred to by the tryentityattr
032:         *  attribute is false, always tries to use the request parameter and ignores the entity field.
033:         */
034:        public class InputValue {
035:
036:            PageContext pageContextInternal = null;
037:
038:            public InputValue(PageContext pageContextInternal) {
039:                this .pageContextInternal = pageContextInternal;
040:            }
041:
042:            public void run(String field, String entityAttr) throws IOException {
043:                run(field, null, entityAttr, null, null, null,
044:                        pageContextInternal);
045:            }
046:
047:            public void run(String field, String entityAttr,
048:                    String tryEntityAttr) throws IOException {
049:                run(field, null, entityAttr, tryEntityAttr, null, null,
050:                        pageContextInternal);
051:            }
052:
053:            public void run(String field, String entityAttr,
054:                    String tryEntityAttr, String fullattrsStr)
055:                    throws IOException {
056:                run(field, null, entityAttr, tryEntityAttr, null, fullattrsStr,
057:                        pageContextInternal);
058:            }
059:
060:            /** Run the InputValue Pseudo-Tag, all fields except field, and entityAttr can be null */
061:            public void run(String field, String param, String entityAttr,
062:                    String tryEntityAttr, String defaultStr, String fullattrsStr)
063:                    throws IOException {
064:                run(field, param, entityAttr, tryEntityAttr, defaultStr,
065:                        fullattrsStr, pageContextInternal);
066:            }
067:
068:            /* --- STATIC METHODS --- */
069:
070:            public static void run(String field, String entityAttr,
071:                    PageContext pageContext) throws IOException {
072:                run(field, null, entityAttr, null, null, null, pageContext);
073:            }
074:
075:            public static void run(String field, String entityAttr,
076:                    String tryEntityAttr, PageContext pageContext)
077:                    throws IOException {
078:                run(field, null, entityAttr, tryEntityAttr, null, null,
079:                        pageContext);
080:            }
081:
082:            public static void run(String field, String entityAttr,
083:                    String tryEntityAttr, String fullattrsStr,
084:                    PageContext pageContext) throws IOException {
085:                run(field, null, entityAttr, tryEntityAttr, null, fullattrsStr,
086:                        pageContext);
087:            }
088:
089:            /** Run the InputValue Pseudo-Tag, all fields except field, entityAttr, and pageContext can be null */
090:            public static void run(String field, String param,
091:                    String entityAttr, String tryEntityAttr, String defaultStr,
092:                    String fullattrsStr, PageContext pageContext)
093:                    throws IOException {
094:                if (field == null || entityAttr == null || pageContext == null) {
095:                    throw new RuntimeException(
096:                            "Required parameter (field or entityAttr or pageContext) missing");
097:                }
098:
099:                if (defaultStr == null)
100:                    defaultStr = "";
101:                String inputValue = null;
102:                boolean tryEntity = true;
103:                boolean fullattrs = false;
104:
105:                String paramName = param;
106:
107:                if (paramName == null || paramName.length() == 0)
108:                    paramName = field;
109:
110:                Boolean tempBool = null;
111:
112:                if (tryEntityAttr != null)
113:                    tempBool = (Boolean) pageContext
114:                            .findAttribute(tryEntityAttr);
115:                if (tempBool != null)
116:                    tryEntity = tempBool.booleanValue();
117:
118:                // if anything but true, it will be false, ie default is false
119:                fullattrs = "true".equals(fullattrsStr);
120:
121:                if (tryEntity) {
122:                    Object entTemp = pageContext.findAttribute(entityAttr);
123:
124:                    if (entTemp != null) {
125:                        if (entTemp instanceof  GenericValue) {
126:                            GenericValue entity = (GenericValue) entTemp;
127:                            Object fieldVal = entity.get(field);
128:
129:                            if (fieldVal != null)
130:                                inputValue = fieldVal.toString();
131:                        } else if (entTemp instanceof  Map) {
132:                            Map map = (Map) entTemp;
133:                            Object fieldVal = map.get(field);
134:
135:                            if (fieldVal != null)
136:                                inputValue = fieldVal.toString();
137:                        } // else do nothing
138:                    }
139:                } else {
140:                    // Current code will only get a parameter if we are not trying to get
141:                    // fields from the entity/map
142:                    // OLD WAY:
143:                    // if nothing found in entity, or if not checked, try a parameter
144:                    // if (inputValue == null) {
145:                    inputValue = pageContext.getRequest().getParameter(
146:                            paramName);
147:                }
148:
149:                if (inputValue == null || inputValue.length() == 0)
150:                    inputValue = defaultStr;
151:
152:                if (fullattrs) {
153:                    inputValue = UtilFormatOut.replaceString(inputValue, "\"",
154:                            """);
155:                    pageContext.getOut().print(
156:                            "name=\"" + paramName + "\" value=\"" + inputValue
157:                                    + "\"");
158:                } else {
159:                    pageContext.getOut().print(inputValue);
160:                }
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.