Tabnine Logo
WebContext
Code IndexAdd Tabnine to your IDE (free)

How to use
WebContext
in
org.thymeleaf.context

Best Java code snippets using org.thymeleaf.context.WebContext (Showing top 20 results out of 315)

Refine searchRefine arrow

  • HttpServletRequest
origin: qiurunze123/miaosha

public String render(HttpServletRequest request, HttpServletResponse response, Model model, String tplName, KeyPrefix prefix, String key) {
  if(!pageCacheEnable) {
    return tplName;
  }
  //取缓存
  String html = redisService.get(prefix, key, String.class);
  if(!StringUtils.isEmpty(html)) {
    out(response, html);
    return null;
  }
  //手动渲染
  WebContext ctx = new WebContext(request,response,
      request.getServletContext(),request.getLocale(), model.asMap());
  html = thymeleafViewResolver.getTemplateEngine().process(tplName, ctx);
  if(!StringUtils.isEmpty(html)) {
    redisService.set(prefix, key, html);
  }
  out(response, html);
  return null;
}
origin: ff4j/ff4j

/** {@inheritDoc} */
public void get(HttpServletRequest req, HttpServletResponse res, WebContext ctx)
throws IOException {
  ctx.setVariable(KEY_TITLE, "Not Found ");
}
origin: ff4j/ff4j

/** {@inheritDoc} */
public void get(HttpServletRequest req, HttpServletResponse res, WebContext ctx)
throws IOException {
  ctx.setVariable(KEY_TITLE, "Settings");
  String operation = req.getParameter(WebConstants.OPERATION);
  String msgType = "success";
  String msg = null;
  if (Util.hasLength(operation) && TOGGLE_AUDIT.equalsIgnoreCase(operation)) {
    if (getFf4j().isEnableAudit()) {
      getFf4j().audit(false);
      msg = "Audit is now DISABLED";
      LOGGER.info("Audit has been disabled");
    } else {
      getFf4j().audit(true);
      msg = "Audit is now ENABLED";
      LOGGER.info("Audit has been enabled");
    }
  }
  ctx.setVariable(KEY_AUDITENABLE, getFf4j().isEnableAudit());
  ctx.setVariable("msgType", msgType);
  ctx.setVariable("msgInfo", msg);
}
origin: stackoverflow.com

String link = "";
String contextPath = "http://" + req.getServerName() + ":" + req.getServerPort();
WebContext ctx = new WebContext(req, res, req.getServletContext(),
    req.getLocale());
  link = contextPath + req.getContextPath() + "/checkToken/" + person.getToken();
  ctx.setVariable("tokenLink", link);
  String template = templateEngine.process("email/email_join", ctx);
  msg.setSubject("subject", "UTF-8");
origin: mkalus/segrada

WebContext context = new WebContext(requestInvoker.get(),
    responseInvoker.get(), servletContext, requestInvoker.get().getLocale());
