Select to view content in your preferred language

Open Widget from another Widget

3169
7
09-28-2010 10:45 AM
BobCarberry
Deactivated User
Is there a way to open a widget from another widget?  I almost got it working I just can't get some of the widget behaviors working correctly.  I created a UI type search widget which consists of an input text box and a list component. This widget is place on the HeaderControllerWidget.  The text box is wired up to several custom .NET webservices.  When the user enters something to search for, the list component becomes visible and populated with possible matches.  When the user selects one of these, another widget (based on WidgetTemplate) with a datagrid appears and is populated with information on the selection made from the list component.  I got all this working fine.  The datagrid populates, I can drag the widget around and minimize it.  The problems I'm having however are:
1. The color/alpha skinning are not applied to the widget, it's white.
2. The widget configuation file is never loaded.
3. When closing the widget, I'm left with a draggable white box that won't disappear.
I'm using ModuleLoader to load the widget.
I'm using the Flex Viewer 2.1  Any suggestions would be great.  Thanks!
Tags (2)
0 Kudos
7 Replies
GregoryKramida
Deactivated User
Hi rcarberry and everyone,

I'm using FlexViewer 2.3.1 for my application and I ran into the same issue - I need to open a widget from another widget.

I've looked at the old thread on this topic , but the FlexViewer version that they're discussing is much older than mine, and there seems to be no way to use the suggestions.

- Thanks in advance.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Gregory,

   You can use this line if you know the widgets id which is the sequential number that is given to the widget when it is created, starting with 0.

ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, 2));
0 Kudos
GregoryKramida
Deactivated User
Thank you very much, Mr. Scheitlin, your solution works perfectly. I played around with similar code, but I never realized that the callback parameter for the AppEvent constructor was optional until I read your reply.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
In Flex Viewer 2.4 this will be built into the viewer but for now if you want to determine the widgets.id than you will need to add this code to the ViewerContainer.mxml

            public var _configData:ConfigData;
            public function getWidgetId(widgetLabel:String):Number
            {
                var id:Number = Number.NaN;
                for (var i:Number = 0; i < _configData.widgets.length; i++)
                {
                    if (_configData.widgets.label == widgetLabel)
                        id = _configData.widgets.id;
                }
                return id;
            }

//find the postConfigHandler function and change this line
var configData:ConfigData = _configData = event.data as ConfigData;
0 Kudos
GregoryKramida
Deactivated User
Thanks.

I just upgraded my app to Flex Viewer 2.4 today, and, if any other developers are interested, this ^ function is accessible via WidgetManager. It can be called from
ViewerContainer.getInstance().widgetManager.getWidgetId(<MyWidgetLabel:String>)


There's also another useful function:
ViewerContainer.getInstance().widgetManager.getWidget(<id:Number>,<optional open-when-not-open:Boolean>)

It returns a whole widget.

Back to the original topic, now (in 2.4) the WIDGET_RUN event is issued by
AppEvent.dispatch(AppEvent.WIDGET_RUN, id)
, where id is an int. This part isn't explicitly mentioned within the Flex Viewer source code comments.
These kinds of events can be consumed by
 AppEvent.AddListener(AppEvent.<EVENT_TYPE>, <Callback>).
0 Kudos
RinatSolorzano_Palero
Deactivated User

Changing a little bit the question, how can I change the data of a Wdiget already opened from another widget. I want to change the source of an image from one widget when i make a selection on another widget. I'm not using WidgetTemplate son i can't use function "open". I'm transfering the data with a TransferDataManager

Thanks

Rinat

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Rinat,

  So if you are not using the BaseWidget at least then you still have access to addSharedData and other widget communication functions. Our you just set a public var in the fidget toy are wanting to change something in and use

ViewerContainer.getInstance().widgetManager.getWidget

to get access to the other widget and then set that public var.

I have no idea what TransferDataManager is...

0 Kudos