Dynamically create context menu

I'm trying to create a context menu based on a certain af:commandImageLink.
I have an af:popup with an af:menu in my page. I bound the af:menu to my bean so I can change the content. I didn't put any children in the menu to start because I want to add the children based on the image that's click.
I added an af:showPopupBehavior to show my popup on click. The idea was that I wanted to use the actionListener of the af:commandImageLink to dynamically create the menu that I need. But it seems that the actionListener fires after the showPopupBehavior most times. On the first click, it looks like the actionListener fires first then the showPopupBehavior. After that, it seems the actionListener always fires after.
So it looks like this is not really supposed to work.
Does anyone have any suggestions on how this should be made to work?

Thanks a lot Timo,
This does allow me to control when the popup shows up.
I modified the code you gave slightly to include code to align the popup:
    public static void showPopup(String popupId, String alignId) {
        FacesContext context = FacesContext.getCurrentInstance();
        StringBuilder script = new StringBuilder();
        script.append("var popup = AdfPage.PAGE.findComponent('").append(popupId).append("'); ").append("if (!popup.isPopupVisible()) { ")
            .append("var hints = {}; ").append("hints[AdfRichPopup.HINT_ALIGN_ID] = '").append(alignId).append("'; ")
            .append("hints[AdfRichPopup.HINT_ALIGN] = AdfRichPopup.ALIGN_AFTER_END; ").append("popup.show(hints);}");
        ExtendedRenderKitService erks = Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
        erks.addScript(context, script.toString());
    }I still have some problems though. I need to give some more context on this.
