2
votes

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 :-)

2
You don't need a component from the other page. You need a managed bean storing the value you want to access.Sven Hasselbach
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
In this case I'm trying to reuse an existing dialog box (<xe:dialog>) from the main page. This dialog box is inside a custom control which holds the application layout and some other common things.Kraeven
I think you overcomplicate it. Why not to use dialog as Custom Control and use it inside your document page?Frantisek Kossuth
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

2 Answers

0
votes

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>
0
votes

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();");