Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2 Sprint 8
    • Fix Version/s: 2.2
    • Component/s: Facelets/VDL
    • Labels:
      None
    • Status Whiteboard:
      Hide

      size_medium importance_medium

      Show
      size_medium importance_medium

      Description

      A @ViewScoped bean will behave like a @RequestScoped bean when at least an
      UIComponent is bound to the bean using binding attribute in the view. I.e. it
      will be recreated on every request.

      I can't find any line in the JSF specification if this is intentional or not.

      A side effect is that UIData#getRowData() of the bound h:dataTable returns only
      the 1st item everytime. When the bean is @RequestScoped, the UIData#getRowData()
      returns the expected item.

        Activity

        Hide
        arjan tijms added a comment -
        Show
        arjan tijms added a comment - See http://java.net/jira/browse/JAVASERVERFACES-1658 for additional details.
        Hide
        Darious3 added a comment -

        Wasn't this fixed already by the way the view scope is handled now in JSF 2.2? (restoring the view scope first)

        Show
        Darious3 added a comment - Wasn't this fixed already by the way the view scope is handled now in JSF 2.2? (restoring the view scope first)
        Hide
        arjan tijms added a comment -

        It looks like this has been fixed indeed.

        I tested on GlassFish 4.0 b88 with the following Facelet:

        <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
        >
            <h:body>
                <h:form id="form">
                    <p>
                        <h:outputText id="test" value="test component" binding="#{viewScopedBean.component}" />
                    </p>
                    
                    <p>
                        Output from bean:
                        <h:outputText value="#{viewScopedBean.value}" />
                    </p>
                
                    <h:commandButton value="Submit form" action="#{viewScopedBean.doAction}" />
                </h:form>
            </h:body>
        </html>
        

        and the following bean:

        @ViewScoped
        @ManagedBean
        public class ViewScopedBean {
        
            private Date date = new Date();
            private UIComponent component;
            private int postbackCount;
            
            private String value;
        
            public String doAction() {
                value = String.format("Postback: '%d' -- Bean created at: '%s' -- Component id: '%s'  -- Bean class id: '%s'",
                    ++postbackCount,
                    date,
                    component.getClientId(),
                    this
                );
                        
                return null;
            }
        
            public UIComponent getComponent() {
                return component;
            }
        
            public void setComponent(UIComponent component) {
                this.component = component;
            }
            
            public String getValue() {
                return value;
            }
            
        }
        

        After the first postback I got:

        test component
        
        Output from bean: Postback: '1' -- Bean created at: 'Sun May 19 14:32:55 CEST 2013' -- Component id: 'form:test' -- Bean class id: 'beans.ViewScopedBean@552f82fe'
        

        After the second:

        test component
        
        Output from bean: Postback: '2' -- Bean created at: 'Sun May 19 14:32:55 CEST 2013' -- Component id: 'form:test' -- Bean class id: 'beans.ViewScopedBean@552f82fe'
        

        etc.

        I also tried with the new JSF 2.2 CDI view scope and an @Named bean and there it also worked; after every postback the bean instance remains the same one and the counter correctly increases.

        Show
        arjan tijms added a comment - It looks like this has been fixed indeed. I tested on GlassFish 4.0 b88 with the following Facelet: <html xmlns= "http://www.w3.org/1999/xhtml" xmlns:h = "http://java.sun.com/jsf/html" > <h:body> <h:form id= "form" > <p> <h:outputText id= "test" value= "test component" binding= "#{viewScopedBean.component}" /> </p> <p> Output from bean: <h:outputText value= "#{viewScopedBean.value}" /> </p> <h:commandButton value= "Submit form" action= "#{viewScopedBean.doAction}" /> </h:form> </h:body> </html> and the following bean: @ViewScoped @ManagedBean public class ViewScopedBean { private Date date = new Date(); private UIComponent component; private int postbackCount; private String value; public String doAction() { value = String .format( "Postback: '%d' -- Bean created at: '%s' -- Component id: '%s' -- Bean class id: '%s'" , ++postbackCount, date, component.getClientId(), this ); return null ; } public UIComponent getComponent() { return component; } public void setComponent(UIComponent component) { this .component = component; } public String getValue() { return value; } } After the first postback I got: test component Output from bean: Postback: '1' -- Bean created at: 'Sun May 19 14:32:55 CEST 2013' -- Component id: 'form:test' -- Bean class id: 'beans.ViewScopedBean@552f82fe' After the second: test component Output from bean: Postback: '2' -- Bean created at: 'Sun May 19 14:32:55 CEST 2013' -- Component id: 'form:test' -- Bean class id: 'beans.ViewScopedBean@552f82fe' etc. I also tried with the new JSF 2.2 CDI view scope and an @Named bean and there it also worked; after every postback the bean instance remains the same one and the counter correctly increases.

          People

          • Assignee:
            Ed Burns
            Reporter:
            rogerk
          • Votes:
            9 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: