List of usage examples for javax.servlet.jsp PageContext getRequest
abstract public ServletRequest getRequest();
From source file:org.apache.struts.taglib.tiles.util.TagUtils.java
/** * Search attribute in different contexts. * First, check in component context, then use pageContext.findAttribute(). * @param beanName Name of bean to retrieve. * @param pageContext Current pageContext. * @return Requested bean or <code>null</code> if not found. *//*ww w. jav a 2 s.c om*/ public static Object findAttribute(String beanName, PageContext pageContext) { ComponentContext compContext = ComponentContext.getContext(pageContext.getRequest()); if (compContext != null) { Object attribute = compContext.findAttribute(beanName, pageContext); if (attribute != null) { return attribute; } } // Search in pageContext scopes return pageContext.findAttribute(beanName); }
From source file:org.apache.struts.taglib.tiles.util.TagUtils.java
/** * Get object from requested context. Return <code>null</code> if not found. * Context can be "component" or normal JSP contexts. * @param beanName Name of bean to retrieve. * @param scope Scope from which bean must be retrieved. * @param pageContext Current pageContext. * @return Requested bean or <code>null</code> if not found. *//*from w ww . j a v a 2s. c om*/ public static Object getAttribute(String beanName, int scope, PageContext pageContext) { if (scope == ComponentConstants.COMPONENT_SCOPE) { ComponentContext compContext = ComponentContext.getContext(pageContext.getRequest()); return compContext.getAttribute(beanName); } return pageContext.getAttribute(beanName, scope); }
From source file:org.apache.struts.taglib.tiles.util.TagUtils.java
/** * Get component definition by its name. * @param name Definition name.//from w ww . j av a2 s . c o m * @param pageContext The PageContext for the current page. * @throws JspException - */ public static ComponentDefinition getComponentDefinition(String name, PageContext pageContext) throws JspException { try { return TilesUtil.getDefinition(name, pageContext.getRequest(), pageContext.getServletContext()); } catch (NoSuchDefinitionException ex) { throw new JspException("Error : Can't get component definition for '" + name + "'. Check if this name exist in component definitions."); } catch (FactoryNotFoundException ex) { // factory not found. throw new JspException(ex.getMessage()); } catch (DefinitionsFactoryException ex) { if (debug) ex.printStackTrace(); // Save exception to be able to show it later saveException(pageContext, ex); throw new JspException(ex.getMessage()); } }
From source file:org.apache.struts.tiles.taglib.util.TagUtils.java
/** * Get component definition by its name. * @param name Definition name.//from ww w . j a v a 2s . co m * @param pageContext The PageContext for the current page. * @throws JspException - */ public static ComponentDefinition getComponentDefinition(String name, PageContext pageContext) throws JspException { try { return TilesUtil.getDefinition(name, pageContext.getRequest(), pageContext.getServletContext()); } catch (NoSuchDefinitionException ex) { throw new JspException("Error : Can't get component definition for '" + name + "'. Check if this name exist in component definitions.", ex); } catch (FactoryNotFoundException ex) { // factory not found. throw new JspException(ex); } catch (DefinitionsFactoryException ex) { if (debug) ex.printStackTrace(); // Save exception to be able to show it later saveException(pageContext, ex); throw new JspException(ex); } }
From source file:org.apache.struts2.components.template.JspTemplateEngine.java
public void renderTemplate(TemplateRenderingContext templateContext) throws Exception { Template template = templateContext.getTemplate(); if (LOG.isDebugEnabled()) { LOG.debug("Trying to render template " + template + ", repeating through parents until we succeed"); }//from w ww . ja va2s. c o m UIBean tag = templateContext.getTag(); ValueStack stack = templateContext.getStack(); stack.push(tag); PageContext pageContext = (PageContext) stack.getContext().get(ServletActionContext.PAGE_CONTEXT); List templates = template.getPossibleTemplates(this); Exception exception = null; boolean success = false; for (Iterator iterator = templates.iterator(); iterator.hasNext();) { Template t = (Template) iterator.next(); try { Include.include(getFinalTemplateName(t), pageContext.getOut(), pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse()); success = true; break; } catch (Exception e) { if (exception == null) { exception = e; } } } if (!success) { LOG.error("Could not render JSP template " + templateContext.getTemplate()); if (exception != null) { throw exception; } else { return; } } stack.pop(); }
From source file:org.apache.tiles.jsp.context.JspTilesRequestContext.java
/** * Constructor./* w w w. ja v a2 s .c o m*/ * * @param context The servlet context to use. * @param pageContext The page context to use. */ public JspTilesRequestContext(ServletContext context, PageContext pageContext) { super(context, (HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse()); this.pageContext = pageContext; }
From source file:org.broadleafcommerce.core.web.catalog.taglib.SearchFilterItemTag.java
protected String getUrl(Category category) { PageContext pageContext = (PageContext) getJspContext(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); StringBuffer sb = new StringBuffer(); sb.append("<a href=\""); sb.append(request.getContextPath()); sb.append("/"); sb.append(category.getGeneratedUrl()); sb.append("\">"); sb.append(category.getName());/*from w w w . j a va 2 s . c om*/ sb.append("</a>"); return sb.toString(); }
From source file:org.codelabor.system.web.taglib.PaginationTag.java
@Override public void doTag() throws JspException, IOException { logger.debug("doTag"); // if numberOfRow is 0, do nothing if (numberOfRow == 0) { return;/*from ww w . ja v a2 s. co m*/ } PageContext context = (PageContext) this.getJspContext(); HttpServletRequest request = (HttpServletRequest) context.getRequest(); JspWriter out = context.getOut(); // queryString queryString = request.getQueryString(); // max row per page String maxRowPerPageString = request.getParameter(maxRowPerPageParamName); if (!StringUtils.isBlank(maxRowPerPageString)) { maxRowPerPage = Integer.parseInt(maxRowPerPageString); } // total count int totalPageCount = (int) Math.ceil((double) numberOfRow / (double) maxRowPerPage); // page number int firstPageNo = 1; lastPageNo = totalPageCount; currentPageNo = 1; String pageNoString = request.getParameter(pageNoParamName); if (!StringUtils.isBlank(pageNoString)) { currentPageNo = Integer.parseInt(pageNoString); } // validation if (currentPageNo > lastPageNo) { StringBuilder sb = new StringBuilder(); sb.append(pageNoParamName).append(" is exeeded."); sb.append(" ("); sb.append("requested page number: ").append(currentPageNo).append(", "); sb.append("last page number: ").append(lastPageNo).append(")"); throw new JspException(sb.toString()); } // current index lastPageNoOnCurrentIndex = ((int) Math.ceil((double) currentPageNo / (double) maxIndexPerPage)) * maxIndexPerPage; firstPageNoOnCurrentIndex = (lastPageNoOnCurrentIndex - maxIndexPerPage) + 1; // compensate page number if (lastPageNoOnCurrentIndex > lastPageNo) { lastPageNoOnCurrentIndex = lastPageNo; } // first page number on previous, next index firstPageNoOnPreviousIndex = firstPageNoOnCurrentIndex - maxIndexPerPage; firstPageNoOnNextIndex = lastPageNoOnCurrentIndex + 1; // compensate page number if (firstPageNoOnPreviousIndex < firstPageNo) { firstPageNoOnPreviousIndex = firstPageNo; } if (firstPageNoOnNextIndex > lastPageNo) { firstPageNoOnNextIndex = lastPageNo; } // first page number of first index firstPageNoOnFirstIndex = firstPageNo; // last page number of last index lastPageNoOnLastIndex = ((int) Math.ceil((double) numberOfRow / (double) maxRowPerPage)); // debug logger.debug("queryString: {}", queryString); logger.debug("numberOfRow: {}", numberOfRow); logger.debug("totalPageCount: {}", totalPageCount); logger.debug("firstPageNo: {}", firstPageNo); logger.debug("lastPageNo: {}", lastPageNo); // write html tag StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(); sb.append("<div"); if (!StringUtils.isBlank(cssClass)) { sb.append(" class=\"").append(cssClass).append("\""); } sb.append(" />"); getJspBody().invoke(sw); sb.append(sw.getBuffer()); sb.append("</ div>"); out.print(sb.toString()); }
From source file:org.displaytag.decorator.CheckboxTableDecorator.java
/** * @see org.displaytag.decorator.Decorator#init(javax.servlet.jsp.PageContext, java.lang.Object, * org.displaytag.model.TableModel)/* ww w . j av a 2s.c o m*/ */ public void init(PageContext pageContext, Object decorated, TableModel tableModel) { super.init(pageContext, decorated, tableModel); String[] params = pageContext.getRequest().getParameterValues(fieldName); checkedIds = params != null ? new ArrayList(Arrays.asList(params)) : new ArrayList(0); }
From source file:org.displaytag.localization.I18nSpringAdapter.java
/** * @see I18nResourceProvider#getResource(String, String, Tag, PageContext) *///w w w.j a v a 2 s. c o m public String getResource(String resourceKey, String defaultValue, Tag tag, PageContext pageContext) { MessageSource messageSource = RequestContextUtils.getWebApplicationContext(pageContext.getRequest()); if (messageSource == null) { log.warn("messageSource not found"); return null; } // if resourceKey isn't defined either, use defaultValue String key = (resourceKey != null) ? resourceKey : defaultValue; String message = null; message = messageSource.getMessage(key, null, null, RequestContextUtils.getLocale((HttpServletRequest) pageContext.getRequest())); // if user explicitely added a titleKey we guess this is an error if (message == null && resourceKey != null) { log.debug(Messages.getString("Localization.missingkey", resourceKey)); //$NON-NLS-1$ message = UNDEFINED_KEY + resourceKey + UNDEFINED_KEY; } return message; }