Bookmarkable URL

The page index.xhtml and manage.xhtml can show any contents by adding backing beans in their regions. They are bookmarkable but they show default contents only.

Bookmarkable URLs can be achieved using pages (website or manage center) with embedded objects. For example, show full-time employees order by hired date. Bookmarkable URL:

	http://domain/showEmployees.page?empType=FULL_TIME
The web page showEmployees:

<object xmlns="http://www.cmobilecom.com/af/objects" 
	id="employees" type="entities">
	
	<entityType>ExampleHR.EMP</entityType>
	<properties>
		<property name="type">#{param.empType}</property>
		<property name="hiredDate" queryType="ORDER_ASC"></property>
	</properties>

	<viewConfig>
		<viewType>ENTITY_LIST_WIDE</viewType>
		<property name="name">
			<renderStyle>
				<styleNumber>16</styleNumber>
			</renderStyle>
			<outputLink>/showEmployee.page?empId=#{entity.nid}</outputLink>
		</property>
	</viewConfig>
  
</object>

The page above embeds an employee list whose type is bound to request parameter empType. So to show part-time employees, change empType to PART_TIME:
	http://domain/showEmployees.page?empType=PART_TIME
The employee name on each row is rendered as outputLink that is bookmarkable.
	/showEmployee.page?empId=#{entity.nid}
The entity in #{entity.nid} is bound to current row entity, employee in this case. so the bookmarkable URLs for the employees(id: 100, 101) are
	http://domain/showEmployee.page?empId=100
	http://domain/showEmployee.page?empId=101
The web page showing an employee:

<object xmlns="http://www.cmobilecom.com/af/objects" 
	id="showEmployee" type="entity">
	
	<entityType>ExampleHR.EMP</entityType>
	<mode>VIEW</mode>
	<properties>
		<property name="nid">#{param.empId}</property>
	</properties>

	<viewConfig>
		<viewType>ENTITY</viewType>
	</viewConfig>
  
</object>
The nid of the employee to retrieve from persistence is bound to request parameter empId. So the page can show an employee by its employee id.

If a bookmarkable URL is accessing entities in a subsystem, the subsystem must be bound to the domain.

Pagination

Entity list pagination is ajaxed by default. By specifying pageParam in viewConfig, pagination commands will be rendered as bookmarkable URLs. For example,

<viewConfig>
    <viewType>ENTITY_LIST_WIDE</viewType>
    <pageSize>20</pageSize>
    <pageParam>pageNumber</pageParam>
</viewConfig>
The value of request parameter pageNumber will be the page to show in the entity list. Page number starts from 1.

Post, Redirect and Get

In a page of creating an employee, clicking Create command sends POST request. After creating the employee in the persistence, the server redirects to a new page showing the employee created.

<object xmlns="http://www.cmobilecom.com/af/objects" 
	id="createEmployee" type="entity">
	
	<entityType>ExampleHR.EMP</entityType>
	<mode>CREATE</mode>

	<viewConfig>
		<viewType>ENTITY</viewType>
		<redirect action="cmd.Create"
			toURL="/showEmployee.page">
			<add name="empId" value="#{entity.nid}" />
		</redirect>
	</viewConfig>
  
</object>
Redirect URL parameter construction

Redirect to a URL after the command is completed. The URL parameters can be constructed by propagating existing view parameters, remove or override existing parameters, and add new parameters.


	<redirect action="command-or-id" 
		enabled="#{EL-expression}"
		toURL="redirect-page-URL">
		<addAll />
		<remove name="parameterName" />
		<add name="parameterName" value="parameterValue" />
	</redirect>
For example, current page URL is
	http://domain/page1.page?p1=v1&p2=v2&p3=v3
The redirect URL for the command doSomething is configured as following:

	<redirect action="doSomething" to="/page2.page">
		<addAll />
		<remove name="p2" />
		<add name="p3" value="foo" />
		<add name="p4" value="bar" />
	</redirect>
The computed redirect URL would be:
	http://domain/page2.page?p1=v1&p3=foo&p4=bar
Parameter values can contain expressions. For example,

	<add name="p4" value="foo#{entity.id}" />
The entity variable entity is available only in ENTITY view, and for a row command in entity list view.

Website and URL Rewriting

Website module is an independent module, and can be assembled into the system InstanceType or a subsystem InstanceType.

With Website module, users can do:

For example, If a different style of URLs is preferred, for example:

      /showEmployees/FULL_TIME
      /showEmployee/100
The following URL rewriting rules can be specified.

<url-rewriting>
	<rule>
		<pattern>^/showEmployees/(.+)$</pattern>
		<page>index.xhtml</page>
		<parameter name="pageIdentifier">showEmployees</parameter>
		<parameter name="empType">$1</parameter>
	</rule>
	<rule>
		<pattern>^/showEmployee/(.+)$</pattern>
		<page>index.xhtml</page>
		<parameter name="pageIdentifier">showEmployee</parameter>
		<parameter name="empId">$1</parameter>
	</rule>	
</url-rewriting>
see Website module documentation for detail.