Wiki source code of Your First Rest Project

Version 46.1 by Filippo Laurìa on 2013/07/22 12:55

Hide last authors
Filippo Laurìa 21.1 1
Filippo Laurìa 46.1 2
3 {{toc/}}
4
Pascal Robert 5.1 5 = Introduction =
6
7 In the first part of the Blog tutorial, you will learn:
8
9 * How to create a EOModel for the database (we will use H2)
10 * How to use migrations to create the database tables
11 * How to use ERRest to create blog posts with JSON format and how to display the blog posts in HTML for readers
12
Pascal Robert 30.1 13 = Create a new project =
14
15 You will need to create a new project for this tutorial. In Eclipse, open the **File** menu, select **New** and select **Wonder REST Application**. Name your project as //BlogRest//.
16
Pascal Robert 5.1 17 = Create the database model =
18
Pascal Robert 30.1 19 == Database structure ==
20
Pascal Robert 5.1 21 We will build a small database model for the blog. The database will have two tables: BlogEntry and Author.
22
23 BlogEntry will have the following columns:
24
Filippo Laurìa 46.1 25 |=(((
26 Column name
27 )))|=(((
28 Type
29 )))|=(((
30 Constraints
31 )))
32 |(((
33 id
34 )))|(((
35 integer
36 )))|(((
37 primary key
38 )))
39 |(((
40 title
41 )))|(((
42 string(255)
43 )))|(((
44
45 )))
46 |(((
47 content
48 )))|(((
49 string(4000)
50 )))|(((
51
52 )))
53 |(((
54 creationDate
55 )))|(((
56 timestamp
57 )))|(((
58
59 )))
60 |(((
61 lastModified
62 )))|(((
63 timestamp
64 )))|(((
65
66 )))
67 |(((
68 author
69 )))|(((
70 integer
71 )))|(((
72 relation with Author
73 )))
Pascal Robert 5.1 74
75 Author will have the following columns:
76
Filippo Laurìa 46.1 77 |=(((
78 Column name
79 )))|=(((
80 Type
81 )))|=(((
82 Constraints
83 )))
84 |(((
85 id
86 )))|(((
87 integer
88 )))|(((
89 primary key
90 )))
91 |(((
92 firstName
93 )))|(((
94 string(50)
95 )))|(((
96
97 )))
98 |(((
99 lastName
100 )))|(((
101 string(50)
102 )))|(((
103
104 )))
105 |(((
106 email
107 )))|(((
108 string(100)
109 )))|(((
110 unique
111 )))
Pascal Robert 5.1 112
Pascal Robert 30.1 113 == Creating the EOModel ==
114
Pascal Robert 5.1 115 To create the database, we will first create a EOModel and use migrations to build the database on the file system (H2 will take care of creating the database file).
Pascal Robert 30.1 116
117 An EOModel consists of entities, attributes and relationships. When using it in a RDBMS context, an entity is a table (or a view), an attribute is a table column and a relationship is a join between two tables.
118
Filippo Laurìa 46.1 119 To create the EOModel, in the project right-click on the project name and select **New** -> **EOModel**.
Pascal Robert 30.1 120
121 Name it **BlogModel** and in the plugin list, select **H2**. Click **Finish**.
122
123 The model should show up in a window that looks like this:
124
Filippo Laurìa 46.1 125 [[image:attach:EOModeler.png]]
126
Pascal Robert 30.1 127 If it didn't show up, the window might have opened behind the main Eclipse window. If that's the case, open the **Window** menu and select the windows that have //Entity Modeler// in its name.
128
Filippo Laurìa 46.1 129 In the Entity Modeler window, click on **Default**, and for the **URL** field, type
Pascal Robert 30.1 130
Filippo Laurìa 46.1 131 {{code}}
132 jdbc:h2:~/BlogTutorial
133 {{/code}}
134
135 . When the database will be created, it will be stored in your home directory (/Users/youruser/ on OS X).
136
Pascal Robert 30.1 137 Now, right-click on **BlogModel** and select **New Entity**.
138
139 Type the following details in the **Basic** tab:
140
141 * **Name**: BlogEntry
142 * **Table Name**: BlogEntry
143 * **Class Name**: your.app.model.BlogEntry
144
145 Now, it's time to add the entity's attributes (aka, the table's columns). You will see that the entity already have an attributed named "id". That attribute is a integer for the primary key. Leave it there.
146
147 Let's create the first attribute: the title of the blog entry. Right-click on the entity and select **New Attribute**. Type the following values:
148
149 * **Name**: title
150 * **Column**: title
151 * **Prototype**: varchar255
152
153 When you use prototypes, you don't need to define the type (varchar, int, etc.) for the database, so by using prototypes, if you switch from a RDBMS system to another one, say from H2 to MySQL, you only need to change the JDBC connection string and bundle the EOF plugin for the RDBMS, no need to switch data types in the model.
154
155 Now, repeat the last two steps to create the other attributes for the **BlogEntry** entity, with the following values:
156
Filippo Laurìa 46.1 157 |=(((
158 Attribute name
159 )))|=(((
160 Column
161 )))|=(((
162 Prototype
163 )))
164 |(((
165 content
166 )))|(((
167 content
168 )))|(((
169 longtext
170 )))
171 |(((
172 creationDate
173 )))|(((
174 creationDate
175 )))|(((
176 dateTime
177 )))
178 |(((
179 lastModified
180 )))|(((
181 lastModified
182 )))|(((
183 dateTime
184 )))
Pascal Robert 30.1 185
186 If you did everything well, the list of attributes should look like this:
187
Filippo Laurìa 46.1 188 [[image:attach:list_wlock.png]]
189
pauldlynch 36.1 190 You will notice that the attributes have a column with a lock in it. When a lock is present, it will use the value of that attribute for //UPDATE ... WHERE attribute = ''// statement. This is to do optimistic locking, aka to prevent data conflict when the data object was modified by two different users. Using timestamps for optimistic locking is not a good idea because for certain RDBMS, the value can be different because of milliseconds, so remove the locks on the **creationDate** attribute. The final list should look like this:
Pascal Robert 30.1 191
Filippo Laurìa 46.1 192 [[image:attach:list.png]]
193
Pascal Robert 30.1 194 Next step is to create the **Author** entity. Create a new entity with **Author** at its name (and also as the table name), and for the class name, use **your.app.model.Author**. The attributes for this entity are:
195
Filippo Laurìa 46.1 196 |=(((
197 Attribute name
198 )))|=(((
199 Column
200 )))|=(((
201 Prototype
202 )))
203 |(((
204 firstName
205 )))|(((
206 firstName
207 )))|(((
208 varchar50
209 )))
210 |(((
211 lastName
212 )))|(((
213 lastName
214 )))|(((
215 varchar50
216 )))
217 |(((
218 email
219 )))|(((
220 email
221 )))|(((
222 varchar100
223 )))
Pascal Robert 30.1 224
225 Final list of attributes should look like this:
226
Filippo Laurìa 46.1 227 [[image:attach:author_list.png]]
228
pauldlynch 36.1 229 Now, it's time to link the two entities together. An Author can have multiple blog entries, and a BlogEntry can only have one author. To create the relationship (the join), right-click on **Author** and select **New Relationship**. On your right, select **BlogEntry** in the list. On your left, select **to many BlogEntries**, and on your right, select **to one Author**. Now, in BlogEntry, we need to store the primary key of the author so that we can make the join. The relationship builder allow us to add that attribute, so make sure **and a new foreign key named** is checked (it is checked by default). The **Create Relationship** pane should look like this:
Pascal Robert 30.1 230
Filippo Laurìa 46.1 231 [[image:attach:relationship.png]]
232
franc 34.1 233 If you check in the **Outline** tab, you should see that **Author** now have a **blogEntries** relationship, and **BlogEntry** have a **author** relationship.
Pascal Robert 30.1 234
Filippo Laurìa 46.1 235 [[image:attach:outline_tab.png]]
Pascal Robert 30.1 236
Filippo Laurìa 46.1 237 You are now ready to save the model. Save it (File -> Save) and close the **Entity Modeler** window. If you open the **Sources** in the main Eclipse window, you will notice that the **Sources** folder contains a package named **your.app.model**. (If this folder doesn't appear, you may need to set your preferences to automatically generate these source files; see the second suggestion on [[http:~~/~~/wiki.wocommunity.org/display/documentation/Useful+Eclipse+or+WOLips+Preferences>>url:http://wiki.wocommunity.org/display/documentation/Useful+Eclipse+or+WOLips+Preferences||rel="nofollow" shape="rect" class="external-link"]].)
Pascal Robert 30.1 238
Filippo Laurìa 46.1 239
240
241 That package have four Java classes: **_Author**, **Author**, **_BlogEntry** and **BlogEntry**. Those classes were generated by Veogen, a templating engine build on Velocity. The two classes that starts with a underscore are recreated every time you change the EOModel, so if you want to change something in those classes, you need to change the template (no need for that right now). But you can change freely the two classes that don't have the underscore, and this is what we will be doing.
242
243
244
Pascal Robert 30.1 245 What we are going to do is to write a simple method that returns the full name of an author, e.g. a method that simply concatenate the first name, a space and the last name of the author. To do so, double-click on **Author.java** and add the following methods:
246
247 {{code}}
franc 34.1 248 public String fullName() {
Pascal Robert 30.1 249 return this.firstName() + " " + this.lastName();
250 }
251
252 {{/code}}
253
franc 34.1 254 Nothing fancy here. Now open **BlogEntry.java** and add the following method:
Pascal Robert 30.1 255
franc 34.1 256 {{code}}
skcodes 44.1 257 @Override
franc 34.1 258 public void awakeFromInsertion(EOEditingContext editingContext) {
skcodes 44.1 259 super.awakeFromInsertion(editingContext);
260 NSTimestamp now = new NSTimestamp();
261 setCreationDate(now);
262 setLastModified(now);
franc 34.1 263 }
264
265 {{/code}}
266
skcodes 44.1 267 Why are we adding this? **awakeFromInsertion** is a very good way of setting default values when creating a new instance of a Enterprise Object (EO). In this case, we want to set automatically the creation and last modification dates without having the user to add those values.
franc 34.1 268
269 Now, let's use migrations to actually create the database.
270
271 == Using migrations ==
272
pauldlynch 36.1 273 Migrations allow you to create the tables and columns (and some types of constraint). **Entity Modeler** has support to generate the code for the first migration, which is called "migration 0". To do that, open the EOModel (**BlogModel EOModel** in the **Resources** folder), right-click on the model name and select **Generate Migration**.
franc 34.1 274
275 Copy the generated code in the clipboard. Close **Entity Modeler** and in the main Eclipse window, right-click on **Sources**, select **New** and select **Class**.
276
277 Type **your.app.model.migrations** as the package and **BlogModel0** as the name of the class. Click **Finish**.
278
279 In the **Sources** folder, open the **your.app.model.migrations** package, a class named **BlogModel0** should be there. Delete everything in that file **EXCEPT** the first line (which should be //package your.app.model.migrations//) and paste the code that was generated by **Entity Modeler**. Save the file.
280
281 One last step: migrations are disabled by default. To enable them, you need to uncomment two properties in the **Properties** file that is located in the **Resources** folder. Open that file (double-click on it).
282
283 Remove the pound char in front of those two properties:
284
285 {{code}}
286 #er.migration.migrateAtStartup=true
287 #er.migration.createTablesIfNecessary=true
288
289 {{/code}}
290
291 After removing the pound char, the two properties should look like this:
292
293 {{code}}
294 er.migration.migrateAtStartup=true
295 er.migration.createTablesIfNecessary=true
296
297 {{/code}}
298
Filippo Laurìa 46.1 299 You are now ready to start the application so that it creates the database! To do so, right-click on **Application.java** (in the **your.app** folder) and select **Run As** -> **WOApplication**. In Eclipse's Console tab, you should see some output, including something similar to:
franc 34.1 300
301 {{code}}
302 BlogRest[62990] INFO er.extensions.migration.ERXMigrator - Upgrading BlogModel to version 0 with migration 'your.app.model.migrations.BlogModel0@4743bf3d'
303 BlogRest[62990] INFO er.extensions.jdbc.ERXJDBCUtilities - Executing CREATE TABLE Author(email VARCHAR(100) NOT NULL, firstName VARCHAR(50) NOT NULL, id INTEGER NOT NULL, lastName VARCHAR(50) NOT NULL)
304 BlogRest[62990] INFO er.extensions.jdbc.ERXJDBCUtilities - Executing ALTER TABLE Author ADD PRIMARY KEY (id)
305 BlogRest[62990] INFO er.extensions.jdbc.ERXJDBCUtilities - Executing CREATE TABLE BlogEntry(authorID INTEGER NOT NULL, content TIMESTAMP NOT NULL, creationDate TIMESTAMP NOT NULL, id INTEGER NOT NULL, title VARCHAR(255) NOT NULL)
306 BlogRest[62990] INFO er.extensions.jdbc.ERXJDBCUtilities - Executing ALTER TABLE BlogEntry ADD PRIMARY KEY (id)
307 BlogRest[62990] INFO er.extensions.jdbc.ERXJDBCUtilities - Executing ALTER TABLE BlogEntry ADD CONSTRAINT "FOREIGN_KEY_BLOGENTRY_AUTHORID_AUTHOR_ID" FOREIGN KEY (authorID) REFERENCES Author (id)
308 BlogRest[62990] DEBUG NSLog - evaluateExpression: <er.h2.jdbcadaptor.ERH2PlugIn$H2Expression: "UPDATE _dbupdater SET version = ? WHERE modelname = ?" withBindings: 1:0(version), 2:"BlogModel"(modelName)>
309
310 {{/code}}
311
Filippo Laurìa 46.1 312 If you see this and that the application is running (it should open a window in your favorite browser), migration worked and your database have been created, congratulations! You can now stop the application (click the square red button in Eclipse's Console tab) and continue to the next step.
franc 34.1 313
Pascal Robert 30.1 314 = Creating REST controllers and routes =
franc 34.1 315
316 Project Wonder contains a framework called ERRest, which follow the same patterns as Ruby on Rails REST concepts. Using REST-style URLs is perfect for building a public blog and to create REST services to manage posting over HTTP with JSON, XML or other formats.
317
318 By default, a REST route in ERRest will generate a link like this:
319
320 {{code}}
321 /cgi-bin/WebObjects/AppName.woa/ra/EntityName/id
322 {{/code}}
323
324 So for our case, to get the first blog posting from BlogRest, the URL will look like this:
325
326 {{code}}
327 /cgi-bin/WebObjects/BlogRest.woa/ra/blogEntries/1.html
328 {{/code}}
329
330 {{info}}
331 You can shorten the URL by using mod_rewrite in Apache httpd
332 {{/info}}
333
334 == Creating controllers ==
335
336 ERRest needs controllers to act as a broker between working with the objects and the routes. So let's create a controller for BlogEntry.
337
338 Create a Java class named **BlogEntryController**, in the **your.app.rest.controllers** package, that will extend from **er.rest.routes.ERXDefaultRouteController**. Click **Finish**.
339
340 When you extend from **ERXDefaultRouteController**, a bunch of methods are added to the subclass. Let's see what they are for.
341
342 * **updateAction**: to update a specific instance of BlogEntry
343 * **destroyAction**: to delete a specific instance of BlogEntry
344 * **showAction**: to get one specific instance of BlogEntry
345 * **createAction**: to create a new object (a new instance of BlogEntry)
346 * **indexAction**: to list all (or a sublist) of the objects.
347
348 {{info}}
Filippo Laurìa 46.1 349 In Project Wonder, **Action** at the end of a method is a convention for REST and Direct Actions, when you call those methods from certain components, you don't need to add the **Action** part.
franc 34.1 350 {{/info}}
351
Filippo Laurìa 46.1 352 For this tutorial, we will implement the **createAction** and **indexAction** methods. But first, we need to create a key filter. A key filter will... filter the input and the output of REST request so that you don't have to send all attributes for a blog entry. For example, we want to show the details for an author, but we don't want to show the password for the author (in real-life, the password would be encrypted)!
franc 34.1 353
354 Add this method in **BlogEntryController**:
355
356 {{code}}
357 protected ERXKeyFilter filter() {
358 ERXKeyFilter personFilter = ERXKeyFilter.filterWithAttributes();
359 personFilter.setAnonymousUpdateEnabled(true);
360
361 ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes();
362 filter.include(BlogEntry.AUTHOR, personFilter);
363 filter.setUnknownKeyIgnored(true);
364
365 return filter;
366 }
367
368 {{/code}}
369
pauldlynch 36.1 370 Now, let's implement the **createAction** method:
franc 34.1 371
372 {{code}}
373 public WOActionResults createAction() throws Throwable {
374 BlogEntry entry = create(filter());
375 editingContext().saveChanges();
376 return response(entry, filter());
377 }
378
379 {{/code}}
380
381 In 3 lines of code, you can create an object based on the request, save the new object to the database and return the new object in the response. Not bad, eh?
382
pauldlynch 36.1 383 Last step in the controller: implementing the **indexAction** method. Again, the code is simple:
franc 34.1 384
385 {{code}}
386 public WOActionResults indexAction() throws Throwable {
387 NSArray<BlogEntry> entries = BlogEntry.fetchAllBlogEntries(editingContext());
388 return response(entries, filter());
389 }
390
391 {{/code}}
392
393 That code simply fetch all blog entries and return them in the response.
394
395 We can now go to the next step: adding the routes.
396
397 == Adding the routes ==
398
399 A route in ERRest is simply a way to define the URL for the entities and to specify which controller the route should use. When your controller extends from **ERXDefaultRouteController**, it's easy to register a controller and a route. In **Application.java**, in the **Application** constructor, add the following code:
400
401 {{code}}
402 ERXRouteRequestHandler restRequestHandler = new ERXRouteRequestHandler();
403 restRequestHandler.addDefaultRoutes(BlogEntry.ENTITY_NAME);
404 ERXRouteRequestHandler.register(restRequestHandler);
405 setDefaultRequestHandler(restRequestHandler);
406
407 {{/code}}
408
409 The **addDefaultRoutes** method do all of the required magic, and use convention. That's why we had to name the controller **BlogEntryController**, because the convention is <EntityName>Controller.
410
Filippo Laurìa 46.1 411 We are now reading to add and list blog postings! Start the application and take notice of the URL. It should be something like _[[http:~~/~~/yourip:someport/cgi-bin/WebObjects/BlogRest.woa_>>url:http://youripsomeport||shape="rect"]]
franc 34.1 412
413 == Adding posts and authors with curl ==
414
415 Since we didn't implement any HTML for our REST routes, we will create blog entries with //curl//, an open source HTTP client that is bundled with Mac OS X (you can use another client, like wget, if you like too). So let's create a blog entry.
416
Filippo Laurìa 46.1 417 To create a blog entry, you need to use the POST HTTP method. We will use JSON as the format since it's a bit less chatty than XML. So if the URL to the application is //[[http:~~/~~/192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa_>>url:http://192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa_||shape="rect"]], the full _curl// command will be:
franc 34.1 418
419 {{code}}
420 curl -X POST -v -d '{ "title": "First post", "content": "Some text", "author": { "firstName": "Pascal", "lastName": "Robert", "email": "probert@macti.ca" } }' http://192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa/ra/blogEntries.json
421 {{/code}}
422
423 The response should look this:
424
425 {{code}}
426 HTTP/1.0 201 Apple WebObjects
427 Content-Length: 249
428 x-webobjects-loadaverage: 0
429 Content-Type: application/json
430
431 {"id":1,"type":"BlogEntry","content":"Some text","creationDate":"2011-12-27T21:59:08Z","title":"First post","author":{"id":1,"type":"Author","email":"probert@macti.ca","firstName":"Pascal","lastName":"Robert"}}
432
433 {{/code}}
434
435 To get a list of blog entries:
436
437 {{code}}
438 curl -X GET http://192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa/ra/blogEntries.json
439
440 {{/code}}
441
442 You can stop the application and proceed to the next step.
443
444 == Adding HTML views for blog posts ==
445
446 Now, let's build a HTML view for blog posts (you don't want your readers to get your posts by JSON, right?). Again, we will use convention to make it work easily. Open up **BlogEntryController** and add the following method:
447
448 {{code}}
449 @Override
450 protected boolean isAutomaticHtmlRoutingEnabled() {
451 return true;
452 }
453
454 {{/code}}
455
Filippo Laurìa 46.1 456 Switching the return value of this method says that we will follow a certain convention for HTML components. The convention for automatic HTML routing is that the component should be named <EntityName><Action>Page.wo. So in our case, the component will be **BlogEntryIndexPage**. Right-click on the project name in Eclipse and select **New** -> **WOComponent**. Change the name to **BlogEntryIndexPage** and check the **Create HTML contents** button. Click **Finish**.
franc 34.1 457
pauldlynch 36.1 458 The next step to get it to work is to make **BlogEntryIndexPage** to implement the **er.rest.routes.IERXRouteComponent** interface.
franc 34.1 459
460 {{code}}
461 import er.rest.routes.IERXRouteComponent;
462
463 public class BlogEntryIndexPage extends WOComponent implements IERXRouteComponent {
464
465 {{/code}}
466
467 So now, the automatic HTML routing will send the request for **ra/blogEntries.html** to the **BlogEntryIndexPage** component. But we don't have any content in this component, so let's make a method to fetch all blog entries per creation date in descending order. So in **BlogEntryIndexPage.java**, add the following method:
468
469 {{code}}
470 public NSArray<BlogEntry> entries() {
471 EOEditingContext ec = ERXEC.newEditingContext();
472 return BlogEntry.fetchAllBlogEntries(ec, BlogEntry.CREATION_DATE.descs());
473 }
474
475 {{/code}}
476
477 We need to use that method in a WORepetition, and for that loop, we need a BlogEntry variable to iterate in the list, so add the following code to **BlogEntryIndexPage.java**:
478
479 {{code}}
480 private BlogEntry entryItem;
481
482 public BlogEntry entryItem() {
483 return entryItem;
484 }
485
486 public void setEntryItem(BlogEntry entryItem) {
487 this.entryItem = entryItem;
488 }
489
490 {{/code}}
491
492 The Java part is done, so let's add the loop inside the component. Open **BlogEntryIndexPage.wo** (it's located in the **Component** folder) and right after the <body> tag, add:
493
494 {{code}}
495 <wo:loop list="$entries" item="$entryItem">
496 <p><wo:str value="$entryItem.title" /></p>
497 <p><wo:str value="$entryItem.author.fullName" /></p>
498 </wo:loop>
499
500 {{/code}}
501
502 That component code will loop over the blog entries and display the title of the entry + the name of the author. Save everything and run the application.
503
Filippo Laurìa 46.1 504 If you go to [[http:~~/~~/192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa/ra/blogEntries.html>>url:http://192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa/ra/blogEntries.html||shape="rect"]], you will see the list of blog entries!
franc 34.1 505
506 Now that we have a list of blog entries, let's make a page to show the content of a blog entry. Create a new component named **BlogEntryShowPage**.
507
Filippo Laurìa 46.1 508 Open **BlogEntryShowPage.java** and make sure the class implements **er.rest.routes.IERXRouteComponent**.
franc 34.1 509
510 {{code}}
511 import er.rest.routes.IERXRouteComponent;
512
513 public class BlogEntryShowPage extends WOComponent implements IERXRouteComponent {
514
515 {{/code}}
516
517 We need to add other methods to receive the BlogEntry object from the controller. In **BlogEntryShowPage.java**, add:
518
519 {{code}}
520 private BlogEntry blogEntry;
521
522 @ERXRouteParameter
523 public void setBlogEntry(BlogEntry blogEntryFromController) {
524 this.blogEntry = blogEntryFromController;
525 }
526
527 public BlogEntry blogEntry() {
528 return this.blogEntry;
529 }
530
531 {{/code}}
532
533 The **@ERXRouteParameter** annotation tells the REST framework that it can automatically receive an object from the controller. And again, it's convention at work. You have to use the annotation and the setter name should be //set<EntityName>//, so for a BlogEntry, it's //setBlogEntry//, for a Author, it will be //setAuthor//.
534
535 The Java part of the work is done, so save the Java class. It's time to work on the component part. Open **BlogEntryShowPage.wo** and between the <body></body> part, add:
536
537 {{code}}
538 <h1><wo:str value="$blogEntry.title" /></h1>
539 <p><wo:str value="$blogEntry.content" /></p>
540 <p>Created on: <wo:str value="$blogEntry.creationDate" dateformat="%Y/%m/%d" /></p>
541 <p>Added by: <wo:str value="$blogEntry.author.fullName" /></p>
542
543 {{/code}}
544
545 Our view component is done, the only thing remaining is a link for the blog entry list (BlogEntryIndexPage) to the view page (BlogEntryShowPage). Save **BlogEntryShowPage.wo** and open **BlogEntryIndexPage.wo**. We are going to add a link on the title, you will replace to replace this:
546
547 {{code}}
548 <p><wo:str value="$entryItem.title" /></p>
549
550 {{/code}}
551
552 with:
553
554 {{code}}
555 <p><wo:ERXRouteLink entityName="BlogEntry" record="$entryItem" action="show"><wo:str value="$entryItem.title" /></wo:ERXRouteLink></p>
556
557 {{/code}}
558
Filippo Laurìa 46.1 559 Save the component and run the app. Go to [[http:~~/~~/192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa/ra/blogEntries.html>>url:http://192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa/ra/blogEntries.html||shape="rect"]] to get the list of posts, and you should see a link on the title. Click on it, and now you get the full details of the blog entry!
franc 34.1 560
Filippo Laurìa 46.1 561 The REST part of this tutorial is now complete, [[you can now move to the next part of the tutorial>>doc:Your First Framework]].