0
votes

I've a @ViewScoped bean

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class MyBean implements Serializable

It is reconstructed on every postback (with all obvious consequences such as losing initial properties). How is this caused and how can I solve it? If it is not solveable are there any workarounds?

I cannot change the scope of the bean to for example @SessionScoped due to non technical reasons.

Following State Saving Method is configured:

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>

All JSF Related files out of my pom.xml

        <!-- JSF Files -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>mojarra-jsf-impl</artifactId>
        <version>2.0.0-b04</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.12</version>
    </dependency>

    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.0.2-FCS</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>javax.faces-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
1
What does the postback-method you're calling look like? - Dawn
Danny, nope, you have never shown it. @Dawn: OP's problem already occurs before the method is hit, otherwise the problem would only occur "every second click" only. So that part is already irrelevant and would only add distracting noise to the question. - BalusC
have you tried posting the title of this question in Google and tried finding a cause of your problem by reading the results? Or even reading the 'related' questions on the right in Stackoverflow - Kukeltje
Well, the How to Ask page (and also any how-to-ask-smart-questions) state to describe what you did/tried and why it was no solution. So instead of asking me what I found (several possible causes), please improve your question from your side. - Kukeltje
Your browser cookie store is messed up too due all those old and mixed dependencies which had previously flash scope bugs. Just clear all cookies or spawn an incognito window. - BalusC

1 Answers

2
votes

This doesn't make sense.

<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>mojarra-jsf-impl</artifactId>
    <version>2.0.0-b04</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.2.12</version>
</dependency>
<dependency>
    <groupId>javax.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.0.2-FCS</version>
</dependency>
<dependency>
    <groupId>javax.faces</groupId>
    <artifactId>javax.faces-api</artifactId>
    <version>2.0</version>
    <scope>provided</scope>
</dependency>

Get rid of them all. They're incompatible with each other. This can have many consequences, of which a broken view scope is indeed one.

To use Mojarra on Tomcat, just grab the single org.glassfish:javax.faces dependency.

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.faces</artifactId>
    <version><!-- Check javaserverfaces.java.net for latest version --></version>
</dependency>

Latest stable 2.2.x version is currently 2.2.12.

Related potential causes: