Changes for page Your First Stateful Project
Last modified by Bastian Triller on 2021/08/07 03:59
From version 2.1
edited by Pascal Robert
on 2012/01/07 22:22
on 2012/01/07 22:22
Change comment:
There is no comment for this version
To version 6.1
edited by Pascal Robert
on 2012/08/06 05:52
on 2012/08/06 05:52
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,1 +1,75 @@ 1 -Forthcoming 1 +{{info}} 2 +Work in progress 3 +{{/info}} 4 + 5 +So far, we have seen two of the technologies, D2W and ERRest, that Project Wonder offers for viewing and managing the data. In this tutorial, we will show how to do it with the "stateful" way of doing things. Stateful have been around since the beginning of WebObjects in 1996, so it's the oldest way of presenting data and constructing pages. 6 + 7 +Stateful means that you don't have to worry about creating sessions and keeping track of data coming from HTML input fields and controls. In fact, D2W is also stateful. 8 + 9 +In this tutorial, we are also going to use the Ajax framework, who is stateful too. We will replicate the functionalities of the two other tutorials, but by creating pages ourselves. The application will have the following pages: 10 + 11 +* The main page will display a list of blog entries, with a link to see the blog entry. 12 +* The main page will have a link to an "admin" page that will show a login form. 13 +* After login, a list of blog entries with links to edit, delete and create blog entries will be show. 14 +* We need a form to edit/create blog entries. 15 + 16 +Let's start by creating a new project in Eclipse. You need to create a **Wonder Application** project type, and name it **StatefulBlog**. 17 + 18 +[[image:Capture d’écran 2012-08-06 à 04.56.13.png||border="1"]] 19 + 20 +Just like the D2W tutorial, you need to link the application with the **BlogCommon**, **Ajax** and **H2PlugIn** frameworks. To do so, right-click on **StatefulBlog** and select **Build Path** > **Configure Build Path**. 21 + 22 +[[image:Capture d’écran 2012-07-29 à 14.25.46.png||border="1"]] 23 + 24 +In the **Libraries** tab, click on **Add Library**. Select **WebObjects Frameworks** and click **Next**. Check **Ajax**, **BlogCommon** and **H2PlugIn** from the list and click **Finish**. The **Libraries** tab should look like this: 25 + 26 +[[image:Capture d’écran 2012-08-06 à 05.15.32.png||border="1"]] 27 + 28 +We are ready to code Open the **Components** folder of the project, and open **Main WO**. In the **Related** view (bottom-right), you see that all related files of the component are listed, and we need to open the Java code associated with the component. To do so, in the **Related** view, double-click on **Main.java** to open the Java class into an editor. 29 + 30 +In **Main.java**, we need some Java code to get the list of blog entries so that we can show that list into the component. The following code will do what we need: 31 + 32 +{{code}} 33 + 34 +import your.app.model.BlogEntry; 35 + 36 +import com.webobjects.appserver.WOContext; 37 +import com.webobjects.eoaccess.EODatabaseDataSource; 38 +import com.webobjects.eocontrol.EOEditingContext; 39 + 40 +import er.extensions.batching.ERXBatchingDisplayGroup; 41 +import er.extensions.components.ERXComponent; 42 +import er.extensions.eof.ERXEC; 43 + 44 +public class Main extends ERXComponent { 45 + 46 + private EOEditingContext _ec; 47 + private BlogEntry _blogEntryItem; 48 + 49 + public Main(WOContext context) { 50 + super(context); 51 + EODatabaseDataSource dataSource = new EODatabaseDataSource(editingContext(), BlogEntry.ENTITY_NAME); 52 + ERXBatchingDisplayGroup<BlogEntry> dg = new ERXBatchingDisplayGroup<BlogEntry>(); 53 + dg.setNumberOfObjectsPerBatch(20); 54 + dg.setDataSource(dataSource); 55 + dg.setObjectArray(BlogEntry.fetchAllBlogEntries(editingContext(), BlogEntry.LAST_MODIFIED.descs())); 56 + } 57 + 58 + private EOEditingContext editingContext() { 59 + if (_ec == null) { 60 + _ec = ERXEC.newEditingContext(); 61 + } 62 + return _ec; 63 + } 64 + 65 + public void setBlogEntryItem(BlogEntry blogEntryItem) { 66 + this._blogEntryItem = blogEntryItem; 67 + } 68 + 69 + public BlogEntry blogEntryItem() { 70 + return this._blogEntryItem; 71 + } 72 + 73 +} 74 + 75 +{{/code}}