The URL Fragments

From WebRatio WebML Wiki

Jump to: navigation, search


Contents

Introduction

A search engine uses a set of well known rules to decide the visibility of a website. One of these rules is to have simple URLs containing the keywords the page should be indexed with. WebRatio 6 introduces a new feature named URL Fragments. This feature allows to increase the search engine ranking of a Web application generated by WebRatio. The URLs are produced at run-time using a set of URL Fragments defined in the Web Project.

To enable the URL Fragment feature on a Web Project you have to use these two properties:


The Properties View of the Web Project
  • Enable URL Fragments: A flag stating whether the URL Fragment functionality is enabled or not.
  • Global URL Fragment: The list of Context Paramters that must be used to create URLs. The order of the element in this list is relevant. In fact the value of each Context Parameter will be placed in the URL at the same position in which it appears in the list. Each element is joined with the others using the "/" character. The list of the standard Context Parameters is shown in the following figure. The last item, "Target URL Name", represents the name of the element reached by the user (e.g. page), so it's usually placed as the last fragment of the URL.


In the Web Project also the Page and the Parameter Collector Unit can be involved in the definition of the URL Fragments. The related properties are enabled only when the URL Fragments are enabled on the entire project.

Using URL Fragments in a Page

  • Custom URL Name. A meaningful name for the page.
  • URL Fragments. The list of the Input Parameters and Variables present in the page that must be used by the URL. Clicking on the button next to this property opens a dialog with the whole list of the page Input Parameters and Variables. The Variables considered are only those not connected to a Unit.


Using URL Fragments in a Parameter Collector Unit.

  • Custom URL Name. A meaningful name for the Parameter Collector Unit.
  • URL Fragments. The list of the Collector parameter specified on the Parameter Collector Unit that must be used by the URL. Clicking on the button next to this property opens a dialog with the whole list of the Collector Parameter.


Examples

The purpose of this section is to show some examples for the usage of the URL Fragment feature.


Example 1: The URL of the Product Page

Our goal is to show a URL for the Product Page having the following structure:

http://localhost:8080/Acme/product/<productName>

where "productName" is the name of the product being viewed by the user.

In order to accomplish this example, it is necessary to download the Acme Sample Project. To get this project, select Help -> WebRatio Samples from the main menu and choose "Acme" from the opening dialog. Once downloaded the project you just have to go through the following steps:

  1. Enable the URL Fragment Feature: in the Properties View of the Project flag the Enable URL Fragment property. Then click the button next to the Global URL Fragment property and choose the "Target URL Name".
  2. Set a name for the "Product Page": select the "Product Page" and write "product" in the Custom URL Name property inside the Properties View. This name will be used in the URL dynamic construction.
  3. Add the "ProductName" variable: select the "Product Page" and right clicking on it choose the Add Variable command. Give a name to the variable.
  4. Define the parameters coupling: open the Parameters Coupling window of the "More..." link outgoing from the "Product of the day" Data Unit in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit. In the Parameters Coupling dialog, select the Variable tab and couple the "name" attribute of the Index Unit with the "productName" variable.
  5. Set the URL Fragments for the "Product Page": select the "Product Page". In the Properties View click the button next to the URL Fragment property. In the opening dialog, choose the productName variable.
  6. Generate the Web application: click on "Generate Full Web Project" on the WebRatio Menu Bar. Once the generation process has completed, it is possible to start the application server and test the Web application.
  7. Navigate the "More..." link of the "Product of the day" content and you should see an URL like the following
    http://localhost:8080/Acme/product/Aladdin

N.B. In order to have the proper URL everytime the user reaches the Product Page, you have to correctly couple the variable on every link having this page as target.

The Global Paramater dialog
The Site View properties

Possible Enhancement

Our goal is to add to the URL of the Product Page also the category of the product in order to obtain the following URL:

http://localhost:8080/Acme/product/<productCategory>/<productName>

In order to accomplish this example, it is necessary to go through the following steps:

  1. Add the "category" attribute: right click on the "Product" entity in the Data Model and choose the Add Attribute command. Give a name to the attribute and then click on the button next to the Derivation property. Create a Simple Imported Attribute retrieving the category from the Category entity.
  2. Add the "ProductCategory" variable: select the "Product Page" and right clicking on it choose the Add Variable command. Give a name to the variable.
  3. Define the parameters coupling: open the Parameters Coupling window of the "More..." link outgoing from the "Product of the day" Data Unit in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit. In the Parameters Coupling dialog, select the Variable tab and couple the "category" attribute of the Index Unit with the "productCategory" variable.
  4. Set the URL Fragments for the "Product Page": select the "Product Page". In the Properties View click the button next to the URL Fragment property. In the opening dialog, choose the productName and the productCategory variables. Change the order of the variables so that the productCategory is the first one.
  5. Generate the Web application: click on "Generate Full Web Project" on the WebRatio Menu Bar. Once the generation process has completed, it is possible to start the application server and test the Web application.
  6. Navigate the "More..." link of the "Product of the day" content and you should see an URL like the following
    http://localhost:8080/Acme/product/Tables/Aladdin
URL Fragment Dialog

Example 2: The URL of Categories page

Our goal is to show a URL for the Categories page having the following structure:

http://localhost:8080/Acme/categories/<categoryName>

where "categoryName" is the name of the category chosen by the user once he have accessed the page.

In order to accomplish this example, it is necessary to download the AcmeWSProject Web Project. Once downloaded the project you just have to go through the following steps:

  1. Enable the URL Fragment Feature: in the Properties View of the Project flag the Enable URL Fragment property. Then click the button next to the Global URL Fragment property and choose the "Target URL Name".
  2. Set a name for the "Categories" page: select the "Categories" page and write "categories" in the Custom URL Name property inside the Properties View. This name will be used in the URL dynamic construction.
  3. Add the "categoryName" variable: select the "Categories" and right clicking on it choose the Add Variable command. Give a name to the variable.
  4. Define the parameters coupling: open the Parameters Coupling window of the "Details" link outgoing from the "All Categories" Index Unit, in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit. In the Parameters Coupling dialog, select the Variable tab and couple the "name" attribute of the Index Unit with the "productCategory" variable.
  5. Set the URL Fragments for the "Products" page: select the "Categories" page. In the Properties View click the button next to the URL Fragment property. In the opening dialog, choose the productCategory variable.
  6. Generate the Web application: click on "Generate Full Web Project" on the WebRatio Menu Bar. Once the generation process has completed, it is possible to start the application server and test the Web application.
  7. Navigate the application since you reach the "Categories" page. You will obtain an URL like the following
    http://localhost:8080/AcmeWS/categories
  8. Selecting a category to see its details you will see something like the following
The Global Paramater dialog
The Site View properties
http://localhost:8080/AcmeWS/categories?kcond2.att31=657650961&sp=page39&var1=Chairs&inu4.current.att31=657650961

Possible Enhancement

The starting Web Model

Looking at the Web Model of the project used in the previous example, you can notice that between the starting page "Load Categories" and the target page "Categories" there's an operation chain. This operation chains loads the category list calling a Web Services and storing the information in a volatile entity.

The problem of this model is that, if the user saves the URL of the target page, and after a day or two, he tries to navigate it again from its bookmarks, he will not see any category since the Web Service will not be invoked.

In order to have a full working page, it's now possible to include an operation chain inside a page. This can be done using an operation module, containing the operation chain, placed inside the page. Every time the user accesses the page, the very first thing done by the Web application is to invoke the operation chain and then the content of the page.

To accomplish this enhancement, just follow these steps:

The optimized Web Model
  1. Create the operation module. Using CTRL + Left Click, select the three operation units outside the page. Then use the Right Click and choose the "Transform into Module.." command. If requested, specify a name for the Module View, then follow the wizard.
  2. Place the module in the page. Cut the operation module and paste it inside the page. You should obtain the Web Model shown in the figure on the right.
  3. Generate the Web application: click on "Generate Full Web Project" on the WebRatio Menu Bar. Once the generation process has completed, it is possible to start the application server and test the Web application.
  4. Navigate the application since you reach the "Categories" page. You will obtain an URL like the following
    http://localhost:8080/AcmeWS/categories
  5. Copy the link and paste it in a new browser. You should see that the page is loaded with all the necessary information.

Example 3: The Confirm Registration URL

Our goal is to obtain a meaningful link for the operation chain that should be invoked in order to confirm the registration of a user. This example refers to the How_to_dinamically_create_URLs. In particular this article focuses on this section of the Web Model:

The Web Model for the example

Suppose that the username is a unique information, then it's possible to use this information to retrieve the user and see if it exists. So, the URL that can be created is something like the following:

http://localhost:8080/Acme/confirmRegistration/<username>

To accomplish this example, follow these steps:

The final Web Model
  1. Enable the URL Fragment Feature: in the Properties View of the Project flag the Enable URL Fragment property. Then click the button next to the Global URL Fragment property and choose the "Target URL Name".
  2. Add a Parameter Collector Unit: select the Parameter Collector Unit icon from the palette and place it inside the Web Model. Change the "Name" property in "Confirm Registration". In the Properties View write "confirmRegistration" in the Custom URL Name property.
  3. Add the username parameter: right click on the Parameter Collector Unit and choose the Add Collector Parameter command. Write "username" as the name of the parameter.
  4. Set the URL Fragments for the "Confirm Registration" Unit: select the Parameter Collector Unit. In the Properties View click the button next to the URL Fragment property. In the opening dialog, choose the username Collector Parameter.
  5. Configure the Selector Unit: delete all the condition on the "User Confirmation" Selector Unit. Then right click on the Selector Unit and choose "Add Attributes Condition" from the Context Menu. Select the newly added Condition from the Outline View and configure the properties as follow:
    • Name="username"
    • Attributes="username"
    • Predicate="Equals"
    • Boolean Operator="Or"
    • Value=""
    • Required="True"
  6. Draw an OK link between the "Confirm Registration" Parameter Collector Unit and the "User Confirmation" Selector Unit: select the Link button from the palette and click on the "Confirm Registration" Parameter Collector Unit (the Source of the OK Link) and then on the "User Confirmation" Selector Unit (the Target of the OK Link). Set the Name property of the newly created OK Link to "Transport Username".
  7. Define the parameters coupling: open the Parameters Coupling window of the newly created link in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit.In the Parameters Coupling dialog, couple the "username" Collector Parameter of the Parameter Collector Unit with the "username" Attribute Condition of the Selector Unit.
  8. Generate the Web application: click on "Generate Full Web Project" on the WebRatio Menu Bar. Once the generation process has completed, it is possible to start the application server and test the Web application.


Related articles:
Category Difficulty Refers
Connect Unit Web Model Beginner Connect Unit
Context Parameters Web Model Beginner Get Unit
Set Unit
Reset Unit
Create Unit Web Model Beginner Create Unit
Create a "Simple data centric" web application Web Model Beginner Site View
WebML
WebRatio
Custom Locations and Master pages Web Model Beginner Master Page
Custom Location
… further results












Did you find this article useful? Please rate it!

Rating: 5.0/5 (4 votes cast)