开发者

View scoped bean is instantiated twice on one page, if there is no redirect when going to page

开发者 https://www.devze.com 2023-03-17 05:25 出处:网络
I have a page where I use @ViewScoped bean. On page I get data from the bean, and call action on it. Something 开发者_开发技巧like this:

I have a page where I use @ViewScoped bean. On page I get data from the bean, and call action on it. Something 开发者_开发技巧like this:

<h:form>
  <h:dataTable value="#{partyBean.foundOrganisations}" var="party">
    <h:column headerClass="header">
      <f:facet name="header">
        #{msgs['company.registration.number']}
      </f:facet>
      <h:commandLink value="#{party.registrationNumber}" action="#{partyBean.select}">
        <f:setPropertyActionListener value="#{party}" target="#{partyBean.selectedParty}" />
      </h:commandLink>
    </h:column>
  </h:dataTable>
</h:form>

partyBean is @ViewScoped. When I get to this page by navigation rule with <redirect />, everything works fine, but when there is no <redirect />, foundOrganisations are taken from one instance of the bean, but setSelectedParty is called on another instance of the bean when link is clicked. Checked by debug.

Why is that? Can I do something to make it work without <redirect />?


I think its perfectly normal. partyBean is renew with new view. For a submit to same page you can change your commandLink with command button and return null in action method. In this way JSF acts like same view.

Or you can try keep selectedparty value in a hiddenField (not tested in JSF 2.0)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号