Source Code Cross Referenced for GuestBook.java in  » J2EE » wicket » wicket » examples » ajax » builtin » 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 » J2EE » wicket » wicket.examples.ajax.builtin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package wicket.examples.ajax.builtin;
002:
003:        import java.util.ArrayList;
004:        import java.util.Date;
005:        import java.util.List;
006:
007:        import wicket.Component;
008:        import wicket.ajax.AjaxRequestTarget;
009:        import wicket.ajax.IAjaxCallDecorator;
010:        import wicket.ajax.calldecorator.AjaxCallDecorator;
011:        import wicket.ajax.form.AjaxFormSubmitBehavior;
012:        import wicket.examples.guestbook.Comment;
013:        import wicket.markup.html.WebMarkupContainer;
014:        import wicket.markup.html.basic.Label;
015:        import wicket.markup.html.basic.MultiLineLabel;
016:        import wicket.markup.html.form.Form;
017:        import wicket.markup.html.form.TextArea;
018:        import wicket.markup.html.list.ListItem;
019:        import wicket.markup.html.list.ListView;
020:        import wicket.model.CompoundPropertyModel;
021:        import wicket.model.Model;
022:        import wicket.model.PropertyModel;
023:
024:        /**
025:         * Ajax enabled example for the guestbook.
026:         * 
027:         * @author Martijn Dashorst
028:         */
029:        public class GuestBook extends BasePage {
030:            /** A global list of all comments from all users across all sessions */
031:            public static final List commentList = new ArrayList();
032:
033:            /** The list view that shows comments */
034:            private final ListView commentListView;
035:            /** Container for the comments, used to update the listview.  */
036:            private WebMarkupContainer comments;
037:
038:            /** The textarea for entering the comments, is updated in the ajax call. */
039:            private Component text;
040:
041:            /**
042:             * Constructor.
043:             */
044:            public GuestBook() {
045:                // Add comment form
046:                CommentForm commentForm = new CommentForm("commentForm");
047:                add(commentForm);
048:
049:                // the WebMarkupContainer is used to update the listview in an ajax call
050:                comments = new WebMarkupContainer("comments");
051:                add(comments.setOutputMarkupId(true));
052:
053:                // Add commentListView of existing comments
054:                comments.add(commentListView = new ListView("comments",
055:                        new PropertyModel(this , "commentList")) {
056:                    public void populateItem(final ListItem listItem) {
057:                        final Comment comment = (Comment) listItem
058:                                .getModelObject();
059:                        listItem.add(new Label("date", new Model(comment
060:                                .getDate())));
061:                        listItem.add(new MultiLineLabel("text", comment
062:                                .getText()));
063:                    }
064:                });
065:
066:                // we need to cancel the standard submit of the form in the onsubmit handler,
067:                // otherwise we'll get double submits. To do so, we return false after the
068:                // ajax submit has occurred.
069:
070:                // The AjaxFormSubmitBehavior already calls the onSubmit of the form, all
071:                // we need to do in the onSubmit(AjaxRequestTarget) handler is do our Ajax
072:                // specific stuff, like rendering our components.
073:                commentForm.add(new AjaxFormSubmitBehavior(commentForm,
074:                        "onsubmit") {
075:                    protected IAjaxCallDecorator getAjaxCallDecorator() {
076:                        return new AjaxCallDecorator() {
077:                            public CharSequence decorateScript(
078:                                    CharSequence script) {
079:                                return script + "return false;";
080:                            }
081:                        };
082:                    }
083:
084:                    protected void onSubmit(AjaxRequestTarget target) {
085:                        // add the list of components that need to be updated
086:                        target.addComponent(comments);
087:                        target.addComponent(text);
088:
089:                        // focus the textarea again
090:                        target.appendJavascript("document.getElementById('"
091:                                + text.getMarkupId() + "').focus();");
092:                    }
093:                });
094:            }
095:
096:            /**
097:             * A form that allows a user to add a comment.
098:             * 
099:             * @author Jonathan Locke
100:             */
101:            public final class CommentForm extends Form {
102:                /**
103:                 * Constructor
104:                 * 
105:                 * @param id
106:                 *            The name of this component
107:                 */
108:                public CommentForm(final String id) {
109:                    // Construct form with no validation listener
110:                    super (id, new CompoundPropertyModel(new Comment()));
111:
112:                    // Add text entry widget
113:                    text = new TextArea("text").setOutputMarkupId(true);
114:                    add(text);
115:                }
116:
117:                /**
118:                 * Show the resulting valid edit
119:                 */
120:                public final void onSubmit() {
121:                    // Construct a copy of the edited comment
122:                    final Comment comment = (Comment) getModelObject();
123:                    final Comment newComment = new Comment(comment);
124:
125:                    // Set date of comment to add
126:                    newComment.setDate(new Date());
127:
128:                    // Add the component we edited to the list of comments
129:                    commentList.add(0, newComment);
130:
131:                    // Clear out the text component
132:                    comment.setText("");
133:                }
134:            }
135:
136:            /**
137:             * Clears the comments.
138:             */
139:            public static void clear() {
140:                commentList.clear();
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.