jsf 2 - How to access ServletConfig in JSF Managed bean -
at moment, try integrate confident captcha jsf project. constructor of class confidentcaptchaclient following:
public confidentcaptchaclient(string settingsxmlfilepath, httpservletrequest request, javax.servlet.servletconfig servletconfig) this requires servletconfig argument. how inside managed bean?
this hack. servletconfig is, object containing parameters of servlet. you'll find practically same methods , info in servletregistration interface. it's same if pull config params off servletcontext , populate in custom implementation of servletconfig. try this:
retrieve
servletcontextobjectfacescontext facescontext = facescontext.getcurrentinstance(); servletcontext servletcontext = (servletcontext) context.getexternalcontext(); // servlet context herefrom servlet context, servlet registration object servlet desire
servletregistration reg = servletcontext.getservletregistration("theservlet"); //servletregistration contains info you'll need populate custom servletconfig objectuse information you've derived (2) populate custom impl of
servletconfigservletconfig myservletconfig = new mycustomservletconfig(); myservletconfig.setinitparams(reg.getinitparameters()); //do simple transfer of content
the last step oversimplification, you'll idea.
if running previous version of java ee (pre 3.0), you'll have had access servletcontext#getservlet() deprecated.
Comments
Post a Comment