Ssv
Ssv

Reputation: 1059

Bean methods not invoked on JSF page which is included by <iframe>

I have a <p:commandButton> which, oncomplete gives a dialog which contains an iframe. iframe contains another page which contains menu's. I wrote an actionListener on clicking commandbutton a method will execute and make menu's rendered false. Surprisingly the get method's for rendering variable is not calling. Here is my sample code.

<p:commandButton oncomplete="PF('Loc').show();"
                 action="bean.rendermethod"
                 update="createDialog">

    <p:dialog closeOnEscape="true"
              widgetVar="Loc"
              modal="true"
              dynamic="true"
              id="createDialog"
              minimizable="false"
              maximizable="true"
              height="100%"
              width="100%"
              style="background-color:rgb(232, 232, 232) !important;">

        <iframe frameborder="0" height="768" width="100%"
                src="loc.faces"
                name="someName" id="someId" scrolling="auto" />
    </p:dialog>
</p:commandButton>

loc.xhtml:

<p:menubar autoSubmenuDisplay="true"
           effectDuration="0"
           rendered="#{!(createAssociationsBean.splcCreate)}">

    ...

</p:menubar>

Java code:

public void renderMethod() {
    setSplcCreate("true");
}

public String getSplcCreate() {
    return splcCreate;
}

public void setSplcCreate(String splcCreate) {
    this.splcCreate = splcCreate;
}

Upvotes: 0

Views: 580

Answers (2)

BalusC
BalusC

Reputation: 1108642

An <iframe> doesn't include the specified page in the same HTTP request as its parent page. It will be included in a brand new and independent HTTP request. Namely, it's executed by the webbrowser, not the webserver. In effects, the framed page would get its own brand new request scoped bean which is not the same as the one of the parent page.

Moreover, that new HTTP request also doesn't contain any information about the JSF view, so it would also get its own view scoped bean instance, if any. Only if they run in the same HTTP session, then they may share the same session scoped bean instance. But making the bean session scoped has drastic consequences.

Nonetheless, this approach doesn't make any sense. This is the wrong purpose of an <iframe>. Use <ui:include> instead. If your sole concern is having scrollbars and such, simply throw in CSS overflow:scroll on a fixed sized block element like <div>.


Unrelated to the concrete problem, your <p:commandButton action> is not correct due to absence of EL expression braces and thus introduces a major red herring. And, the rendered attribtue referring a String value of "true" is nasty as it's using the wrong data type for the value it holds. If you want a boolean type, just use boolean instead of String. I can imagine that this all is result of fiddling around in the dark and then carelessly copypasting the code snippet into the question without carefully testing it as MCVE. In the future please don't do that. See also https://stackoverflow.com/tags/jsf/info.

Upvotes: 3

Mahendran Kandiar
Mahendran Kandiar

Reputation: 980

In addition to doing @BalusC 's approach

splcCreate is a String field.

el expression

 rendered="#{!(createAssociationsBean.splcCreate)}"

be better with splcCreate being a boolean expression

Upvotes: 1

Related Questions