sotn
sotn

Reputation: 2101

JSF request attribute

I am using JSF 1.2. I have a page with a button. The action hooked to the button adds a request attribute to the request object and navigates to page2. On page2 I try to retrieve that attribute with #{requestScope.attr}. But this doesn't work. Any ideas why?

Thx.

Upvotes: 0

Views: 801

Answers (1)

BalusC
BalusC

Reputation: 1108632

Apparently page2 was requested by a different HTTP request. That can happen if you have sent a redirect instead of a forward when the action method is finished. For example, by calling ExternalContext#redirect() in the action method or by adding <redirect /> to the navigation case. A redirect basically instructs the browser to create a brand new HTTP request.

That said, I wonder how it's useful to explicitly set a request attribute if you're already using JSF. Just assign the desired data as a property of the current bean (which I assume to be just request scoped).

private String foo; // +getter

public String submit() {
    foo = "some value";
    return "nextpage";
}

This way it's just available by #{bean.foo} in the next page.

<h:outputText value="The value is: #{bean.foo}" />

Upvotes: 1

Related Questions