This tutorial will demonstrate the use of the <mobi:menuButton>, <mobi:panelConfirmation> and <mobi:submitNotification> components. The menuButton drop down will allow the user to dynamically change the page's CSS stylesheet between the iphone, ipad and android stylesheets. We will have cover two use cases:
- [Single dialog]
- [Dialog for each menu item]
Here are the descriptions of the main <mobi> components that will be used:
- [<menuButton>] - This component renders a select menu button with a collection of menuButtonItems upon selection of a menuButtonItem, and actionListener will be queued.
- [<panelConfirmation>|] - This mobility component renders a confirmation panel to be used with any mobi commandButton or menuButton
- [<mobi:submitNotification>|] - This mobility component renders a panel to be used with any mobi commandButton which blocks any other submission for the duration the process triggered by the button until the update is complete
- <mobi:deviceStylesheet> - This mobility component loads an outputStyleSheet in the head of a jsf view page while determining which device is to be supported and delivering the correct stylesheet based on the device type
We will layout our form using the <mobi:fieldsetGroup> and <mobi:fieldsetRow> components. Please paste the following into the <h:body> of your ICEmobile page:
The menuButton allows a user to select and execute a menu item. ActionListener methods can be assigned for each MenuButtonItem in the menu which we will use to toggle the device specific CSS stylesheet of the page. We will also tie the menuButton with the panelConfirmation and submitNotification components. Please add the following within the <mobi:fieldsetRow>:
The menuButton value binding menu.menuData, will consist of a list of <SelectItem> objects that will populate our menuButtonItems below.
The menuButton will iterate over the list supplied by the value binding and create the menuButtonItems. The menuButtonItem options will include the ipad, iphone, and android values. Please add the following code within the <mobi:menuButton>:
The <SelectItem> values provided by the menuButton value binding will supply our menuButtonItems value and label attributes. When clicking a MenuButtonItem, the <mobi:panelConfirmation> with id="pc1" will be triggered followed by the <mobi:submitNotification> with id="sn1". Lastly, our actionListener method changeDeviceStyle will be called and will toggle the device CSS stylesheet applied by <mobi:deviceStylesheet>.
The panelConfirmation will prompt the user to either accept or decline the action while the submitNotifcation will prevent any further user interaction until page processing has completed. Please add the following code below the closing </mobi:menuButton> tag:
The deviceStylesheet will automatically provide the correct stylesheet for the target device (iPhone, iPad, Android, etc.). If the name attribute is provided, the component will render that stylesheet. Please add the following code to the <h:head> section of your ICEmobile page:
We will dynamically change the stylesheet by modifying the menu.style property in our managed bean.
Please add the following managed bean code:
Our actionListener changeDeviceStyle, will get the user's menu item selection from the ActionEvent and will set the deviceStyle accordingly. The Thread.sleep is used to simulate a long running process in order to show the panelConfirmation functionality.
The full source code for both the single and multiple examples can be found at the bottom under the source heading.
The menuButtonItems will have parameterized panelConfirmation and SubmitNotification attributes. We will keep track of these values in a custom object in our managed bean. Please replace the previous menuButton with the following:
Each menuButtonItem will now have a specific panelConfirmation component. Please add the following below the closing </mobi:menuButton> tag: