Changes for page Your First Stateful Project
Last modified by Bastian Triller on 2021/08/07 03:59
From version 12.1
edited by Pascal Robert
on 2012/08/09 04:59
on 2012/08/09 04:59
Change comment:
There is no comment for this version
To version 18.1
edited by Pascal Robert
on 2012/12/12 07:59
on 2012/12/12 07:59
Change comment:
Migrated to Confluence 5.3
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,7 +5,3 @@ 1 -{{info}} 2 -Work in progress 3 -{{/info}} 4 - 5 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 6 7 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. ... ... @@ -15,17 +15,17 @@ 15 15 16 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 17 18 -[[image:Capture d’écran 2012-08-06 à 04.56.13.png ||border="1"]]14 +[[image:attach:Capture d’écran 2012-08-06 à 04.56.13.png]] 19 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**. 16 +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 21 22 -[[image:Capture d’écran 2012-07-29 à 14.25.46.png ||border="1"]]18 +[[image:attach:Capture d’écran 2012-07-29 à 14.25.46.png]] 23 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:20 +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 25 26 -[[image:Capture d’écran 2012-08-06 à 05.15.32.png ||border="1"]]22 +[[image:attach:Capture d’écran 2012-08-06 à 05.15.32.png]] 27 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. 24 +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 29 30 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 31 ... ... @@ -74,7 +74,7 @@ 74 74 75 75 {{/code}} 76 76 77 -[[ERXBatchingDisplayGroup>>http://jenkins.wocommunity.org/job/Wonder/lastSuccessfulBuild/javadoc/er/extensions/appserver/ERXDisplayGroup.html]] is a subclass of WODisplayGroup, a utility that adds multiple actions and logic to a list of objects. One of the best features of ERXBatchingDisplayGroup is that it does real batching (if the RDBMS that you use supports it), so that means that if we specify a batch of 20 objects (//dg.setNumberOfObjectsPerBatch(20)//), it will fetch only the first 20 objects from the database, and if you switch to the next batch, the display group will go to the database to get the next 20 objects. ERXBatchingDisplayGroup is useful if you known that your list will contains hundred of objects. 73 +[[ERXBatchingDisplayGroup>>url:http://jenkins.wocommunity.org/job/Wonder/lastSuccessfulBuild/javadoc/er/extensions/appserver/ERXDisplayGroup.html||shape="rect"]] is a subclass of WODisplayGroup, a utility that adds multiple actions and logic to a list of objects. One of the best features of ERXBatchingDisplayGroup is that it does real batching (if the RDBMS that you use supports it), so that means that if we specify a batch of 20 objects (//dg.setNumberOfObjectsPerBatch(20)//), it will fetch only the first 20 objects from the database, and if you switch to the next batch, the display group will go to the database to get the next 20 objects. ERXBatchingDisplayGroup is useful if you known that your list will contains hundred of objects. 78 78 79 79 Let's edit the component. Open **Main.wo** and edit the content in the top panel to be: 80 80 ... ... @@ -138,8 +138,18 @@ 138 138 139 139 {{/code}} 140 140 141 -Save the file. N ext:weneed toadd a componentto present the login form to theuser. Right-click on the **Components** folderin the project,andselect **New** > **WOComponent**. Changethename ofthe component to be **AdminMainPage**and changee superclass to**er.extensions.components.ERXComponent**.137 +Save the file. Now open Author.java and add the following method: 142 142 139 +{{code}} 140 +public static Author validateLogin(EOEditingContext editingContext, String _emailAddress) { 141 + Author user = Author.fetchAuthor(ERXEC.newEditingContext(), Author.EMAIL.eq(_emailAddress)); 142 + return user; 143 +} 144 + 145 +{{/code}} 146 + 147 +Next: we need to add a component to present the login form to the user. Right-click on the **Components** folder in the project, and select **New** -> **WOComponent**. Change the name of the component to be **AdminMainPage** and change the superclass to **er.extensions.components.ERXComponent**. 148 + 143 143 After the component have been created, open **AdminMainPage.java** and override the content of the class with the following code: 144 144 145 145 {{code}} ... ... @@ -233,22 +233,22 @@ 233 233 234 234 {{/code}} 235 235 236 -You will notice that we are using a ERXBatchingDisplayGroup again. But this time, when we call dg.setObjectArray//, we set the array of objects so that only the blog entries created by the logged author are displayed. //242 +You will notice that we are using a ERXBatchingDisplayGroup again. But this time, when we call _//dg.setObjectArray//, we set the array of objects so that only the blog entries created by the logged author are displayed. 237 237 238 238 Open **AdminMainPage.wo** and override all the content between the <body> tag to be: 239 239 240 240 {{code}} 241 241 242 - 248 +<wo:AjaxUpdateContainer id="main"> 243 243 <wo:if condition="$isLogged"> 244 244 <wo:if condition="$displayGroup.hasMultipleBatches"> 245 245 <div> 246 246 <wo:link action="$displayGroup.displayPreviousBatch">Previous</wo:link> 247 - | Batch 253 + | Batch 248 248 <wo:str value="$displayGroup.currentBatchIndex" /> 249 - of 255 + of 250 250 <wo:str value="$displayGroup.batchCount" /> 251 - | 257 + | 252 252 <wo:link action="$displayGroup.displayNextBatch">Next</wo:link> 253 253 </div> 254 254 </wo:if> ... ... @@ -365,7 +365,7 @@ 365 365 366 366 {{code}} 367 367 368 - 374 +<wo:form> 369 369 <div> 370 370 <label>Title:</label> 371 371 <wo:textfield value="$blogEntry.title" /> ... ... @@ -384,16 +384,16 @@ 384 384 385 385 {{code}} 386 386 387 - 393 +public WOActionResults editBlogEntry() { 388 388 EditBlogEntry nextPage = pageWithName(EditBlogEntry.class); 389 389 nextPage.setBlogEntry(_blogEntryItem); 390 390 return nextPage; 391 391 } 392 - 398 + 393 393 public WOActionResults createBlogEntry() { 394 394 EditBlogEntry nextPage = pageWithName(EditBlogEntry.class); 395 395 nextPage.setBlogEntry(null); 396 - return nextPage; 402 + return nextPage; 397 397 } 398 398 399 399 {{/code}} ... ... @@ -422,4 +422,4 @@ 422 422 423 423 {{/code}} 424 424 425 -Save everything, run the app, click on the "admin" link, login and check if you can create or edit a blog entry. Everything should be working, and just created your first stateful Project Wonder application! 431 +Save everything, run the app, click on the "admin" link, login and check if you can create or edit a blog entry. Everything should be working, and just created your first stateful Project Wonder application! [[It's time to deploy an application>>doc:Your First Deployment]].