eclipse-ee4j / mojarra

Mojarra, a Jakarta Faces implementation
Other
160 stars 109 forks source link

ViewScoped bean being initialized multiple times with includeViewParams="true" #5290

Closed DanielNovo closed 1 year ago

DanielNovo commented 1 year ago

I'm currently migrating an web application developed in JSF from Wildfly 26 to Wildfly29. All the code was refactored to jakarta.* and I'm experiencing some strange behaviour with ViewScoped beans.

A clear and concise description of what the bug is.

On pages containing <h:link ... includeViewParams="true"/> the corresponding backing bean is being initialized multiple times.

Page Bean

package mypackage;

import java.io.Serializable;

import jakarta.annotation.PostConstruct;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;

@Named
@ViewScoped
public class PageOne implements Serializable {

    private static final long serialVersionUID = 1L;

    private String page = null;

    private String search = null;

    @PostConstruct
    private void init() {
        System.out.println("Page One PostConstruct");
    }

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

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public String getSearch() {
        return search;
    }

    public void setSearch(String search) {
        this.search = search;
    }

}

Page One XHTML

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="jakarta.faces.core" xmlns:ui="jakarta.faces.facelets" xmlns:h="jakarta.faces.html" xmlns:a="jakarta.faces.passthrough">

<f:metadata>
    <f:viewParam name="page" value="#{pageOne.page}" />
    <f:viewParam name="search" value="#{pageOne.search}" />
</f:metadata>

<body>
    <main>
        <div>
            <h:link value="#{pageOne.value}" outcome="pageTwo?faces-redirect=true" includeViewParams="true" />
        </div>
    </main>
</body>

Page Two XHTML

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="jakarta.faces.core" xmlns:ui="jakarta.faces.facelets" xmlns:h="jakarta.faces.html" xmlns:a="jakarta.faces.passthrough">

<f:metadata>
    <f:viewParam name="page" value="#{pageOne.page}" />
    <f:viewParam name="search" value="#{pageOne.search}" />
</f:metadata>

<body>
    <main>
        <div>Page Two</div>
    </main>
</body>

When accessing page one, the page bean is instanciated multiple times.

The same code works as expected on Wildfly 26 (only one instance is created).

BalusC commented 1 year ago

Norepro in Mojarra 4.0.3.

DanielNovo commented 1 year ago

Norepro in Mojarra 4.0.3.

Hi @BalusC

I replaced mojarra 4.0.3 on wildfly and its fixed.

Thanks.

BalusC commented 1 year ago

ok! tyvm for feedback