jsf - Redirect in @PostConstruct causes IllegalStateException -
i want make redirect in @postconstruct in 4 of backing beans. i've learned follwoing question: jsf postconstruct exception handling - redirect know i'm supposed use:
@postconstruct public void init() { if (shouldredirect) { try { facescontext.getcurrentinstance().getexternalcontext().redirect("bolagssok_company.xhtml"); return; } catch (ioexception e) { //do nothing } } .... }
this works great 2 of backing beans... other two, non-redirected-xhtml file still making calls backing bean , doesn't redirect. i've confirmed (with debug) backing beans indeed calls both facescontext.getcurrentinstance().getexternalcontext().redirect("bolagssok_company.xhtml");
, return; statements.
any clues wrong?
redirecting in @postconstruct
might late if response committed. i.e. when first few bytes of response been sent client. point of no return. can in case happen when backing bean referenced (and constructed) first time relatively late in view, maybe halfway or in end.
you solve in 1 of following ways:
reference bean first time possible in view.
use
<f:event type="prerenderview">
instead of@postconstruct
. invoke method right before render response starts (thus, before bit been sent response). or, when you're on jsf 2.2 already, use<f:viewaction>
. additional advantage<f:viewaction>
can return navigation case outcomereturn bolagssok_company?faces-redirect=true"
without need fiddleexternalcontext#redirect()
.increase default facelets buffer size
javax.faces.facelets_buffer_size
context param inweb.xml
size of largest html response.
Comments
Post a Comment