12 Replies Latest reply on Aug 11, 2009 4:14 AM by Ilya Shaikovsky

    MenuItem and Iframe

    Ray Wilson Newbie

      I have an Iframe on a web page that I want to have the contents change when different menuitems are clicked. The iframe is initialially loaded with a blank web page.

      I set the menuitem target to the iframe and tried using the action attibute for the page. That just seems to reload the blank page each time. I also tried the actionlistener and in the method tried request redirect with the viewId but that also just loads the blank page.

      I this possible or am I just spinning my wheels. Any help would be appreciated.

        • 1. Re: MenuItem and Iframe
          Nick Belaevski Master

          Hello,

          Please make sure that you are using "server" mode for menu item.

          • 2. Re: MenuItem and Iframe
            Ray Wilson Newbie

            The attribute of the menuitem submitMode is set to "server". I'm guessing that view and viewId are not interpeted correctly by the Iframe since it is not a standared JSF component. Anyone have suggestions?

            • 3. Re: MenuItem and Iframe
              Nick Belaevski Master

              This should work. Does navigation work well if you don't use "target"?

              • 4. Re: MenuItem and Iframe
                Ray Wilson Newbie

                Yes Navigation does work without the target attibute. It replaces the current page with the intended iframe page. The view is correct, it just doesn't load it in the iframe.

                I know the target is refreshing the iframe also. I have logs in my pages to print to the console when the page is loaded. It is just reloading my blank page when I click on the menu.

                • 5. Re: MenuItem and Iframe
                  Nick Belaevski Master

                  Please post page code.

                  • 6. Re: MenuItem and Iframe
                    Ray Wilson Newbie

                    What I found out is that if I use the target attribute, the action is not fired.

                    I set the target to the iframe name and also to "_blank" and it did not fire.

                    Hear is the menu from the menu page and following that is the iframe. And lastly the action function from the header bean. I have the views defined as constants in the beans they are attacted to.

                    Thanks
                    ============================================
                    <h:form id="formHeaderMenu">
                    <rich:toolBar id="tbarHeaderMenu" width="100%">
                    <rich:toolBarGroup id="tbarGroupHeaderMenu" location="left">
                    <rich:dropDownMenu id="menuHome" value="Home">
                    <rich:menuItem id="menuItemBridgeHome" value="Bridge Home" action="#{headerBean.actionHome}"></rich:menuItem>
                    <rich:menuItem id="menuItemEngineeringHome" value="Engineering Home" action="#{headerBean.actionHome}"></rich:menuItem>
                    </rich:dropDownMenu>
                    <rich:dropDownMenu id="menuSearch" value="Search">
                    <rich:menuItem id="menuItemAssetSearch" value="Asset Search" actionListener="#{headerBean.actionOpenSearchDialog}" submitMode="ajax" reRender="searchDialog"></rich:menuItem>
                    <rich:menuItem id="menuItemAssetSearch2" value="Asset Search Iframe" submitMode="server" action="#{headerBean.actionAssetSearch}" target="frameDialog"></rich:menuItem>
                    </rich:dropDownMenu>

                    </rich:toolBarGroup>
                    </rich:toolBar>
                    </h:form>

                    ========================================
                    <f:verbatim>
                    <IFRAME name="frameDialog" src='<%=request.getContextPath() + "/jsp/dialog/blankDialog.faces"%>' scrolling="no" frameborder="0" id="frameDialog" marginheight="0" marginwidth="0" style="position: absolute; margin: 0px; z-index: 99; border: outset; display: none">
                    </f:verbatim>
                    ========================================

                    public String actionAssetSearch() {
                    String view;
                    NavigationBean navigationBean = (NavigationBean)FacesUtil.getManagedBean(NavigationBean.MANAGED_BEAN_NAME);
                    if("C".equals(navigationBean.getAssetType())) {
                    selectedTab = "tabCulvert";
                    view = CulvertSearchBean.VIEW;
                    }
                    else if("T".equals(navigationBean.getAssetType())) {
                    selectedTab = "tabTunnel";
                    view = TunnelSearchBean.VIEW;
                    }
                    else {
                    selectedTab = "tabBridge";
                    view = BridgeSearchBean.VIEW;
                    }
                    return view;
                    }


                    • 7. Re: MenuItem and Iframe
                      Ray Wilson Newbie

                      The version of Richfaces I'm using is 3.3.1 with Java 5.0 and JSF 1.2

                      • 8. Re: MenuItem and Iframe
                        Ilya Shaikovsky Master

                        removing display none; resolves problem for me :)

                        • 9. Re: MenuItem and Iframe
                          Ray Wilson Newbie

                          The page when loaded changes that style to display = 'block'.

                          var me = parent.document.getElementById(window.name);



                          function bodyLoaded() {
                          me.style.width = "750px";
                          me.style.height = "440px";

                          me.style.left = parent.document.body.scrollLeft + ((parent.body.clientWidth-me.offsetWidth)/2);
                          me.style.top = parent.document.body.scrollTop + ((parent.document.body.clientHeight-me.offsetHeight)/2);
                          me.style.display = "block";

                          }



                          Also that doesn't explain why the target attribute keeps the action method from being called. With target = '_blank', it doesn't even care about the iframe and the action method is not invoked.

                          Did you actually try this or did you just see the style and assume I didn't know what I was doing?

                          I tried it, the action is not firing when the target attribute is set.

                          • 10. Re: MenuItem and Iframe
                            Nick Belaevski Master

                            We tried it and it worked.

                            • 11. Re: MenuItem and Iframe
                              Ray Wilson Newbie

                              Could you send what you tried?

                              • 12. Re: MenuItem and Iframe
                                Ilya Shaikovsky Master

                                 

                                 <h:form id="myform">
                                 <rich:toolBar>
                                 <rich:menuItem target="_blank" action="sortingFeature" value="sortingFeature" submitMode="server"/>
                                 </rich:toolBar>
                                 </h:form>
                                

                                 <h:form id="myform">
                                 <rich:toolBar>
                                 <rich:menuItem target="frameDialog" action="sortingFeature" value="sortingFeature" submitMode="server"/>
                                 </rich:toolBar>
                                 </h:form>
                                 <f:verbatim>
                                <iframe name="frameDialog" src="/richfaces-demo/welcome.jsf" scrolling="no" frameborder="0" id="frameDialog" marginheight="0" marginwidth="0" style="position: absolute; margin: 0px; z-index: 99; border: outset; width: 800px; height: 600px;"/>
                                </f:verbatim>
                                


                                both code snippets works fine for me.

                                And we always checking the sample before posting if enough info provided. And could answer without such checking if the mistake is obvious or not enough info.