Skip to main content link. Accesskey S
  • Anonymous
  • Log on
  • Help
  • IBM logo
  • IBM Mashup Center wiki
  • All Wikis
  • Home
  • Community Articles
  • Product Documentation
  • Learning Center


Search

Advanced Search
IBM Translated Product Documentation...

 Developing with Mashup Center 3.0.0.1

 Planning, Installing, Configuring Mashup Center 3
 Enterprise Content Management Widgets 4.5.2.1 documentation

 IBM Mashup Center 2.0.0.2 documentation

Tag Cloud

  • 2.0
  • 3.0
  • 3.0.0.1
  • action widgets
  • actions
  • admin
  • administering
  • administration
  • administrator
  • adminstering
  • Ajax
  • AJAX proxy
  • annotate function
  • annotator
  • API
  • api reference
  • benchmark testing
  • catalog
  • configuing
  • configuration
  • configure
  • configuring
  • creating
  • creating mashups
  • data
  • data mashup builder
  • data mashups
  • database
  • DB2
  • demo
  • deploy
  • deployment
  • designing applications
  • developer
  • developing
  • developing mashups
  • developing widgets
  • documentation
  • ECM Widgets
  • editing
  • Enterprise Content Management Widgets
  • errors
  • events
  • examples
  • explanations
  • feed
  • feed mashups
  • feeds
  • format
  • functions
  • getting started
  • greenhouse
  • guide
  • IMS database feeds
  • IMS feeds
  • IMS transaction feeds
  • installation
  • installing
  • mashup
  • MashupHub
  • mashuphub examples
  • mashuphub users guide
  • mashups
  • messages
  • migrating
  • objects
  • operators
  • Oracle
  • pages
  • payload types
  • pdf
  • performance
  • performance tuning
  • planning
  • product
  • programming
  • proxy
  • rest services
  • security
  • service
  • spaces
  • themes
  • troubleshooting
  • tutorial
  • tutorials
  • upgrading
  • user
  • users
  • v1.0
  • v1.1
  • v2.0
  • v2.0.0.2
  • v4.5.2.1
  • video
  • WAR
  • widget
  • widgets
  • widgets
  • wire
  • YouTube
InformationInformation
You are currently viewing machine translated content. IBM translation might be available. Click IBM Translated Product Documentation to see what is available.X


Home > Developing with Mashup Center 3.0.0.1 > Defining custom widget modes
Rate this article 1 starRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars
(Current editable edition)
Original noneditable edition
Current editable edition
(Original noneditable edition)

Defining custom widget modes 

expanded Abstract
collapsed Abstract
When developing widgets, you might want to implement the ability to switch among various modes, for example, edit, view, help, and print modes. This article provides some suggestions about how to switch widget modes.



When developing widgets, you might want to implement the ability to switch among various modes, for example, edit, view, help, and print modes. This article provides some suggestions about how to switch widget modes.

By default, widgets that are provided with Mashup Center provide the ability for you to switch between edit and view modes. When the widget is in view mode, you can click the display menu and select Edit Settings to open the widget in edit mode. Both widget modes are visible on the page. However, only the edit mode has focus. After you edit the settings and click Save, the onModeChanged event gets fired, and the edit mode closes, leaving only the view mode available on the page.

Now let us talk about how you can add custom modes such as view and edit modes to your widgets

Step 1: Updating the widget definition file

The first step in the process of creating custom modes is to update the widget definition XML file (widget.xml) that controls the mode-switching code. Here is an example of how you can define the content for three modes: view, edit, and print:

<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>
   ]]&gt;  
   </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>    
]]&gt;
 </iw:content>
<iw:content mode="print">  --> this view could be used to edit broker
       <! [CDATA [    
         print mode
        ]]&gt; 
    </iw:content>


Step 2: Defining event handlers for each mode

After you update the widget definition file, the next step is to define the event handlers for each custom mode. To help illustrate how to accomplish this, let us look at an example widget that allows users to view IBM® stock quote data from multiple brokers. You can select among multiple brokers and display the latest data for each broker. Here is what the widget looks like in view mode:


Widget in view mode

Notice how the widget's default broker is Ameritrade. Now let's look at what happens when you want to select a different broker.

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 list, as shown here:


Widget in edit mode
When the widget in view mode fires the onModeChanged event, the widget framework 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 an encapsulation class, gets broker from some specified attributes, and finally sets the broker to be 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 <em>></em>= 0;i--) { 
    var value = element.options [i].value; 
    if (value != null && value == broker) { 
          element.options [i].selected = true; 
    } 
} 
} 


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


Widget in view mode after selecting Etrade and clicking Done

In this case, the widget defines an onview event handler in an 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.

Step 3: Using APIs

See the following table for how to use APIs:

Table 1. APIs
API Description
this.iContext.iEvents.fireEvent
("onModeChanged",
null, "{newMode:'edit'}");

Switches widget modes.
var mode = iContext.getiDescriptor
().getItemValue
("mode"); 

Retrieves the current widget mode.
serviceManager.getService
("eventService").fireEvent
(targetWidget,"onModeChanged", 
"{newMode:'edit'}");

Invokes new widget modes in other page components such as the skin widget.
serviceManager.getService
("eventService").fireEvent
(targetWidget,"onModeChanged", 
"{newMode:'edit'
,rootElementId:domNode}");

Provides a root node in the event payload so that the new widget mode gets rendered under the new root node.


expanded Article information
collapsed Article information
Category:
Developing with Mashup Center 3.0.0.1, Product documentation, IBM Mashup Center 3.0.0.1 documentation, Product Documentation,
Tags:
developing mashups, spaces, pages, themes, widgets

This Version: Version 1 May 19, 2011 6:31:19 PM by IBM  IBMer

expanded Attachments (3)
collapsed Attachments (3)

 


File TypeSizeFile NameCreated On
image/jpeg 10 KB mode1.jpg 5/19/11 6:39 PM
image/jpeg 8 KB mode2.jpg 5/19/11 6:39 PM
image/jpeg 10 KB mode3.jpg 5/19/11 6:39 PM
expanded Versions (1)
collapsed Versions (1)
Version Comparison     
Version Date Changed by               Summary of changes
This version (1) May 19, 2011 6:31:19 PM IBM  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedSubscribe to RSSHelpAbout
  • All Lotus and WebSphere Portal wikis
  • IBM developerWorks
  • IBM Software support
  • IBM Social Business User Experience Blog
  • IBMSocialBizUX on Twitter
  • IBMSocialBizUX on Facebook
  • Lotus product forums
  • IBM Social Business UX blog
  • IBM Collaboration Solutions
  • Recently added feedRecently added
  • Recently edited feedRecently edited
  • Recently added comments feedRecently Added Comments
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Contact IBM
  • IBM Terms of use
  • Wiki terms of use