1

Sorry for bad title, feel free to edit please.

So I have this piece of code:

<h:outputLink value="goodbye.xhtml">
    Go to goodbye!
    <f:param name="msg" value="test_one" />
</h:outputLink>

so when clicked, I will end up in goodbye.xhtml and the code for it is as follows:

<f:view>
    <f:metadata>
        <f:viewParam name="msg" value="#{blahBlah.parameter}"/>
    </f:metadata>
    <h:body>
        #{blahBlah.parameter}
    </h:body>
</f:view>

So when I have BlahBlah.java as follows:

@ManagedBean
@SessionScoped
public class BlahBlah {
    private String parameter;
    public String getParameter() {
        return parameter;
    }
    public void setParameter(String parameter) {
        if (parameter.equals("test_one")) {
            this.parameter = "test_one_modified";
            return;
        }
        this.parameter = parameter;
    }
}

I will see test_one_modified on goodbye.xhtml which is fine.

But when I modify BlahBlah.java as follows:

@ManagedBean
@SessionScoped
public class BlahBlah {
    private String parameter;
    public String getParameter() {
        if (parameter.equals("test_one")) {
            this.parameter = "test_one_modified";
        }
        return parameter;
    }
    public void setParameter(String parameter) {
        this.parameter = parameter;
    }
}

what I expect is to again see test_one_modified but instead I will get a nice Null Pointer Exception.

Isn 't

<f:viewParam name="msg" value="#{blahBlah.parameter}"/>

supposed to set BlahBlah.parameter?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319

0 Answers0