exception handling - Navigation from managed bean constructor in ADF Faces JSF 1.2 -
is possible navigate page/view constructor of managed bean? want redirection if exception occurred. have tried many ways:
try-1:
getfacescontext().responsecomplete(); getfacescontext().getapplication().getnavigationhandler().handlenavigation(getfacescontext(), null, "gotoparterror"); getfacescontext().renderresponse();
try-2:
getservletresponse().sendredirect("parterror.jspx")
try-3:
getfacescontext().responsecomplete(); getfacescontext().getexternalcontext().redirect(getservletrequest().getcontextpath() + "/pages/parterror.jspx");
try-4:
requestdispatcher dispatcher = getservletrequest().getrequestdispatcher("parterror.jspx"); dispatcher.forward(getservletrequest(), getservletresponse());
try-5:
facescontext context = getfacescontext(); uiviewroot newpage = context.getapplication().getviewhandler().createview(context, "/parterror.jspx"); context.setviewroot(newpage); context.renderresponse();
try-6:
controllercontext.getinstance().getcurrentviewport().setviewid("parterror");
try-7:
exception handler in adfc-config.xml
try-8:
custom service handler defined in /.adf/meta-inf/services/oracle.adf.view.rich.context.exceptionhandler extends oracle.adf.view.rich.context.exceptionhandler
try-9:
by extending jsf life cycle
none of them worked. cases received
java.lang.illegalstateexception: cannot forward after response has been committed
is not possible in jsf 1.2? using adf 11.1.1.6.0, uses jsf 1.2, of above "try" contains adf faces ways.
i need anyway, can jsf 1.2 or adf faces, navigate error page. way got success use of javascript, executed backend, open error page in _self
window in case of error, don't it.
any pointer in matter helpful.
it's easier solve problem if cause of problem understood. exception tells cause of problem.
look closer:
java.lang.illegalstateexception: cannot forward after response has been committed
the response has been committed. point of no return. perhaps failed understand means response has been committed (which has consequence failed understand exception itself).
by default, http response written buffer flushed every ~2kb, depending on server configuration. flush of response buffer causes written bytes being sent server client. once happens first time, response considered committed. point of no return. server cannot take written bytes client in case server needs change response afterwards.
if have code potentially needs change response, should invoking before response committed.
in particular case, managed bean apparently constructed in midst of jsf render response phase during generating html output. part of generated html output has been sent client (so, response committed). you're apparently referencing request scoped bean relatively late in jsf page, or response buffer relatively small, or html <head>
relatively large causes flush before <body>
starts, etcetera.
you need invoke code before render response phase. in jsf 1.2, can use <f:view beforephase>
this.
e.g.
<f:view beforephase="#{bean.navigate}">
with
public void navigate(phaseevent event) { if (event.getphaseid() == phaseid.render_response) { // here job should run right before render_response. } }
then try-1 , try-3 work (you can leave responsecomplete()
, renderresponse()
lines away, implicitly taken care of).
try-2 , try-4 poor. should avoid having javax.servlet.*
imports in backing bean. try-5 clumsy. try-6, try-7 , try-8 beyond scope. try-9 doable, extremely clumsy.
Comments
Post a Comment