if (viewable.getModel() != null) {
    context.setVariables((Map) viewable.getModel());
  else {
    context.setVariables(variables);
context.setVariable("_csrf", CSRFTokenManager.getTokenForSession(context.getSession()));
Enumeration<String> elements = context.getSession().getAttributeNames();
while (elements.hasMoreElements()) {
  String key = elements.nextElement();
  if (key.contains("org.segrada.session.Identity")) {
    context.setVariable("identity", context.getSession().getAttribute(key));
    break;
if (templateSelectors == null && "XMLHttpRequest".equals(context.getRequest().getHeader("X-Requested-With")) && !templateName.startsWith("redirect:")) {
  templateSelectors = new HashSet<>();
  templateSelectors.add(".container/div");
context.getResponse().setContentType("text/html; charset=utf-8");
origin: ff4j/ff4j

/**
 * Invoked by dispatcher.
 *
 * @param req
 *      current request
 * @param res
 *      current response
 * @throws IOException
 *      error occured.
 */
public void post(HttpServletRequest req, HttpServletResponse res)
throws IOException {
  WebContext ctx = new WebContext(req, res,  req.getSession().getServletContext(), req.getLocale());
  ctx.setVariable("uptime",  getUptime());
  ctx.setVariable("version", ff4j.getVersion());
  // Adding attribute to response
  try {
    post(req, res, ctx);
  } catch(Throwable t) {
    ctx.setVariable("msgType", "error");
    ctx.setVariable("msgInfo", t.getMessage());
  }
  // Render to view
  templateEngine.process(getSuccessView(), ctx, res.getWriter());
}
origin: ff4j/ff4j

i18n(req, res);
WebContext ctx = new WebContext(req, res,  req.getSession().getServletContext(), res.getLocale());
ctx.setVariable("uptime",  getUptime());
ctx.setVariable("version", ff4j.getVersion());
ctx.setVariable("secure", false);
if (getFf4j().getAuthorizationsManager() != null) {
  ctx.setVariable("secure", true);
  ctx.setVariable("userName", getFf4j().getAuthorizationsManager().getCurrentUserName());
  Set < String > permissions = getFf4j().getAuthorizationsManager().getCurrentUserPermissions();
  ctx.setVariable("userPermissions", permissions);
  get(req, res, ctx);
} catch(Throwable t) {
  ctx.setVariable("msgType", "error");
  ctx.setVariable("msgInfo", t.getMessage());
origin: com.github.dandelion/dandelion-thymeleaf

WebContext ctx = new WebContext(handlerContext.getRequest(), handlerContext.getResponse(), handlerContext
   .getRequest().getServletContext(), handlerContext.getRequest().getLocale());
  ctx.setVariables(requestData.getAttributes());
origin: stackoverflow.com

request.getServletContext(), request.getLocale());
ctx.setVariable("info", info);
origin: com.peterphi.std.guice/stdlib-guice-thymeleaf

  /**
   * Build a new IContext (exposing the HttpCallContext, where possible)
   *
   * @return
   */
  private IContext makeContext()
  {
    final HttpCallContext http = HttpCallContext.peek();

    if (http != null)
    {
      return new WebContext(http.getRequest(), http.getResponse(), http.getServletContext(), http.getRequest().getLocale());
    }
    else
    {
      return new Context();
    }
  }
}
origin: com.oracle.ozark.ext/ozark-thymeleaf

  @Override
  public void processView(ViewEngineContext context) throws ViewEngineException {
    try {
      HttpServletRequest request = context.getRequest();
      HttpServletResponse response = context.getResponse();
      WebContext ctx = new WebContext(request, response, servletContext, request.getLocale());
      ctx.setVariables(context.getModels());
      engine.process(resolveView(context), ctx, response.getWriter());
    } catch (IOException e) {
      throw new ViewEngineException(e);
    }
  }
}
origin: justlive1/oxygen

public void handler(String path, Map<String, Object> data, Writer writer) {
 Request request = Request.current();
 templateEngine.process(path,
   new WebContext(request.getOriginalRequest(), Response.current().getOriginalResponse(),
     request.getOriginalRequest().getServletContext(), Locale.getDefault(), data), writer);
}
origin: org.thymeleaf/thymeleaf-testing

protected IWebContext doCreateWebContextInstance(
    final ITest test,
    final HttpServletRequest request, final HttpServletResponse response, final ServletContext servletContext,
    final Locale locale, final Map<String,Object> variables) {
  return new WebContext(request, response, servletContext, locale, variables);
}
origin: com.github.dandelion/dandelion-thymeleaf

  /**
  * {@inheritDoc}
  */
  @Override
  protected ProcessorResult doProcessAttribute(Arguments arguments, Element element, String attributeName) {

   String strippedAttributeName = AttributesUtil.stripPrefix(attributeName, DandelionDialect.DIALECT_PREFIX);
   BundleAttributeNames assetsAttributeName = (BundleAttributeNames) AttributesUtil.find(strippedAttributeName,
      BundleAttributeNames.values());

   HttpServletRequest request = ArgumentsUtil.getWebContext(arguments).getHttpServletRequest();
   AssetRequestContext context = AssetRequestContext.get(request);
   switch (assetsAttributeName) {
   case INCLUDES:
     context.addBundles(element.getAttributeValue(attributeName));
     break;
   case EXCLUDES:
     context.excludeBundles(element.getAttributeValue(attributeName));
     break;
   }

   return ProcessorResult.ok();
  }
}
origin: ff4j/ff4j

String msg       = null;
String msgType   = "success";
String operation = req.getParameter(WebConstants.OPERATION);
  ctx.setVariable("msgType", msgType);
  ctx.setVariable("msgInfo", msg);
  get(req, res, ctx);
} else if (WebConstants.OP_CREATE_SCHEMA.equalsIgnoreCase(operation)) {
    getFf4j().createSchema();
    msg = "Schema has been created in DB (if required).";
    ctx.setVariable("msgType", msgType);
    ctx.setVariable("msgInfo", msg);
    get(req, res, ctx);
  } catch(RuntimeException re) {
    ctx.setVariable("msgType", ERROR);
    ctx.setVariable("msgInfo", "Cannot create Schema:" + re.getMessage());
    ctx.setVariable(KEY_TITLE, "Home");
    ctx.setVariable("today", Calendar.getInstance());
    ctx.setVariable("homebean", new HomeBean());
   msg = "Cache not present: it cannot be cleared!";
 ctx.setVariable("msgType", msgType);
 ctx.setVariable("msgInfo", msg);
 get(req, res, ctx);
origin: dandelion/dandelion

WebContext ctx = new WebContext(handlerContext.getRequest(), handlerContext.getResponse(), handlerContext
   .getRequest().getServletContext(), handlerContext.getRequest().getLocale());
  ctx.setVariables(requestData.getAttributes());
origin: com.peterphi.std.guice/stdlib-guice-webapp

  /**
   * Build a new IContext (exposing the HttpCallContext, where possible)
   *
   * @return
   */
  protected IContext makeContext()
  {
    final HttpCallContext http = HttpCallContext.peek();

    if (http != null)
    {
      return new WebContext(http.getRequest(), http.getResponse(), http.getServletContext(), http.getRequest().getLocale());
    }
    else
    {
      return new Context();
    }
  }
}
origin: thymeleaf/thymeleaf-testing

public IWebContext versionSpecificCreateContextInstance(
    final ApplicationContext applicationContext, final HttpServletRequest request,
    final HttpServletResponse response, final ServletContext servletContext,
    final Locale locale, final Map<String, Object> variables) {
  return new WebContext(request, response, servletContext, locale, variables);
}
origin: dandelion/dandelion

  /**
  * {@inheritDoc}
  */
  @Override
  protected ProcessorResult doProcessAttribute(Arguments arguments, Element element, String attributeName) {

   String strippedAttributeName = AttributesUtil.stripPrefix(attributeName, DandelionDialect.DIALECT_PREFIX);
   BundleAttributeNames assetsAttributeName = (BundleAttributeNames) AttributesUtil.find(strippedAttributeName,
      BundleAttributeNames.values());

   HttpServletRequest request = ArgumentsUtil.getWebContext(arguments).getHttpServletRequest();
   AssetRequestContext context = AssetRequestContext.get(request);
   switch (assetsAttributeName) {
   case INCLUDES:
     context.addBundles(element.getAttributeValue(attributeName));
     break;
   case EXCLUDES:
     context.excludeBundles(element.getAttributeValue(attributeName));
     break;
   }

   return ProcessorResult.ok();
  }
}
origin: ff4j/ff4j

