Developer download: Upvise Mobile Application XML (MAX) Basics

  1. Asking user input
  2. Multiple pages and navigation
  3. Passing Parameters between pages
  4. Defining a Data Store
  5. Queries
  6. Databinding
  7. Posting Data to server

Asking user input

You can easily make an item editable by specifying a type="text" attribute. You can also add a label attribute which is displayed before the user entered any text. 
<?xml version="1.0"?>
<max id="mycompany.sample4" version="1.0">
  <page id="default">
    <title>Sample 4</title>
      <item type="text" label="Enter your name" />
  </page>
<max>
Initially the page will display an item with the label : Enter your name. When the user selects this item and presses the center key of the mobile phone, a popup input box will be displayed. When he has finished entering text, the item in the page will be updated to display the text he just entered.

Multiple pages and navigation

You can add multiple pages in your application to create a complex behavior and navigate between these pages using urls, just like you would do with a web site.

<?xml version="1.0"?>
<max id="mycompany.sample5" version="1.0">
  <page id="page1">
    <title>This is page 1</title>
    <item href="page2">Go to page 2</item>
    <item href="page3">Go to page 3</item>
  </page>
  
<page id="page2"> <title>This is page 2</title> <item href="page1">Go back to Page 1</item> </page> <page id="page3"> <title>This is page 3</title> <item href="page1">Go back to Page 1</item> </page> </max>

You already noticed that each page node contains an id attribute which uniquely identfies the page within the application.

Passing Parameters between pages

You can pass any parameter in the target page url, the same way you would do with standard web sites and html pages. These parameters can be retrieved using the request object in the target page.

<?xml version="1.0"?>
<max id="mycompany.sample6" version="1.0">
	<page id="page1">
		<title>What's your name?</title>
		<item href="page2?name=Bill">I'm Bill</item>
		<item href="page2?name=Steve">I'm Steve</item>
	</page>
	<page id="page2">
		<title>Your name is:</title>
		<item>{request.name}</item>
	</page>
</max>

In this example, we are passing the parameter name and its value to page2. In page2, we retrieve this parameter using {request.name} and display it

Defining a Data Store

The Upvise client contains an embedded database and you can easily define any number of tables (called data sources) to enable local persistence of data on the phone. Supported data types are

  • primarykey (it must be the first and unique field in the data source. Its names must be id)
  • string
  • integer
  • date
  • list

To define a data source in a max application, use the datasrc tag. You must specificy a mandatory id attribute which is the datasource name. Then you define the fields with the field tag. You can have up to 255 fields in a datasource. Each field tag must contain a type attribute corresponding to one of the value above.

<?xml version="1.0"?>
<max id="mycompany.sample7" version="1.0">
   
   <datasrc id="customers">
<field type="primarykey">id</field> <field type="string">name</field>
<field type="string">company</field>
<field type="integer">importance</field>
<field type="date">creationdate</field>
</datasrc> .... </max>

Queries

In any page on the MAX application, you can define queries against a local data source. Queries can be of type: select, insert, update, delete and updatemultiple

Use the following URL like syntax:

TypeSyntax
SELECT MAX Langague:
   <query id="q1" type="select">mytable?field1=value1&amp;field2=value2...</query>

SQL Equivalent:
   SELECT * FROM mytable WHERE field1=value1 AND field2=value2
INSERT MAX Langague:
   <query id="q2" type="insert">mytable?field1=value1&amp;field2=value2...</query>

SQL Equivalent:

    INSERT INTO mytable (field1, field2) VALUES (value1, value2)
UPDATE MAX Langague:
   <query id="q3" type="update">mytable?id=id1&amp;field1=value1&amp;field2=value2...</query>

SQL Equivalent:
   UPDATE mytable SET field1=value1, field2=value2 WHERE id=id1
DELETE MAX Langague:
   <query id="q4" type="delete">mytable?id=id1</query>

SQL Equivalent:
   DELETE FROM mytable WHERE id=id1
UPDATEMULTIPLE MAX Langague:
   <query id="q3" type="updatemultiple">mytable?field1=value1&amp;field1=value2...</query>

SQL Equivalent:
   UPDATE mytable SET field1=value1, field2=value2 WHERE field1=value1

Databinding

Once you defined a SELECT query in a given MAX page, you can easily bind the values of the resulting recordset into any MAX UI tag, Simply use the {queryid.fieldid} syntax in any tag content or attribute. queryid is the id of the query you defined in the same MAX page and fieldid is the name of a field of the datasource used in the query.

<?xml version="1.0"?>
<max id="mycompany.sample6" version="1.0">
...
<page id="view">
    <query id="data" type="select">customers?id=5</query>
    
    <title>Customer Detail</title>
    <item label="Name">{data.name}</item>
    <item label="Company">{data.company}</item>
    <item label="Importance">{data.importance}</item>
    <item label="Date">{data.creationdate.date}</item>
</page>
...
</max>

Posting Data to a server

You can easily post data gathered from user input using a GET or POST query. To do so, simply define a custom query of type "sendget" to send data using HTTP GET or "sendpost" using HTTP POST. The target server URL and the parameters are set on the text content of the query parameter. Note that the URL must be an absolute http URL.

<query id="myquery" type="sendget">http://myserver?name=Bill&age=32</query>

You can call this custom query with the standard [queryid].execute() script from any onclick attribute.

A simple example is given below:

<?xml version="1.0"?>
<max id="mycompany.sample7" version="1.0">
   <title>Post Data</title>
   <page id="default">
      <query id="mywebservice" type="sendget">http://myserver?name=Bill&age=32</query>
      <title>Post Data</title>
      <item onclick="mywebservice.execute()">SEND NOW</item>
   </page>
</max>

Warning: you need to be in Online mode on your mobile phone to issue any send or post request. If you are in Offline mode, the request will not be sent until you go into Online mode (it will stay on the Outbox HTTP query cache on the phone). This applies both to real phones and the simulator.

Adding some scripting

coming soon...