1

I'm using Mojarra 2.2.12. I have a case where a @ViewScoped @ManagedBean is immediately destroyed on page load, although the view is not ended. The problem is reproducible with solely the below in <h:body>:

<h:outputText value="#{testBean.value}" />
<h:link outcome="other" includeViewParams="true">link</h:link>

The other must refer to a different view and not the same view. There's no <f:viewParam> necessary to reproduce the problem.

And the below bean:

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class TestBean implements Serializable {

    @PostConstruct
    public void init() {
        System.out.println("@PostConstruct on " + this);
    }

    @PreDestroy
    public void clear() {
        System.out.println("@PreDestroy on " + this);
    }

    public String getValue() {
        return "test";
    }

}

If we remove includeViewParams="true" attribute, then the bean is not immediately destroyed.Why does includeViewParams="true" cause this behavior?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
jpl
  • 347
  • 3
  • 11
  • Do you mean to say that it's destroyed on page load or only when the link is clicked? – BalusC Sep 22 '15 at 17:12
  • The bean is destroyed on page load. – jpl Sep 24 '15 at 14:27
  • Can't reproduce it based on information provided so far. – BalusC Sep 24 '15 at 14:38
  • Then information in the question is lacking. Imagine us having a completely blank project with everything set to bare minimum and defaults, how could we reproduce your problem? The question has to cover all of that. – BalusC Sep 25 '15 at 06:56
  • Thank you for taking time to help me, I reproduced it systematically. I work with a showcase project very simple. The project logs PostConstruct on org.exemple.PF.showcase.TestBean sept. 25, 2015 9:11:13 AM com.sun.faces.application.view.ViewScopeManager INFO: CDI @ViewScoped bean functionality unavailable PreDestroy on org.exemple.PF.showcase.TestBean – jpl Sep 25 '15 at 07:16
  • The question, not the comments. Comments are volatile. There's an "edit" link below the question. – BalusC Sep 25 '15 at 07:20
  • Reproduced. Happens only when the link outcome points to different view and you manage bean by legacy JSF `@ManagedBean` instead of CDI `@Named`. And, it's not specific to PrimeFaces. Happens already on ``. – BalusC Sep 25 '15 at 09:37
  • @Balusc, i cannot use CDI because the project is based on Spring and CDI/spring integration is not trivial. Is it a bug or a normal functionnality? – jpl Sep 25 '15 at 09:50
  • Spring and Java EE are indeed competitors. As to the problem, this is definitely a bug. – BalusC Sep 25 '15 at 09:57
  • Thanks for your support, you have definitively a very good understand of jsf technologie. How can i report this bug? – jpl Sep 25 '15 at 10:12
  • You can create it here https://java.net/jira/browse/JAVASERVERFACES If time allows me I can also take a closer look at it. – BalusC Sep 25 '15 at 10:14
  • Issue created with id JAVASERVERFACES-4069 – jpl Sep 25 '15 at 12:28

1 Answers1

0

Add this dependency to pom.xml, I was passed it.

<dependency>
    <groupId>javax.enterprise</groupId>
    <artifactId>cdi-api</artifactId>
    <version>1.2</version>
</dependency>
  • Please read the comments: _"@B...c, i cannot use CDI because the project is based on Spring and CDI/spring integration is not trivial. Is it a bug or a normal functionnality?"_ – Kukeltje May 23 '17 at 08:15