Menu Confirmation Dialog Tutorial

compared with
Current by Tyler Johnson
on Jun 20, 2013 16:06.


 
Key
These lines were removed. This word was removed.
These lines were added. This word was added.

View page history


There are 47 changes. View first change.

 h2. Menu + Confirmation Dialog Tutorial
  h1. Menu Confirmation Dialog Tutorial
  
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:
  This tutorial will demonstrate the use of the <mobi:menuButton>, <mobi:panelConfirmation> and <mobi:submitNotification> components. The menuButton drop down will allow the user the option of selecting several actions and then confirm their selection via a confirmation dialog. The submit notification component will then prevent further user interaction until the backing bean process has completed. We will have cover two use cases:
  
* [Single dialog|single]
 * [Dialog for each menu item|multiple]
  * [Single dialog|#single]
 * [Dialog for each menu item|#multiple]
  
Here are the descriptions of the main <mobi> components that will be used:
  {gallery}
  
* [<menuButton>|tld] \- This component renders a select menu button with a collection of menuButtonItems upon selection of a menuButtonItem, and actionListener will be queued.
  \\
 The source code for both tutorials can be found at the bottom of the tutorial [here|#source]. Additional information regarding these components can be found here:
  
* [<panelConfirmation>|] \- This mobility component renders a confirmation panel to be used with any mobi commandButton or menuButton
  * [WIKI|http://www.icesoft.org/wiki/display/icemobile/ICEmobile+Component+Suite]
 * [TLD|http://res.icesoft.org/docs/icemobile/v1_latest/jsf/tld/]
  
* [<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
 \\
  
 h3. Add <mobi:fieldsetGroup> layout component
  
  
 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:
  
\\
 {code}
 <h:form>
<mobi:fieldsetGroup style="width:200px">
   <mobi:fieldsetGroup>
  <mobi:fieldsetRow>
  .......
  </mobi:fieldsetRow>
  </mobi:fieldsetGroup>
 </h:form>
 {code}
 \\
  
  
  
 h3. Add <mobi:menuButton>
  
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 allows a user to select and execute a menu item while ActionListener methods can be assigned for each of the MenuButtonItem's in the menu. We will also tie the menuButton with a panelConfirmation and submitNotification component. Please add the following within the <mobi:fieldsetRow>:
  
\\
 {code}
 <mobi:menuButton id="mnu" value="#{menu.menuData}" var="item">
 </mobi:menuButton>
 {code}
 \\
  
 The menuButton value binding menu.menuData, will consist of a list of <SelectItem> objects that will populate our menuButtonItems below.
\\
  
\\
 {anchor:single}
 h2. Example 1: Single Dialog
 \\
  
h2. Usage 1: Single Dialog
  
 h3. Add <menuButtonItem>
  
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 menuButton will iterate over the list supplied by the value binding and create the menuButtonItems. The menuButtonItem options will 'add', 'edit' and 'delete' values. Please add the following code within the <mobi:menuButton>:
  
\\
 {code}
<mobi:menuButtonItem value="#{item.value}" label="#{item.label}" panelConfirmation="pc1" submitNotification="sn1"
 actionListener="#{menu.changeDeviceStyle}" />
  <mobi:menuButtonItem value="#{item.value}" label="#{item.label}" panelConfirmation="pc1"
 submitNotification="sn1" actionListener="#{menu.performAction}" />
 {code}
 \\
  
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 <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 actionListener method performAction and lastly the <mobi:submitNotification> blocker.
  
 h3. Add <mobi:panelConfirmation> <mobi:submitNotification>
  
 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:
  
\\
 {code}
<mobi:panelConfirmation id="pc1" message="Change Style?" />
  <mobi:panelConfirmation id="pc1" message="Perform Action?" />
 <mobi:submitNotification id="sn1">
<h:outputText value="Working.." />
   <h:outputText value="Working..." />
 </mobi:submitNotification>
 {code}
 \\
  
h3. Add <mobi:deviceStylesheet>
  h3. Add action output
  
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:
  Add the following <mobi:fieldSetRow> below the row containing our panelConfirmation and submitNotification components:
  
\\
 {code}
<mobi:deviceStylesheet name="#{menu.style}" />
  <mobi:fieldsetRow>
 Action: <h:outputText value="#{menu.action}"/>
 </mobi:fieldsetRow>
 {code}
 \\
  
We will dynamically change the stylesheet by modifying the menu.style property in our managed bean.
  
 h3. Add Managed Bean
  
Please add the following managed bean code:
  Please add the following managed bean code in addition to generating getters and setters:
  
 {code}
 @ManagedBean(name = "menu")
 @ViewScoped
 public class MenuBean implements Serializable {
  
  List<SelectItem> menuData = new ArrayList<SelectItem>();
private String action;
  
// Default to iPhone stylesheet
  private String deviceStyle = "iphone";
  
  public MenuBean() {
 
  // Construct our menu items
  this.menuData.add(new SelectItem("ipad", "ipad"));
  this.menuData.add(new SelectItem("android", "android"));
  this.menuData.add(new SelectItem("iphone", "iphone"));
   this.menuData.add(new SelectItem("Add", "Add"));
  this.menuData.add(new SelectItem("Edit", "Edit"));
  this.menuData.add(new SelectItem("Delete", "Delete"));
  }
  
public void changeDeviceStyle(ActionEvent ae) {
   public void performAction(ActionEvent ae) {
  
  try {
  MenuButtonItem item = (MenuButtonItem) ae.getSource();
style = (String) item.getValue();
  
  // Used to simulate a long running process
  action = (String) item.getValue();
  
  System.out.println("Action performed: " + action);
  
  Thread.sleep(5000);
  
  } catch (Exception e) {
  }
  }
 
  //TODO GENERATE GETTERS/SETTERS
 {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.
  Our actionListener performAction, will get the user's menu item selection from the ActionEvent and call Thread.sleep which is used to simulate a long running process in order to demonstrate the panelConfirmation functionality.
 \\
  
h2. Usage 2 - Multiple confirmation dialogs
  \\
 {anchor:multiple}
 h2. Example 2 - Multiple confirmation dialogs
 \\
  
The full source code for both the single and multiple examples can be found at the bottom under the source heading.
  
 h3. Modify the ICEmobile page
  
 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:
  
\\
 {code}
 <mobi:menuButton id="mnu" value="#{menu.menuData}" var="item">
  <mobi:menuButtonItem value="#{item.value}" label="#{item.label}" panelConfirmation="#{item.panelConfId}"
submitNotification="#{item.submitNotif}" actionListener="#{item.actionMethod}"/>
   submitNotification="#{item.submitNotif}" actionListener="#{menu.performAction}" />
 </mobi:menuButton>
 {code}
 \\
  
 h3. Add additional panelConfirmation dialogs
  
 Each menuButtonItem will now have a specific panelConfirmation component. Please add the following below the closing </mobi:menuButton> tag:
  
\\
 {code}
<mobi:panelConfirmation id="iphone" message="Switch to iphone style?" />
 <mobi:panelConfirmation id="ipad" message="Switch to ipad style"/>
 <mobi:panelConfirmation id="android" message="Switch to android style"/>
  <mobi:panelConfirmation id="pc1" message="Add Item?" />
 <mobi:panelConfirmation id="pc2" message="Edit Item" />
 <mobi:panelConfirmation id="pc3" message="Delete Item" /
 <mobi:submitNotification id="sn1">
<h:outputText value="Working.." />
 </mobi:submitNotification>
   <h:outputText value="Working..." />
 </mobi:submitNotification>
 {code}
 \\
  
 
  h3. Add Managed Bean code
  
We will use a custom object to hold our menuButtonItem's value, label, and corresponding panelConfirmation and submitNotification ids. Please add the following managed bean code in addition to generating the getters and setters:
  
{code}
 @ManagedBean(name = "menu")
 @ViewScoped
 public class MenuBean implements Serializable {
  
List<ModelData> menuData = new ArrayList<ModelData>();
  private String action;
  
  public MenuBean() {
  this.menuData.add(new ModelData("Add", "Add","pc1","sn1"));
  this.menuData.add(new ModelData("Edit", "Edit","pc2","sn1"));
  this.menuData.add(new ModelData("Delete", "Delete","pc3","sn1"));
  }
  
  public void performAction(ActionEvent ae) {
  
  try {
  MenuButtonItem item = (MenuButtonItem) ae.getSource();
  action = (String) item.getValue();
  
  System.out.println("Action performed: " + action);
  
  Thread.sleep(5000);
  
  } catch (Exception e) {
  }
  }
  
  //TODO GENERATE GETTERS/SETTERS
  
  public class ModelData implements Serializable {
  private String value;
  private String label;
  private String panelConfId;
  private String submitNotif;
  
  public ModelData(String val, String label, String pcId, String snId) {
  this.value = val;
  this.label = label;
  this.submitNotif = snId;
  this.panelConfId = pcId;
  }
  
  //TODO GENERATE GETTERS/SETTERS
  }
 }
 {code}
  
 h3. Add action output
  
 Add the following <mobi:fieldSetRow> below the row containing our panelConfirmation and submitNotification components:
  
 {code}
 <mobi:fieldsetRow>
 Action: <h:outputText value="#{menu.action}"/>
 </mobi:fieldsetRow>
 {code}
 \\
  
 h3. Run Application
  
 Select an item from the <mobi:menuButton> drop down:
  
 \\
 !menu.png|align=center!
 \\
  
 Click to confirm or cancel the <mobi:panelConfirmation>:
  
 \\
 !menu-confirm.png|align=center!
 \\
  
 The <mobi:submitNotification> will prevent user interaction until our actionListener completes:
  
 \\
 !menu-working.png|align=center!
 \\
  
 h3. Source
  
 1. [menu-basic-tutorial.zip|^menu-basic-tutorial.zip|menu-basic-tutorial.zip]
 2. [menu-advanced-tutorial.zip|^menu-advanced-tutorial.zip|menu-advanced-tutorial.zip]

© Copyright 2016 ICEsoft Technologies Canada Corp.