Contents
- 1 What are we going to build
- 2 Before you start
- 3 Creating a new app
- 4 Creating the first page (station list)
- 5 Creating a REST service (to get all routes)
- 6 Binding the service to the page
- 7 Invoking the routes service
- 8 Creating details page
- 9 Adding navigation
- 10 Creating REST details service
- 11 Adding the details service to the page
- 12 Invoking the details service
- 13 Testing the app
What are we going to build
In this tutorial we are going to show you how to build a mobile app with a clickable list (master-detail). Every item in the list has a unique id which on click will be passed to the next page and used in another service. We are going to be using REST services from San Francisco MUNI (about SF Muni). On the first page we will display a list of all lines. Clicking on a partuclar line will open up a second page showing all stops for the selected line. The app will look like this:
First page shows routes list:
Second page shows details for a selected route:
Before you start
Tutorial level: completed at least one app from Beginner tutorial section.
Creating a new app
Create a new app in Tiggzi app builder. From Apps page, enter app name (use any name you want) and click Create. Once the builder loads, you should see the following:
Creating the first page (station list)
On the first page we are going to display the list of all SF Muni stations so it’s going to be pretty simple. We are going to use a List component.
- Open startScreen
- Change the Caption in the header to any text you want.
- Drag and drop the List component.
- As we are going to bind the list to a service, we just need one time. With the list selected (use breadcrumbs to select it), change the number of Items to: 1 in Properties.
- Instead of using the default label, drag and insert a Label component inside the list
- Change the label name to: routeName. This label will display the station name. We also need to save the route id so that we can pass it to the next page and display the route details.
- For the route id, drag and drop and insert another Label component inside the list:
- Rename the second label to: tagId. This is the id of the route.
- As we don’t want to actually display the list to the end user, with the label selected, uncheck Visible in properties. We are basically creating a hidden field.
- If you would like, you can test the page in the browser by clicking the Test button.
Now that we are done with the first page, next we are going to work on the first REST service.
Creating a REST service (to get all routes)
- From Projects view, Create New > Service. For service name enter: RoutesService.
- Keep REST Service selected and click Create Service button. The service editor will be loaded.
- For the URL enter: http://webservices.nextbus.com/service/publicXMLFeed
- For Data Type, set to: xml
- Check Use Tiggzi Proxy
- Open Request tab
- Add two request parameters and their default values:
- command = routeList
- a = sf-muni
- Let’s now test the service. Open Test tab
- Click Test button. The service response (in XML format) should be displayed:
- Based on this test XML response, we can create the service response. Click Automatically Create Service Response button
- Open Response tab. You should see the service response that was created automatically
- Click Save.
Now that we have the service defined, let’s add the service to the page and bind it to the page.
Binding the service to the page
- Open startScreen
- Switch to Data view
- Select Service from the first list. RoutesService will be automatically selected in the second list.
- Click add. We just added the service to the page. Next is to bind (map) the service to the page.
- Click Edit Mapping button
- Request will open first. We don’t need to map anything as all input values are the default values set when we defined the service.
- Open Response tab
- Create the following mappings:
- Save
Now we just need to invoke the service.
Invoking the routes service
- Switch to Design tab
- Open Events tab
- For Component list, select startScreen.
- For Event select Load (should be selected automatically)
- For Action, select Invoke service, select restservice1
- Save by clicking Add event button. The result will look like this:
- Go ahead and test the app in the browser. The result will look like this:
As you can see, the tagId value is rendered into the page but not visible. We are going to use it very soon.
Creating details page
- Create a new page, Project view > Create New > Page
- For page name enter: details. Click Create Page
- Build UI that looks like this:
Back button was added from header Properties
There is a Grid component (1 row/cell) with a Label inside it
Rename the label component to: stationName - Save
Let’s quickly update the first page so that we can navigate to the second page when an item is clicked.
- Open startScreen
- Select the list item (not the label):
- Open Events tab
- You should have mobilelistitemx_x, and Click event selected (if not, select them).
- For Action, select: Set local storage variable.
- Variable name: _tagId
- Bind to component: check
- Target component: tagId (this is the hidden element in each list item)
- Property name: Text
- Click to add this event.
- Select the list item again, and on Click event, add Navigate to Page action (going to details page)
- Save.
Creating REST details service
- Create a new REST service called: RouteDetails
- For URL enter: http://webservices.nextbus.com/service/publicXMLFeed
- Set Data Type to: xml
- Check Use Tiggzi Proxy
- Open Request tab, and add three parameters:
- command = routeConfig
- a = sf-muni
- r (no default value). This is the route id which is going to be passed from the first page.
- Open Test tab
- We can still test the service by entering a valid route id. Enter 14 for r and click Test
- Once the response is shown, click Automatically Create Service Response
- Go to Response tab to see that response was created:
- Save.
Adding the details service to the page
The details service will be invoked on the second page and it needs to read the id for the route we are interested in from local storage.
- Open details page, switch to Data view
- Add the service to the page, select Service > RouteDetails, click Add
- Open Edit Mappings
- For input, we want to get the value for r from local storage:
- Save
- Open Response tab, to map the output
- Create the following mappings:
- Save.
We are almost done. We just need to invoke the service when we navigate to the second page.
Invoking the details service
- Open details page
- Open Events page
- Add Load event to the page, for Action select Invoke service and select restservice1. Click to save the event:
- Save
Testing the app
Go ahead and test the app. The first page looks like this:
Clicking on M-Ocean View route for example will show the following: