Skip to main content link. Accesskey S
  • Log In
  • Help
  • IBM Logo
  • IBM Mashup Center wiki
  • All Wikis
  • All Forums
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • IBM Redbooks
Community Articles Product Documentation Learning Center IBM Redbooks This category IBM Mashup Center 3.0.0.1 Documentation Custom Search Scope...
Search
Community Articles > IBM Mashup Center > Accessibility > Defining custom page modes
  • New Article
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

Anna G O'Neal
Contribution Summary:
  • Articles authored: 175
  • Articles edited: 274
  • Comments Posted: 34

Recent articles by this author

Maintaining page IDs when importing spaces

After exporting a space to one server and then importing that space to another server, you might notice that the original IDs for that space and all its pages and widgets change. In cases where you do not want the IDs to change, you can run a stableid import command to import the space ZIP file ...

Adding a custom widget to the mashup builder

You can add a custom widget to the mashup build directly from the Add to Mashup Builder window in the catalog. Do the following steps: 1. Open the catalog.xml file for the widget in edit mode, and add the line in italic font: definition ...

IBM Mashup Center Trial Edition, Version 3.0.0.1

This is an evaluation version of IBM Mashup Center, version 3.0.0.1. The product media contains all the functionality of a fully licensed version of IBM Mashup Center, except for the following limitations: This software is valid for 60 days from installation. This software is only available for ...

Date formats do not match browser settings for language

When browser settings for language are set to engb, certain widgets that display start and end dates of events might incorrectly display the dates in American English format ((MMDDYYYY)) instead of United Kingdom English format (DDMMYYYY). For example, when you view a series of events in the ...

Connecting to the Mashup Center WebDAV when working with themes and skins

This topic provides information on WebDAV, including how to connect to the file store to work with Page Builder 2 static resources.

Community articleDefining custom page modes

Added by Anna G O'Neal on September 23, 2008 |
expanded Abstract
collapsed Abstract
No abstract provided.
Tags:
When developing widgets, you may want to implement the ability to switch between multiple modes, for example edit and view modes. This article provides some suggestions for how to accomplish this.

Let's use a scenario as an example. Let's say you are creating a widget that allows users to view IBM stock quote data from multiple brokers.

Now let's look at the widget definition XML file that controls the mode-switching code. Here is an example of how you can define the content for the two modes:

 
<iw:content
mode="view"
 
--
 
this view displays company name, stock price and broker name
        <![CDATA[    
            <div
 
<span id="company" class="companyLabel"
 
loading...</span
 
Stock Quote: <span id="stock"
 
loading...</span
 
</div
 

            <div
 
Broker: <span id="broker"
 
loading...</span
 
</div
 

            <div
 
<input type="button" name="send" value="Send Data" onclick="iContext.iScope().sendData()"/
 
</div
 

            <div
 
<input type="button" name="configure" value="Edit Broker" onclick="iContext.iScope().editBroker()"/
 
</div
 

        ]]
 

     </iw:content
 

    <iw:content mode="edit"
 
 --
 
this view could be used to edit broker
       <![CDATA[    
           <div
 
<select class="brokerSelection"  size="1"
 

                            <option value="Etrade"
 
Etrade</option
 

                            <option selected value="Ameritrade"
 
Ameritrade</option
 

                     </select
 

           </div
 

           <div
 
<input type="button" name="done" value="Done" onclick="iContext.iScope().switchBroker();"/
 
</div
 

        ]]
 

    </iw:content
 


The widget allows users to select among multiple brokers and display the latest data for each broker. Here is what the widget looks like in view mode:



When you click Edit Broker, the widget fires the following onModeChanged event:

this.iContext.iEvents.fireEvent("onModeChanged",null,
"{newMode:'edit'}");


As a result, the widget switches to edit mode. In edit mode, you can  select a different broker in a drop-down list, as shown here:



When the widget in view mode fires the onModeChanged event, the widget framework catches the event, and it essentially replaces the widget in view mode with the widget in edit mode. The framework also invokes the event handler of the onedit event, which is used to initialize the data  for the new mode. In the following example, the onedit event is defined in the iWidget encapsulation class, gets broker from some specified attributes, and finally sets the broker to the default one:


onedit:function(){
          var element = this.iContext.getElementByClass("brokerSelection");
          var attributesItemSet = this.iContext.getiWidgetAttributes();  
          var broker = attributesItemSet.getItemValue("broker");
          if (typeof broker == "undefined" || broker == null) return;
          element = element[0];
          for (var i=element.options.length-1; i
 
= 0;i--) {
              var value = element.options[i].value;
              if (value != null && value == broker) {
                    element.options[i].selected = true;
              }
          }
     }


Now, still in edit mode, let's say you select Etrade as the broker and click Done. This switches the widget back to view mode, as shown here:

 

In this case, the widget defines an onview event handler in the encapsulation class. This reinitializes the data for the widget in view mode so that the data that is changed in edit mode can be picked up in view mode.

You can retrieve the current mode of your widget by using the following API:
 
var mode = iContext.getiDescriptor().getItemValue("mode");


You can also use other page components such as the skin widget to switch the widget mode by using the following API:
 
serviceManager.getService("eventService").fireEvent(targetWidget,"onModeChanged",
"{newMode:'edit'}"); 


In addition, you can add a root node to the event payload so that the new mode gets rendered under the new root node, as shown here:
serviceManager.getService("eventService").fireEvent(targetWidget,"onModeChanged",
"{newMode:'edit',rootElementId:domNode}");


expanded Attachments (0)
collapsed Attachments (0)
expanded Versions (15)
collapsed Versions (15)
Version Comparison     
VersionDateChanged by              Summary of changes
26Aug 17, 2009 12:34:15 PMAnna G O'Neal  IBM contributor
25Aug 12, 2009 11:52:53 AMAnna G O'Neal  IBM contributor
24Aug 12, 2009 11:51:19 AMAnna G O'Neal  IBM contributor
23Mar 21, 2009 10:34:50 AMAnna G O'Neal  IBM contributor
22Mar 21, 2009 10:25:37 AMAnna G O'Neal  IBM contributor
21Mar 21, 2009 10:21:42 AMAnna G O'Neal  IBM contributor
20Mar 20, 2009 11:23:15 AMAnna G O'Neal  IBM contributor
19Mar 20, 2009 11:02:48 AMAnna G O'Neal  IBM contributor
18Mar 20, 2009 9:34:10 AMAnna G O'Neal  IBM contributor
17Mar 19, 2009 4:28:45 PMAnna G O'Neal  IBM contributor
16Dec 7, 2008 11:23:19 AMAnna G O'Neal  IBM contributor
15Dec 7, 2008 11:19:57 AMAnna G O'Neal  IBM contributor
14Dec 7, 2008 11:17:32 AMAnna G O'Neal  IBM contributor
12Nov 21, 2008 10:59:04 AMAnna G O'Neal  IBM contributor
This version (0)Sep 23, 2008 2:58:09 PMAnna G O'Neal  IBM contributor
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMSocialBizUX on Twitter
  • FacebookIBMSocialBizUX on Facebook
  • ForumsLotus product forums
  • BlogsIBM Social Business UX blog
  • Community LinkIBM Collaboration Solutions
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use