java - How to output an error message in my JSF page, related to my httpresponse error -
i have logic code (putting error response):
public modelandview resolveexception(httpservletrequest request, httpservletresponse response, object handler, exception ex) { boolean maxsizeex = true; if (ex instanceof maxuploadsizeexceededexception) { logger.debug("tried upload file exceeded capacity", ex); } else { logger.warn("caught unexpected exception", ex); maxsizeex = false; } final boolean fmaxsizeex = maxsizeex; view view = new view() { public void render(map model, httpservletrequest request, httpservletresponse response) throws exception { map<string, string> data = new hashmap<string, string>(); if (fmaxsizeex) { data.put("error", "limit size exceeded"); } else { data.put("error", "internal error"); } jsonapicontroller.maptojsonandoutput(response.getoutputstream(), data); } public string getcontenttype() { return "application/json"; } }; return new modelandview(view); }
and want after that, output error message in view (my jsf page).
how can in jsf page ?
here code of maptojsonandoutput method :
protected static void maptojsonandoutput(outputstream out, map<string, string> data) throws ioexception { if (data == null || data.isempty()) { logger.warn("you should not call maptojsonandoutput if there no data"); return; } jsonfactory f = new jsonfactory(); jsongenerator g = f.createjsongenerator(out, jsonencoding.utf8); g.writestartobject(); (entry<string, string> e : data.entryset()) { g.writestringfield(e.getkey(), e.getvalue()); } g.writeendobject(); g.flush(); devispdfresourcecontroller.close(out); }
thanks help.
edit :
if (fmaxsizeex) { data.put("error", "limit size exceeded"); } else { data.put("error", "internal error"); } jsonapicontroller.maptojsonandoutput(response.getoutputstream(), data)
the code data.put("error", "limit size exceeded") seems not working, want add error message response.
any suggestions ?
i don't know if simplest method in case, there's jsf tag called <h:messages>
can display facescontext message 4 levels of severity.
see documentation : http://www.jsftoolbox.com/documentation/help/12-tagreference/html/h_messages.html
here's how works in simple case :
view (.jsf) :
<h:messages />
controller (.java) :
facesmessage message = new facesmessage(facesmessage.your_severity, "your description", "your message"); facescontext.getcurrentinstance().addmessage(null, message);
Comments
Post a Comment