2

We have built an Xpage application with a tabbed container inside. The first page of the tab container holds a view, when clicked on a document inside this view, a new tab with the corresponding document is added to the tabcontainer. This new tabpage holds a panel with the scr attribute, the url of the to be displayed page is given to this panel's src attribute. The result is that we have a tabpage with an iframe, the iframe holds our document page.

Problem:

From inside this iframe we need to get a component (SSJS or Java) from our parent webpage. The getComponent function does not work in this case, because it will only search inside the current component tree (of the iFrame not the parent page).

I'm looking for a way to get a component from the parent page...

Any ideas on how to accomplish this?

Thanks :-)

Kraeven
  • 21
  • 4
  • You don't need a component from the other page. You need a managed bean storing the value you want to access. – Sven Hasselbach Jul 31 '15 at 10:34
  • As Sven says, a java object in the sessionScope could be an option. If you just need to pass a text, maybe you could pass it to the iframe as an url param. – Txemanu Jul 31 '15 at 10:45
  • In this case I'm trying to reuse an existing dialog box () from the main page. This dialog box is inside a custom control which holds the application layout and some other common things. – Kraeven Jul 31 '15 at 12:24
  • I think you overcomplicate it. Why not to use dialog as Custom Control and use it inside your document page? – Frantisek Kossuth Jul 31 '15 at 13:04
  • Yes of course that would be a clean solution, but the interest in doing so is mainly that we display a lot of different xpages in these tabs. So that requires us to add this custom control to all of them. The idea is also that people can open many very complex documents on the main page, so in the end any and all components that can be shared could benefit the overall performance of the application... – Kraeven Jul 31 '15 at 15:02

2 Answers2

0

1) Create a managed bean

    package mypackage;

    import javax.faces.component.UIComponent;

    public class MyComponentBean {

        private  UIComponent component;

        public void setComponent(UIComponent component) {
            this.component = component;
        }

        public UIComponent getComponent() {
            return component;
        }

    }

2) Add the managed bean to faces-config.xml in sessionScope

<?xml version="1.0" encoding="UTF-8"?>
<faces-config>

  <managed-bean>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-bean-name>componentBean</managed-bean-name>
    <managed-bean-class>mypackage.MyComponentBean</managed-bean-class>
  </managed-bean>

</faces-config>

3) Add the bean as binding to your component on Page 1

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:inputText
        id="inputText1"
        binding="#{componentBean.component}">
    </xp:inputText>

    <xp:br />

    <xp:button
        value="Label"
        id="button1">
        <xp:eventHandler
            event="onclick"
            submit="true"
            refreshMode="partial" refreshId="inputText1">
        </xp:eventHandler>
    </xp:button>

</xp:view>

4) Access the component's on page 2 (in this example the value of the component)

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:label
        value="#{componentBean.component.value}"
        id="label1">
    </xp:label>

    <xp:br />

    <xp:button
        value="Label"
        id="button1">
        <xp:eventHandler
            event="onclick"
            submit="true"
            refreshMode="partial" refreshId="label1">
        </xp:eventHandler>
    </xp:button>
</xp:view>
Sven Hasselbach
  • 10,455
  • 1
  • 18
  • 26
  • The component I need to get is the dialogbox. When I loop through the code in the java debugger, I see that I do get a handle on the dialogbox component. When the code then calls dialog.show() nothing happens, the page keeps "Waiting for server..." – Kraeven Jul 31 '15 at 14:49
  • I don't understand what you are trying to implement. But something says me that the way how you do it is fundamentally wrong. – Sven Hasselbach Aug 02 '15 at 13:24
  • Well I guess this was more a general question to see what could be achieved, this way of binding components to a managed bean is very interesting and it will be useful in the future. For the dojo dialog box control, this approach is just wrong I guess. I will just add the component to these pages and call it a day ;-) – Kraeven Aug 03 '15 at 09:56
0

Thanks for your advise guys! I went for the following approach, by using the view.postScript command, I was able to trigger a button on the main page, this button fires up my dialogbox :-)

 view.postScript("parent.document.getElementById('view:_id1:_id2:btnDisplayDialog').click();");
Kraeven
  • 21
  • 4