Mobilize Your RIA in 10 Minutes
The existing web application we will work with is called "Tracker". This application is used to track scores (or results) for different types (such as game scores and monthly sales). The application has three pages - home, type and game.
Steps to Mobilize Your RIA:
Add ICEmobileDownload the ICEmobile bundle from http://www.icesoft.org/java/downloads/icemobile-downloads.jsf. Add icefaces-mobi.jar to your existing ICEfaces application.
Redirect Mobile Browsers to Mobile PagesThe entry point to our application is index.jsp as configured in web.xml:
<welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
<%
response.sendRedirect("desktop/home.jsf");
%>
<%@ page import="org.icemobile.util.ClientDescriptor" %> <% org.icemobile.util.ClientDescriptor client = ClientDescriptor.getInstance(request); if(!client.isDesktopBrowser()){ response.sendRedirect("mobile/m_home.jsf"); }else{ response.sendRedirect("desktop/home.jsf"); } %> Add Mobile PageContent of our mobile home page m_home.jsf: <!DOCTYPE html > <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:mobi="http://www.icesoft.com/icefaces/mobile/component"> <f:view contentType="text/html"> <h:head> <title>#{msgs['title']} #{title}</title> <mobi:deviceResource /> </h:head> <h:body> <mobi:smallView> <ui:param name="viewSize" value="small" /> <ui:include src="/WEB-INF/mobile/includes/small/m_s_home.xhtml" /> </mobi:smallView> <mobi:largeView> <ui:param name="viewSize" value="large" /> <ui:include src="/WEB-INF/mobile/includes/large/m_l_home.xhtml" /> </mobi:largeView> </h:body> </f:view> </html>
The <mobi:smallView> and <mobi:largeView> components can be used to define view specific content. The <mobi:smallView> content will be rendered for smaller devices such as phones, while content nested within <mobi:largeView> will be rendered for devices such as tablets. This technique combined with the Facelets tag hander <ui:include/> can build highly reusable and customizable views. It is a best practice to avoid using the more resource intensive ace: components in mobile pages - we try to limit ourselves to stock JSF h: tags and the ICEmobile mobi: tags. Also note the use of html 5 which is widely supported in mobile browsers.
Add Mobile Navigation Rules (if necessary)If your current ICEfaces application has multiple pages with navigation rules, you can easily re-use existing navigation rules and outcomes by adding a mobile version of each navigation rule in faces-config.xml:
<!-- NAVIGATE TO HOME PAGE --> <navigation-rule> <from-view-id>/desktop/*</from-view-id> <navigation-case> <from-outcome>home_page</from-outcome> <to-view-id>/desktop/home.xhtml</to-view-id> <redirect include-view-params="true"/> </navigation-case> </navigation-rule>
<!-- NAVIGATE TO MOBILE HOME PAGE --> <navigation-rule> <from-view-id>/mobile/*</from-view-id> <navigation-case> <from-outcome>home_page</from-outcome> <to-view-id>/mobile/m_home.xhtml</to-view-id> <redirect include-view-params="true"/> </navigation-case> </navigation-rule> Small View Home PageThe steps up to this point have 'Mobilized' our application. Now, when we access the application with a mobile device, the application will automatically redirect us to the mobile home page which in turn, includes either small size (phone) or large size (tablet) content.
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:mobi="http://www.icesoft.com/icefaces/mobile/component"> <mobi:pagePanel> <f:facet name="header"> <h:outputText rendered="#{not appUserBean.loggedIn}" value="#{msgs['trackerSignIn']}" style="font-size: 1em;" /> <h:outputText rendered="#{appUserBean.loggedIn}" value="#{msgs['title']}" style="font-size: 1em;" /> </f:facet> <f:facet name="body"> <mobi:fieldsetGroup> <mobi:fieldsetRow style="padding-bottom:10px;"> #{msgs['intro']} </mobi:fieldsetRow> </mobi:fieldsetGroup> <mobi:outputList> <mobi:outputListItem group="true">#{msgs['types']}</mobi:outputListItem> <mobi:outputListItems value="#{homeBackingBean.types}" var="type" > <h:link value="#{type.name}" outcome="#{type.name}" includeViewParams="true"> <f:param name="entityId" value="#{type.typeId}" /> <p> #{type.summary} </p> </h:link> </mobi:outputListItems> </mobi:outputList> </f:facet> <f:facet name="footer"> <h:outputText rendered="#{appUserBean.loggedIn}" value="#{msgs['welcome']} #{appUserBean.appUser.name}" style="font-size: 0.8em;" /> </f:facet> </mobi:pagePanel> </ui:composition>
When the large view (tablet) content is created, it will provide the same behavior except with a larger screen size available, we can choose to use different components.
|
Mobilize Your RIA in 10 Minutes
© Copyright 2016 ICEsoft Technologies Canada Corp.