1

I have a problem that i don't understand: I request a new site. A site has a link that opens a dialog. The link is inside a form. The dialog is not inside the form.

A reduced code example:

    <p:outputPanel id="layout-center" >
      <h:form>
        <p:commandLink id="option_field_user_profile" actionListener="#{controllerBean.getBean('userProfileBean', component).init}" oncomplete="#{controllerBean.getBean('userProfileBean', component).show}" >
        <h:outputText value="#{msg.mProfile}"/>
        </p:commandLink>
      </h:form>
    </p:outputPanel>

    <p:dialog header="#{userPreferencesBean.header}" widgetVar="#{userPreferencesBean.widgetVar}" appendToBody="#{userPreferencesBean.appendToBody}" resizable="#{userPreferencesBean.resizable}" id="#{userPreferencesBean.xhtmlId}" dynamic="#{userPreferencesBean.dynamic}" modal="#{userPreferencesBean.modal}" closable="#{userPreferenceBean.closable}">
      <ui:include src="/WEB-INF/templates/modification/userPreferences.xhtml" />
    </p:dialog>

UserPreferencesBean is in ViewScope. My problem is now that the @PostConstruct method from the UserPreferencesBean is called twice with the non-postback request i.e. the Bean is constructed twice although it should be the same view. If i move the dialog inside the form for testing purposes it is called once, like expected. But since the dialog has its own form this is not a solution, for sure. When the site is loaded and I hit F5, the PostConstruct method is executed once.

Has somebody an idea?

smotron
  • 107
  • 1
  • 10

1 Answers1

1

This is caused because you referenced a view scoped bean property in the view build time attribute id of the <p:dialog>. If you fix the id to be static, or to reference a request or application scoped bean property instead, then your view scoped bean will behave as expected.

See also:

  • JSTL in JSF2 Facelets... makes sense? - for some background explanation on view build time and view render time; the id and binding attributes of UI components are evaluated during view build time.
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555