/** {@inheritDoc} */
public void get(HttpServletRequest req, HttpServletResponse res, WebContext ctx)
throws IOException {
  String operation    = req.getParameter(WebConstants.OPERATION);
  String propertyName = req.getParameter(WebConstants.FEATID);
  String msgType = "success";
  String msg = null;
  if (Util.hasLength(operation) && Util.hasLength(propertyName) && 
      getFf4j().getPropertiesStore().existProperty(propertyName)) {
        if (OP_DELETE_FIXEDVALUE.equalsIgnoreCase(operation)) {
      String fixedValue = req.getParameter(PARAM_FIXEDVALUE);
      Property<?> ap = getFf4j().getPropertiesStore().readProperty(propertyName);
      // Need to convert back to object to use the remove()
      ap.getFixedValues().remove(ap.fromString(fixedValue));
      getFf4j().getPropertiesStore().updateProperty(ap);
      LOGGER.info("Property '" + propertyName + "' remove fixedValue '" + fixedValue + "'");
    }
    if (OP_ADD_FIXEDVALUE.equalsIgnoreCase(operation)) {
      String fixedValue = req.getParameter(PARAM_FIXEDVALUE);
      Property<?> ap = getFf4j().getPropertiesStore().readProperty(propertyName);
      ap.add2FixedValueFromString(fixedValue);
      getFf4j().getPropertiesStore().updateProperty(ap);
      LOGGER.info("Property '" + propertyName + "' add fixedValue '" + fixedValue + "'");
    }
  }
  ctx.setVariable("msgType", msgType);
  ctx.setVariable("msgInfo", msg);
  renderPage(ctx);
}
org.thymeleaf.contextWebContext

Javadoc

Basic web-oriented implementation of the IContext and IWebContext interfaces.

This context implementation contains all the required Servlet-API artifacts needed for template execution in web environments, and should be enough for most web-based scenarios of template processing.

Note a class with this name existed since 2.0.9, but it was completely reimplemented in Thymeleaf 3.0

Most used methods

  • <init>
    Create an instance specifying a locale and an initial set of context variables.
  • setVariable
  • setVariables
  • getHttpServletRequest
  • getLocale
  • getRequest
  • getResponse
  • getSession
  • getVariables
  • getWebVariablesMap
  • setLocale
  • setLocale

Popular in Java

  • Parsing JSON documents to java classes using gson
  • scheduleAtFixedRate (ScheduledExecutorService)
  • setContentView (Activity)
  • addToBackStack (FragmentTransaction)
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • JFileChooser (javax.swing)
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now