So I have an af:iterator that shows a list of images. I'm trying to popup a context menu when they click the image. The menu needs to be aligned relative to the image that was clicked.
However, when I tried to get the ID from the ActionEvent, I get the design time ID which should not be the same as the run time ID because the iterator would have created multiple instances of the image, each with a unique ID. I'm assuming that's why the alignment is not working.
Am I missing something here?
Also, I seem to be having problems with modifying the menu. Here's my bean code:
    private RichMenu baseMenu;
    public void imageActionListener(ActionEvent actionEvent) {
        Object o = actionEvent.getComponent();
        RichCommandImageLink image = (RichCommandImageLink)o;
        DCIteratorBinding iteLoc = ADFUtils.findIterator("OpItemLocationsVO2Iterator");
        for(Row row : iteLoc.getAllRowsInRange()) {
            OpItemLocationsVORowImpl r = (OpItemLocationsVORowImpl)row;
            RichCommandMenuItem a = new RichCommandMenuItem();
            Number n = r.getItelocId().getSequenceNumber();
            a.setId("i" + r.getItelocId().getSequenceNumber().toString());
            a.setText(r.getItelocId().getSequenceNumber().toString());
            baseMenu.getChildren().add(a);
        AdfFacesContext.getCurrentInstance().addPartialTarget(baseMenu);
        showPopup("vmenu", image.getId());
    }So in my popup, I added a menu and I bound that menu to this bean. The idea was that whenever an image was clicked, I would remove all the children from the menu, then add the new ones. There would be a master-detail relationship between the image's iterator and the menu that's supposed to show up.
The other problems that I'm getting with this is that the menu is not changing when I click on a different image. When I debug, I'll see the correct values being added, but nothing changes on the screen. It's always showing the first popup that was ever created. Also, I don't know how to remove the previous children. There doesn't seem to be an API to remove the children.
Thoughts?

Similar Messages

  • Creating Context Menu for JTree Node

    Hi to all,
    I need to create Context Menu, when i right click on any Tree Node.
    Context Menu should contain selected node information.
    if you click on one tree node named as "AAAA"
    Context Menu Format is as follows
    AAAA
    Create New
    Delete
    If any one knows, please help me

    Here is something for you to start
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=538065
    Denis Krukovsky
    http://dotuseful.sourceforge.net/

  • How to create Context Menu for Full Screen ALV

    Dear Experts,
    Please tell me the procedure to create Context Menu for ALV Grid (full screen ALV using SLIS ).
    Regards
    Arnab

    Hi,
    Check the demo program BCALV_GRID_06

  • Creating Context menu on TREE control

    Hi,
    How to create Context menu on Tree (Nodes and Subnodes) in Web Dynpro for ABAP.
    Helpful answers will be rewarded.
    Regards,
    Jitesh.

    Hi
    You could go to the following link http://help.sap.com/saphelp_nw2004s/helpdata/en/21/ad884118aa1709e10000000a155106/frameset.htm .
    Also you could have a closer look at wdr_test_events example
    Thanks
    Anzy

  • Creating context menu on TREE

    Hi,
    How to create Context menu on Tree (Nodes and Subnodes) in Web Dynpro for ABAP.
    Helpful answers will be rewarded.
    Regards,
    Jitesh.

    hi jitesh,
    check out the sample tutorials in sap under the package : SWDP_DEMO_TUTORIALS
    thanks
    jaideep
    reward points if useful...

  • Dynamically loading context menu

    Hi,
    I am dynamically loading context menu as per XML.
    As I am doing it dynamically, only one callback function is
    used.
    Problem arises here.
    One callback function is not able to identify which menuitem
    is clicked.
    If I am able to identify which menuitem is clicked, so I can
    do different things for every menu in single function.
    function generateRef()
    trace("inside generate reference:generating references for
    individual screen");
    for(var i=0;i<resObj.firstChild.childNodes.length;i++)
    var str = datObj.getCurrent().attributes["path"];
    var string:Array = str.split(">");
    if(string[0] == resObj.firstChild.childNodes
    .attributes["name"])
    for(var j=0;
    j<=resObj.firstChild.childNodes.childNodes.length-1; j++)
    if(datObj.getCurrent().attributes["id"] ==
    resObj.firstChild.childNodes
    .childNodes[j].attributes["id"])
    var PD = new ContextMenuItem("PD", dummy, true, false, true);
    scrRef.customItems.push(PD);
    for(var a=0;
    a<resObj.firstChild.childNodes.childNodes[j].attributes["PDLink"];
    a++)
    var z=a+1;
    PDLArr[a]=_root.resObj.firstChild.childNodes
    .childNodes[j].attributes["PDL"+z];
    PDNArr[a]=_root.resObj.firstChild.childNodes.childNodes[j].attributes["PDN"+z];
    var str = PDNArr[a];
    var curRef = new ContextMenuItem(str, clicking, false, true,
    true);
    scrRef.customItems.push(curRef);
    var MK = new ContextMenuItem("MK", dummy, true, false, true);
    scrRef.customItems.push(MK);
    for(var b=0; b<resObj.firstChild.childNodes
    .childNodes[j].attributes["MKLink"]; b++)
    var z=b+1;
    MKLArr
    =_root.resObj.firstChild.childNodes
    .childNodes[j].attributes["MKL"+z];
    MKNArr
    =_root.resObj.firstChild.childNodes
    .childNodes[j].attributes["MKN"+z];
    var str = MKNArr
    var curRef = new ContextMenuItem(str, clicking, false, true,
    true);
    scrRef.customItems.push(curRef);
    var EW = new ContextMenuItem("EW", dummy, true, false, true);
    scrRef.customItems.push(EW);
    for(var c=0; c<resObj.firstChild.childNodes
    .childNodes[j].attributes["EWLink"]; c++)
    var z=c+1;
    EWLArr[c]=_root.resObj.firstChild.childNodes.childNodes[j].attributes["EWL"+z];
    EWNArr[c]=_root.resObj.firstChild.childNodes
    .childNodes[j].attributes["EWN"+z];
    var str = EWNArr[c];
    var curRef = new ContextMenuItem(str, clicking, false, true,
    true);
    scrRef.customItems.push(curRef);
    var WP = new ContextMenuItem("WP", dummy, true, false, true);
    scrRef.customItems.push(WP);
    for(var d=0;
    d<resObj.firstChild.childNodes.childNodes[j].attributes["WPLink"];
    d++)
    var z=d+1;
    WPLArr[d]=_root.resObj.firstChild.childNodes
    .childNodes[j].attributes["WPL"+z];
    WPNArr[d]=_root.resObj.firstChild.childNodes.childNodes[j].attributes["WPN"+z];
    var str = WPNArr[d];
    var curRef = new ContextMenuItem(str, clicking, false, true,
    true);
    scrRef.customItems.push(curRef);
    }//end of if id
    }//for
    }//if
    }//for
    In for loop I am inserting context menu, but callback
    function is same, which is 'CALLING'. I want to detect for which
    menu item CALLING function is called.
    Please help ASAP.
    Thanks in advanced.

    Hi,
    I am dynamically loading context menu as per XML.
    As I am doing it dynamically, only one callback function is
    used.
    Problem arises here.
    One callback function is not able to identify which menuitem
    is clicked.
    If I am able to identify which menuitem is clicked, so I can
    do different things for every menu in single function.
    function generateRef()
    trace("inside generate reference:generating references for
    individual screen");
    for(var i=0;i<resObj.firstChild.childNodes.length;i++)
    var str = datObj.getCurrent().attributes["path"];
    var string:Array = str.split(">");
    if(string[0] == resObj.firstChild.childNodes
    .attributes["name"])
    for(var j=0;
    j<=resObj.firstChild.childNodes.childNodes.length-1; j++)
    if(datObj.getCurrent().attributes["id"] ==
    resObj.firstChild.childNodes
    .childNodes[j].attributes["id"])
    var PD = new ContextMenuItem("PD", dummy, true, false, true);
    scrRef.customItems.push(PD);
    for(var a=0;
    a<resObj.firstChild.childNodes.childNodes[j].attributes["PDLink"];
    a++)
    var z=a+1;
    PDLArr[a]=_root.resObj.firstChild.childNodes
    .childNodes[j].attributes["PDL"+z];
    PDNArr[a]=_root.resObj.firstChild.childNodes.childNodes[j].attributes["PDN"+z];
    var str = PDNArr[a];
    var curRef = new ContextMenuItem(str, clicking, false, true,
    true);
    scrRef.customItems.push(curRef);
    var MK = new ContextMenuItem("MK", dummy, true, false, true);
    scrRef.customItems.push(MK);
    for(var b=0; b<resObj.firstChild.childNodes
    .childNodes[j].attributes["MKLink"]; b++)
    var z=b+1;
    MKLArr
    =_root.resObj.firstChild.childNodes
    .childNodes[j].attributes["MKL"+z];
    MKNArr
    =_root.resObj.firstChild.childNodes
    .childNodes[j].attributes["MKN"+z];
    var str = MKNArr
    var curRef = new ContextMenuItem(str, clicking, false, true,
    true);
    scrRef.customItems.push(curRef);
    var EW = new ContextMenuItem("EW", dummy, true, false, true);
    scrRef.customItems.push(EW);
    for(var c=0; c<resObj.firstChild.childNodes
    .childNodes[j].attributes["EWLink"]; c++)
    var z=c+1;
    EWLArr[c]=_root.resObj.firstChild.childNodes.childNodes[j].attributes["EWL"+z];
    EWNArr[c]=_root.resObj.firstChild.childNodes
    .childNodes[j].attributes["EWN"+z];
    var str = EWNArr[c];
    var curRef = new ContextMenuItem(str, clicking, false, true,
    true);
    scrRef.customItems.push(curRef);
    var WP = new ContextMenuItem("WP", dummy, true, false, true);
    scrRef.customItems.push(WP);
    for(var d=0;
    d<resObj.firstChild.childNodes.childNodes[j].attributes["WPLink"];
    d++)
    var z=d+1;
    WPLArr[d]=_root.resObj.firstChild.childNodes
    .childNodes[j].attributes["WPL"+z];
    WPNArr[d]=_root.resObj.firstChild.childNodes.childNodes[j].attributes["WPN"+z];
    var str = WPNArr[d];
    var curRef = new ContextMenuItem(str, clicking, false, true,
    true);
    scrRef.customItems.push(curRef);
    }//end of if id
    }//for
    }//if
    }//for
    In for loop I am inserting context menu, but callback
    function is same, which is 'CALLING'. I want to detect for which
    menu item CALLING function is called.
    Please help ASAP.
    Thanks in advanced.

  • How To Create Context Menu In Module Pool

    Moderator message: do not offer points
    hello guru's
    Please help me regarding creation of context menu in MODULE POOL Programming.
    pleaase send me link or procedure to create it.
    <<text removed>>
    waiting for reply
    Edited by: Matt on Feb 20, 2009 3:13 PM

    Do a search first:
    [link1|context menus;
    [link2|http://help.sap.com/saphelp_nw04/helpdata/en/e2/5d3bb2e06411d295a900a0c94260a5/frameset.htm]
    etc. etc.

  • Accessing Dynamically created Context

    Hi,
    I want to actually read the context which is dynamically created. I have a basic doubt that, will that context contain all the records or just metadata in context? How to read certain records from the context. I dont want to populate them to view via some textbox etc, actually using that data I want to create some xml. so I need to read all the records which are available in that context.
    Please let me know your inputs asap.
    Best REgards,
    Ritesh

    Hi Mehta,
    You can create both nodes as well as attributes in context dynamically. If you are creating a context attribute it will have only a single value.If you are creating context nodes it will have multiple values
    IWDNode node = wdContext.getChildNode("<node name>",IWDNode.LEAD_SELECTION);
    IWDTextview text = (IWDTextview)view,createElement(IWDTextview.class,null)
    text.bindText(node.getElementAt(<give index>).getAttribute())
    Hope this helps you
    Try to create context attributes and nodes statically
    Hope this helps you
    Regards
    Rohit

  • Creating Context Menu in ALV tree defined inside DOCKING CONTAINER

    Dear Experts.
    Can you please tell me which EVENTS should i use in CLASS: CL_GUI_SIMPLE_TREE to get a Context menu after right click on any tree node in ALV Tree which has been defined inside a Docking Container.
    Regards Arnab.

    Hi,
    Check Program SAPSIMPLE_TREE_CONTEXT_MEN_DEM and check event node_context_menu_request
    Hope this helps you.
    Thanks,
    Prashanth
    Edited by: Prashanth KR on Jun 2, 2009 7:50 AM

  • How to delete a dynamically created context node ?

    Hi
      I have created a context node dynamically and have added the check boxes to the node.
      But when i am refreshing the page it is giving me the following excepiton:
    com.sap.tc.webdynpro.progmodel.context.ContextException: DataNodeInfo(DwdReportView.Person): duplicate name for attribute attr1
    I am writing the following code in wdDoExit() method so that the node is invalidated  and all dynamically added nodes and attributes are destroyed from the metadata.
    The code  is :
         wdContext.getContext().reset(false);
    or
         wdContext.getContext().reset();
    or
                         wdContext.nodeName().invalidate();
    I have tried all the above mentioned code  snippets but it is still giving me the same exception.
    Please help me  resolve this issue.
    Thanks in advance.
    Regards
    Shaily

    Shally,
    A better forum to place your question is the forum.
    To your question: the wdDoExit() method is only called once i.e. when the view is destroyed from memory. Just like the wdDoInit() mehtod is called only once at initialisation of the view.
    Try refactoring your code, so that upon initialising of your context, the old version of it is removed.
    Hope this helps.
    Regards,
    Alain

  • How to access the structure of a dynamically created context node/element

    Hi All,
    in method wddoinit I have added a context node and some attributes
    lo_node = wd_context->get_child_node( name = wd_this->wdctx_instructors ).
      lo_node_info = lo_node->get_node_info( ).
      lo_node_info = lo_node_info->add_new_child_node( name                  = 'OCCUPANCY'
                                                       is_mandatory          = abap_true
                                                       is_multiple           = abap_false
                                                       is_multiple_selection = abap_false ).
          lo_node_info->add_attribute( ls_attr ).
    So far, I have node INSTRUCTORS (0...n) with a subnode OCCUPANCY (1...1)
    In the supply_method of INSTRUCTORS I would like to fill the instructors node and the OCCUPANCY subnode.
    The thing is I do not know the structure of the dynamicaly created subnode OCCUPANCY there. How can I get a description of this node (that, what in non-dynamic programming would be wd_this->element_occupancy...)??
    THANKS,
    Johannes

    ...I got this one solved by myself...
    I simply added this coding:
    lo_node_info = lo_node->get_node_info( ).
      lt_attributes = lo_node_info->get_attribute_names( ).
    This appers to be enough information to be good to gogo
    Thanks anyway.

  • Abnormality while creating Context Menu

    Hi All,
              When i was working with context menus it is found that the context menus having label like "Copy" "Delete" are not been created..
    Any Idea..
      Thanks And Regards
       Abdul Jaleel C

    If found out that some labels are simply not displayed. If you create a custom menu item with a label like "Adobe" for example, it won't appear.
    I also created this method to ease the addition of menu items:
                 private function createMenuItem(
                     menu:ContextMenu,
                     handler:Function,
                     caption:String,
                     separator:Boolean,
                     enabled:Boolean = true,
                     visible:Boolean = true):void
                     var menuItem:ContextMenuItem = new ContextMenuItem(caption, separator, enabled, visible);
                     menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handler);
                     menu.customItems.push(menuItem);                

  • Context menu's in Alv Report (Grid)

    hello,
    what i have done- i have created a ALV report  by using the function modlue REUSE_ALV_GRID_DISPLAY.
    what i want-  When  user clicks with Right mouse button on some cell.
                              context menu should get displayed. a list of menu should appear  then user can select one of these options        and   eventually i'll on user command.
    however i know the concept of context menu's and i have created context menu on screen elements in module pool.
    but i have no idea whether these menu's can be created on ALV Grid.(simple ALv Grid----not ABAP OOPS)

    check the program BCALV_GRID_06, it gives a demo of context menu functionalty,
    but it uses cl_gui_alv_grid

  • How to set the cardinality property as 1..n for a dynamically created node

    Hi...everybody
        I am creating Dropdown by index UI element and the
    context atrributes dynamically.To bind multiple data to a dropdown
    the cardinality property of the node should be 0..n or 1..n,
    But i could not set the property of the dynamically created context node to 0..n ...
    can any body suggest me..
    I implemented the following code in WDDoModify View
    IWDTransparentContainer tc=(IWDTransparentContainer)view.getElement("RootUIElementContainer");
    IWDNodeInfo node = wdContext.getNodeInfo().addChild("DynamicNode",null,true,true,false,false,false,true,null,
              null,null);
    IWDAttributeInfo strinfo=node.addAttribute("Value","ddic:com.sap.dictionary.string");
    dbyindex.bindTexts(strinfo);
    tc.addChild(dbyindex);
    I could successfully display one value in the drop down,by adding the following code before the line tc.addchild(dbyindex);
    IWDNode node1=wdContext.getChildNode("DynamicNode",0);
    IWDNodeElement nodeElement=node1.createElement();
    nodeElement.setAttributeValue("Value","Hello");
    node1.addElement(nodeElement);
    but when
    i am trying to bind multiple values i am getting Exception ,,,,

    hi
    you are getting the exception because of cardinality property.
    i.e   true,false and
    you are trying to add morethan one element.
    so,if you want to add morethan one than one element you have to set the cardinality property to true,true (or) false,true.
    In your code do the following modification for changing the cardinality.
    For 0..n -->false,true
          1..n-->true,true
    IWDTransparentContainer tc=(IWDTransparentContainer)view.getElement("RootUIElementContainer");
    IWDNodeInfo node = wdContext.getNodeInfo().addChild("DynamicNode",null,true,true,false,false,false,true,null,
    null,null);
    IWDAttributeInfo strinfo=node.addAttribute("Value","ddic:com.sap.dictionary.string");
    dbyindex.bindTexts(strinfo);
    tc.addChild(dbyindex);
    hope this will solve your problem.
    In addchild(..) the parameters are
    addChild("Name ,
                    Element class for model node ,
                    Is singleton? ,
                    Cardinality ,
                    Selection cardinality ,
                    Initialise lead selection? ,
                    Datatype ,
                    Supplier function ,
                     Disposer function);
    Regards
    sowmya

  • Context Menu How-to Questions

    These could be considered follow-up questions to Kris' Blog entry.
    1) Is there a way to group user-created Context Menu items via XML? Similar to the pre-defined ones (Table) or GeoRaptor's?
    2) Could you share with us some of the ither UI compoents for context menu items like the Table -> Priviliges -> Grant (list items, checkboxes with flow of control logic)?

    Well... The grants one is specific. It uses a tag called classname like this
    <item type="PROCEDURE"
    reloadparent="true"
    className="oracle.dbtools.raptor.dialogs.actions.GrantAction">
    <title>Grant</title>
    </item>
    Then the GrantAction class has to extend from this oracle.dbtools.raptor.dialogs.actions.AbstractMenuAction
    However, it's really easy to group actions just wrap them in a <folder> like this:
    <folder type="MATERIALIZED VIEW">
    <name>Privileges</name>
    <!-- your items go here.....-->
    </folder>
    -kris

Maybe you are looking for

  • Unable to run a java program...

    Hi. I am trying to run a server program that I have implemented, but I'm having some trouble. When I click on the run button, I get the following pop-up message: Could not find the main method. Program will exit! On the console it says the following:

  • Apple TV cable hookup

    Is there cable adapters available that would let you hook up an Apple TV to an older TV with RCA hookups (yellow for video, red and white for audio)?

  • Changed Purchase Order Print output

    Hi Gurus, what output type should i choose to get revised purchase order print output with only changes Regards Vivek

  • Protecting  layout of a report

    Hi Please suggest ways if any to protect  layout of SAP standard report like IW38 etc The need is the lay out need to be used by many but only can be edited by the creator rgds Satish

  • Toplink Application Deployment

    i have a JSF/ADF page which uses a toplink connection to oracle database to populate the table.Its working fine on my embeded oc4j server of JDeveloper 10g v 10.1.3.1.0 3984.I got the following error when i deployed and run it on a standalone applica