Just don't use view/session scoped beans (so use only request or application scoped beans) and set state saving to client
instead of (default) server
by setting the following context parameter in web.xml
.
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
Then JSF won't create the session and will store the view state in a hidden input field with the name javax.faces.ViewState
in the form whenever necessary.
The cost of creating and managing the sessions is however pretty negligible. Also, you still have to tradeoff the cost of (de)serializing the view state and the network bandwidth when using client side view state saving.
Update as per your comment:
@BalusC Yes, this could be a global solution. But i need this method only in this public page. In other pages i want server side state saving method.
Ah right. Sorry, I don't see any nice ways in JSF/Facelets to disable the session or change the view state saving on a per-request basis. I'd consider to use a plain HTML <form>
instead of a JSF <h:form>
, let it submit to another JSF page and make use of @ManagedProperty
in the bean associated with the JSF page. E.g.
<form action="register.jsf" method="post">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" />
</form>
with
@ManagedBean
@RequestScoped
public class Register {
@ManagedProperty(value="#{param.username}")
private String username;
@ManagedProperty(value="#{param.password}")
private String password;
@PostConstruct
public void init() {
// Do your thing here.
System.out.println("Submitted username/password: " + username + "/" + password);
}
// ...
}