Source Code Cross Referenced for FormTimeInputHtmlTag.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » jsp » tag » uilib » form » element » date » 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 » Web Framework » aranea mvc 1.1.1 » org.araneaframework.jsp.tag.uilib.form.element.date 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.araneaframework.jsp.tag.uilib.form.element.date;
002:
003:        import java.io.IOException;
004:        import java.io.Writer;
005:        import java.text.ParseException;
006:        import java.util.Calendar;
007:        import javax.servlet.jsp.JspException;
008:        import org.apache.commons.lang.StringUtils;
009:        import org.araneaframework.http.util.ServletUtil;
010:        import org.araneaframework.jsp.AraneaAttributes;
011:        import org.araneaframework.jsp.UiUpdateEvent;
012:        import org.araneaframework.jsp.util.JspUtil;
013:        import org.araneaframework.jsp.util.JspWidgetCallUtil;
014:        import org.araneaframework.uilib.event.OnChangeEventListener;
015:        import org.araneaframework.uilib.form.control.TimeControl;
016:
017:        /**
018:         * Time input form element tag.
019:         * 
020:         * @author Marko Muts
021:         * @jsp.tag
022:         *   name = "timeInput"
023:         *   body-content = "JSP"
024:         *   description = "Form time input field (custom control), represents UiLib "TimeControl"."
025:         */
026:        public class FormTimeInputHtmlTag extends BaseFormDateTimeInputHtmlTag {
027:            protected boolean showTimeSelect = true;
028:            protected boolean surroundingTable = true;
029:
030:            {
031:                baseStyleClass = "aranea-time";
032:            }
033:
034:            protected int doEndTag(Writer out) throws Exception {
035:                assertControlType("TimeControl");
036:
037:                // Prepare    
038:                String name = this .getFullFieldId();
039:                TimeControl.ViewModel viewModel = ((TimeControl.ViewModel) controlViewModel);
040:
041:                Long timeInputSize = DEFAULT_TIME_INPUT_SIZE;
042:
043:                if (surroundingTable)
044:                    out
045:                            .write("<table border='0' cellpadding='0' cellspacing='0'><tr><td nowrap='true'>\n");
046:                this .writeTimeInput(out, name, name,
047:                        viewModel.getSimpleValue(), localizedLabel,
048:                        timeInputSize, viewModel.isDisabled(), accessKey);
049:
050:                Integer minute = null, hour = null;
051:                try {
052:                    if (viewModel.getSimpleValue() != null) {
053:                        Calendar calendar = Calendar.getInstance();
054:                        calendar.setTime(viewModel
055:                                .getCurrentSimpleDateTimeFormat().parse(
056:                                        viewModel.getSimpleValue()));
057:
058:                        hour = new Integer(calendar.get(Calendar.HOUR_OF_DAY));
059:                        minute = new Integer(calendar.get(Calendar.MINUTE));
060:                    }
061:                } catch (ParseException e) {
062:                    if (showTimeSelect) {
063:                        // try to preserve the contents of selects anyway
064:                        String strHour = ServletUtil.getRequest(
065:                                getOutputData().getInputData()).getParameter(
066:                                name + ".select1");
067:                        if (strHour != null && !(strHour.trim().length() == 0))
068:                            hour = Integer.valueOf(strHour.trim());
069:                        String strMinute = ServletUtil.getRequest(
070:                                getOutputData().getInputData()).getParameter(
071:                                name + ".select2");
072:                        if (strMinute != null
073:                                && !(strMinute.trim().length() == 0))
074:                            minute = Integer.valueOf(strMinute);
075:                    }
076:                }
077:
078:                if (showTimeSelect) {
079:                    writeHourSelect(out, name, viewModel.isDisabled(), hour);
080:                    writeMinuteSelect(out, name, viewModel.isDisabled(), minute);
081:                }
082:
083:                if (surroundingTable)
084:                    out.write("</td></tr></table>\n");
085:
086:                super .doEndTag(out);
087:                return EVAL_PAGE;
088:            }
089:
090:            protected void writeMinuteSelect(Writer out, String name,
091:                    boolean disabled, Integer minute) throws IOException {
092:                TimeControl.ViewModel viewModel = ((TimeControl.ViewModel) controlViewModel);
093:                out
094:                        .write("<select id=\""
095:                                + name
096:                                + ".select2\" name=\""
097:                                + name
098:                                + ".select2\" onChange=\""
099:                                + fillXJSCallConstructor(
100:                                        "Aranea.UI.fillTimeText", name, name
101:                                                + ".select1", name + ".select2")
102:                                + ";"
103:                                + ((!disabled && events && viewModel
104:                                        .isOnChangeEventRegistered()) ? JspWidgetCallUtil
105:                                        .getSubmitScriptForEvent()
106:                                        : "") + "\"");
107:
108:                if (disabled)
109:                    out.write(" disabled=\"true\"");
110:
111:                if (!disabled && events
112:                        && viewModel.isOnChangeEventRegistered()) {
113:                    UiUpdateEvent event = new UiUpdateEvent(
114:                            OnChangeEventListener.ON_CHANGE_EVENT, name, null,
115:                            updateRegionNames);
116:                    event
117:                            .setEventPrecondition(getMinuteSelectOnChangePrecondition(name));
118:                    out.write(" ");
119:                    out.write(event.getEventAttributes().toString());
120:                }
121:
122:                out.write(">\n");
123:
124:                JspUtil.writeStartTag_SS(out, "script");
125:                out.write(getTimeSelectScript(name + ".select2", minute, 60));
126:
127:                if (!disabled && backgroundValidation) {
128:                    String s = name + ".select2";
129:                    String es = "$('" + s + "')";
130:                    String ns = "$('" + name + "')";
131:                    String vcall = "formElementValidationActionCall(" + ns
132:                            + ");";
133:                    out.write("Event.observe(" + es
134:                            + ", 'change', function(event) {" + vcall + "});");
135:                }
136:
137:                JspUtil.writeEndTag_SS(out, "script");
138:
139:                JspUtil.writeEndTag_SS(out, "select");
140:            }
141:
142:            protected void writeHourSelect(Writer out, String name,
143:                    boolean disabled, Integer hour) throws IOException {
144:                TimeControl.ViewModel viewModel = ((TimeControl.ViewModel) controlViewModel);
145:                out
146:                        .write("<select id=\""
147:                                + name
148:                                + ".select1\" name=\""
149:                                + name
150:                                + ".select1\" onChange=\""
151:                                + fillXJSCallConstructor(
152:                                        "Aranea.UI.fillTimeText", name, name
153:                                                + ".select1", name + ".select2")
154:                                + ";"
155:                                + ((!disabled && events && viewModel
156:                                        .isOnChangeEventRegistered()) ? JspWidgetCallUtil
157:                                        .getSubmitScriptForEvent()
158:                                        : "") + "\"");
159:                if (disabled)
160:                    out.write(" disabled=\"true\"");
161:
162:                if (!disabled && events
163:                        && viewModel.isOnChangeEventRegistered()) {
164:                    UiUpdateEvent event = new UiUpdateEvent(
165:                            OnChangeEventListener.ON_CHANGE_EVENT, name, null,
166:                            updateRegionNames);
167:                    event
168:                            .setEventPrecondition(getHourSelectOnChangePrecondition(name));
169:                    out.write(" ");
170:                    out.write(event.getEventAttributes().toString());
171:                }
172:                out.write(">\n");
173:
174:                JspUtil.writeStartTag_SS(out, "script");
175:                out.write(getTimeSelectScript(name + ".select1", hour, 24));
176:
177:                if (!disabled && backgroundValidation) {
178:                    String s = name + ".select1";
179:                    String es = "$('" + name + "')";
180:                    String ns = "$('" + s + "')";
181:                    String vcall = "formElementValidationActionCall(" + es
182:                            + ");";
183:                    out.write("Event.observe(" + ns
184:                            + ", 'change', function(event) {" + vcall + "});");
185:                }
186:
187:                JspUtil.writeEndTag_SS(out, "script");
188:
189:                JspUtil.writeEndTag_SS(out, "select");
190:            }
191:
192:            /**
193:             * Writes out time input
194:             */
195:            protected void writeTimeInput(Writer out, String id, String name,
196:                    String value, String label, Long size, boolean disabled,
197:                    String accessKey) throws Exception {
198:                TimeControl.ViewModel viewModel = ((TimeControl.ViewModel) controlViewModel);
199:                // Write input tag
200:                JspUtil.writeOpenStartTag(out, "input");
201:                if (!StringUtils.isBlank(id))
202:                    JspUtil.writeAttribute(out, "id", id);
203:                JspUtil.writeAttribute(out, "name", name);
204:                JspUtil.writeAttribute(out, "class", getStyleClass());
205:                JspUtil.writeAttribute(out, "type", "text");
206:                JspUtil.writeAttribute(out, "value", value);
207:                JspUtil.writeAttribute(out, "size", size);
208:                JspUtil.writeAttribute(out, "tabindex", tabindex);
209:
210:                writeBackgroundValidationAttribute(out);
211:
212:                if (!disabled && events
213:                        && viewModel.isOnChangeEventRegistered()) {
214:                    JspUtil.writeAttribute(out, "onfocus",
215:                            "Aranea.UI.saveValue(this)");
216:                    UiUpdateEvent event = new UiUpdateEvent(
217:                            OnChangeEventListener.ON_CHANGE_EVENT, name, null,
218:                            updateRegionNames);
219:                    event
220:                            .setEventPrecondition(getTimeInputOnChangePrecondition(name));
221:                    out.write(" ");
222:                    out.write(event.getEventAttributes().toString());
223:                }
224:
225:                // validation won't occur with Event.observe registered in aranea-behaviour when date selected from calendar
226:                if (!viewModel.isOnChangeEventRegistered() && !disabled
227:                        && backgroundValidation) {
228:                    JspUtil.writeAttribute(out, "onchange",
229:                            "formElementValidationActionCall(this)");
230:                }
231:
232:                StringBuffer onBlur = new StringBuffer();
233:                if (showTimeSelect)
234:                    onBlur.append(fillXJSCallConstructor(
235:                            "Aranea.UI.fillTimeSelect", name,
236:                            name + ".select1", name + ".select2")
237:                            + ";");
238:                if (!disabled && events
239:                        && viewModel.isOnChangeEventRegistered())
240:                    onBlur.append(JspWidgetCallUtil.getSubmitScriptForEvent());
241:                JspUtil.writeAttribute(out, "onblur", onBlur.toString());
242:
243:                if (!StringUtils.isBlank(accessKey))
244:                    JspUtil.writeAttribute(out, "accesskey", accessKey);
245:                if (disabled)
246:                    JspUtil.writeAttribute(out, "disabled", "true");
247:
248:                JspUtil.writeAttributes(out, attributes);
249:                JspUtil.writeCloseStartEndTag_SS(out);
250:            }
251:
252:            protected String fillXJSCallConstructor(String function,
253:                    String timeInputEl, String hourSelectEl,
254:                    String minuteSelectEl) {
255:                return FormTimeInputHtmlTag.staticFillXJSCall(function,
256:                        timeInputEl, hourSelectEl, minuteSelectEl);
257:            }
258:
259:            public static final String staticFillXJSCall(String function,
260:                    String timeInputEl, String hourSelectEl,
261:                    String minuteSelectEl) {
262:                return function + "('" + timeInputEl + "', '" + hourSelectEl
263:                        + "', '" + minuteSelectEl + "')";
264:            }
265:
266:            /**
267:             * @jsp.attribute
268:             *   type = "java.lang.String"
269:             *   required = "false"
270:             *   description = "Boolean, specifying whether HTML &lt;select&;gt;'s should be shown for hour/minute selection."
271:             * 
272:             * @since 1.0.3
273:             */
274:            public void setShowTimeSelect(String showTimeSelect)
275:                    throws JspException {
276:                this .showTimeSelect = ((Boolean) evaluate("showTimeSelect",
277:                        showTimeSelect, Boolean.class)).booleanValue();
278:            }
279:
280:            /**
281:             * @jsp.attribute
282:             *   type = "java.lang.String"
283:             *   required = "false"
284:             *   description = "Boolean, specifying whether HTML &lt;table&;gt;'s should be rendered to around this time input. Default is true."
285:             * 
286:             * @since 1.1
287:             */
288:            public void setSurroundingTable(String surroundingTable)
289:                    throws JspException {
290:                this .surroundingTable = ((Boolean) evaluate("surroundingTable",
291:                        surroundingTable, Boolean.class)).booleanValue();
292:            }
293:        }
ww_w__.___ja_va_2_s__._c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.