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:

  1. retrieve servletcontext object

    facescontext facescontext = facescontext.getcurrentinstance(); servletcontext servletcontext =  (servletcontext) context.getexternalcontext(); // servlet context here 
  2. from servlet context, servlet registration object servlet desire

    servletregistration reg =   servletcontext.getservletregistration("theservlet"); //servletregistration contains info you'll need populate custom servletconfig object 
  3. use information you've derived (2) populate custom impl of servletconfig

    servletconfig 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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -