Why is separate RequestScoped bean not injected into the bean called by JSF commandButton action?

66 Views Asked by At

For what reason won't an injected secondary bean using the same scope contain the form data from the submit? Using an explicit method call with parameter from a (JSF) commandButton action..

I've resorted to including the same parameter in the calling bean, and then it works fine. But this is annoying as I'd prefer to A. not pass things around like crazy and B. reuse a particular set of settings in several places.

The environment running my application is a Wildfly 11, problem below occured on a Windows box but will run in production on Linux.

My webpage and relevant code from the beans in question:

<ui:composition template="/WEB-INF/template.xhtml" ...
                xmlns:h="http://xmlns.jcp.org/jsf/html">
...
<h:form>
<h:selectBooleanCheckbox id="box1" value="#{mainBean.someBoolean}"/>
<h:selectBooleanCheckbox id="box2" value="#{secondBean.someBoolean}"/>
<h:commandButton id="cmdButton" value="Btn Text" action="#{mainBean.actionMethod(sessionBean.value)}"/>
</h:form>
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
...
@Named
@RequestScoped
public class MainBean implements Serializable {
    @Inject
    private SecondBean secondBean;

    private boolean someBoolean;
    // with getter and setter

    public void actionMethod(Object value) {
        // In here, someBoolean and value are properly set, while secondBean.isSomeBoolean() always returns default/false regardless of the checkbox on the page.
    }
...
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import java.io.Serializable;
...
@Named
@RequestScoped
public class SecondBean implements Serializable {
    private boolean someBoolean;
    // with getter and setter
...

Why is one bean properly populated with form data and not the other?

0

There are 0 best solutions below