List of usage examples for javax.servlet.jsp PageContext REQUEST_SCOPE
int REQUEST_SCOPE
To view the source code for javax.servlet.jsp PageContext REQUEST_SCOPE.
Click Source Link
From source file:org.hdiv.taglib.html.HiddenTag2Test.java
private void runMyTest(String whichTest, String locale) { pageContext.setAttribute(Globals.LOCALE_KEY, new Locale(locale, locale), PageContext.SESSION_SCOPE); pageContext.setAttribute(Constants.BEAN_KEY, new SimpleBeanForTesting("Test Value"), PageContext.REQUEST_SCOPE); request.setAttribute("runTest", whichTest); try {//from ww w . j a va 2 s. co m pageContext.forward("/test/org/hdiv/taglib/html/TestHiddenTag2.jsp"); } catch (Exception e) { e.printStackTrace(); fail("There is a problem that is preventing the tests to continue!"); } }
From source file:org.hdiv.taglib.html.HiddenTag2Test.java
public void testHiddenPropertyIndexedArray() { ArrayList lst = new ArrayList(); lst.add("Test Message"); pageContext.setAttribute("lst", lst, PageContext.REQUEST_SCOPE); runMyTest("testHiddenPropertyIndexedArray", ""); }
From source file:org.hdiv.taglib.html.HiddenTag2Test.java
public void testHiddenPropertyIndexedArrayProperty() { SimpleBeanForTesting sbft = new SimpleBeanForTesting(); ArrayList lst = new ArrayList(); lst.add("Test Message"); sbft.setList(lst);//from w w w. ja v a2 s.com pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE); runMyTest("testHiddenPropertyIndexedArrayProperty", ""); }
From source file:org.hdiv.taglib.html.HiddenTag2Test.java
public void testHiddenPropertyIndexedMap() { HashMap map = new HashMap(); map.put("tst1", "Test Message"); pageContext.setAttribute("lst", map, PageContext.REQUEST_SCOPE); runMyTest("testHiddenPropertyIndexedMap", ""); }
From source file:org.hdiv.taglib.html.HiddenTag2Test.java
public void testHiddenPropertyIndexedMapProperty() { SimpleBeanForTesting sbft = new SimpleBeanForTesting(); HashMap map = new HashMap(); map.put("tst1", "Test Message"); sbft.setMap(map);/* w w w .j a va 2s. c o m*/ pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE); runMyTest("testHiddenPropertyIndexedMapProperty", ""); }
From source file:org.hdiv.taglib.html.HiddenTag2Test.java
public void testHiddenPropertyIndexedEnumeration() { StringTokenizer st = new StringTokenizer("Test Message"); pageContext.setAttribute("lst", st, PageContext.REQUEST_SCOPE); runMyTest("testHiddenPropertyIndexedEnumeration", ""); }
From source file:org.hdiv.taglib.html.HiddenTag2Test.java
public void testHiddenPropertyIndexedEnumerationProperty() { SimpleBeanForTesting sbft = new SimpleBeanForTesting(); StringTokenizer st = new StringTokenizer("Test Message"); sbft.setEnumeration(st);/*from w w w . ja v a2 s . co m*/ pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE); runMyTest("testHiddenPropertyIndexedEnumerationProperty", ""); }
From source file:org.hyperic.hq.ui.taglib.display.TableTag.java
/** * This functionality is borrowed from struts, but I've removed some struts * specific features so that this tag can be used both in a struts * application, and outside of one./* w w w . java 2s .c o m*/ * * Locate and return the specified bean, from an optionally specified scope, * in the specified page context. If no such bean is found, return * <code>null</code> instead. * * @param pageContext * Page context to be searched * @param name * Name of the bean to be retrieved * @param scope * Scope to be searched (page, request, session, application) or * <code>null</code> to use <code>findAttribute()</code> instead * * @exception JspException * if an invalid scope name is requested */ public Object lookup(PageContext pageContext, String name, String scope) throws JspException { Object bean = null; if (scope == null) bean = pageContext.findAttribute(name); else if (scope.equalsIgnoreCase("page")) bean = pageContext.getAttribute(name, PageContext.PAGE_SCOPE); else if (scope.equalsIgnoreCase("request")) bean = pageContext.getAttribute(name, PageContext.REQUEST_SCOPE); else if (scope.equalsIgnoreCase("session")) bean = pageContext.getAttribute(name, PageContext.SESSION_SCOPE); else if (scope.equalsIgnoreCase("application")) bean = pageContext.getAttribute(name, PageContext.APPLICATION_SCOPE); else { Object[] objs = { name, scope }; if (prop.getProperty("error.msg.cant_find_bean") != null) { String msg = MessageFormat.format(prop.getProperty("error.msg.cant_find_bean"), objs); throw new JspException(msg); } else { throw new JspException("Could not find " + name + " in scope " + scope); } } return (bean); }
From source file:org.jahia.modules.tagcloud.taglibs.TagCloudTag.java
@Override public int doStartTag() throws JspException { try {/*w w w. jav a2 s .com*/ final JCRNodeWrapper node = getCurrentResource().getNode(); final RenderContext renderContext = getRenderContext(); final JCRNodeWrapper boundComponent = org.jahia.taglibs.uicomponents.Functions.getBoundComponent(node, renderContext, "j:bindedComponent"); if (boundComponent != null) { // we need to render the hidden.load view of the bound component to make sure that all elements are loaded, this is, in particular, needed when the bound component is a jnt:query component // this is equivalent to using in the JSP: // <template:option node="${boundComponent}" nodetype="${boundComponent.primaryNodeTypeName},jmix:list" view="hidden.load"> // <template:param name="queryLoadAllUnsorted" value="true"/> // </template:option> OptionTag.renderNodeWithViewAndTypes(boundComponent, "hidden.load", boundComponent.getPrimaryNodeTypeName() + ",jmix:list", pageContext, Collections.singletonMap("queryLoadAllUnsorted", "true")); // get component configuration int minimumCardinalityForInclusion = Integer .parseInt(node.getPropertyAsString("minInclusionCardinality")); int maxNumberOfTags = Integer.parseInt(node.getPropertyAsString("maxTagNumber")); // extract URL parameters final String facetURLParameterName = getFacetURLParameterName(boundComponent.getName()); final String currentQuery = Url .decodeUrlParam(renderContext.getRequest().getParameter(facetURLParameterName)); // generate cloud and applied facet list generateTagCloud(boundComponent, minimumCardinalityForInclusion, maxNumberOfTags, currentQuery, renderContext); } if (target != null && !target.isEmpty()) { pageContext.setAttribute(target, boundComponent, PageContext.REQUEST_SCOPE); } } catch (Exception e) { throw new JspException(e); } return SKIP_BODY; }
From source file:org.jahia.modules.tagcloud.taglibs.TagCloudTag.java
/** * Generates the tag cloud associated with the specified bound component, including only tags with a cardinality above the specified minimum cardinality for inclusion, up to * the specified maximum number of tags. * * @param boundComponent the component for which we want to generate a tag cloud. * @param minimumCardinalityForInclusion minimum cardinality (i.e. number of tagged elements) for a tag to be included in the tag cloud * @param maxNumberOfTags maximum number of tags included in the cloud, keeping most numerous tags first (i.e. tags with lower cardinality will be excluded from * the cloud first) * @param currentQuery the currently applied facet query * @param renderContext the {@link org.jahia.services.render.RenderContext} in which this tag cloud is being generated * @throws RepositoryException if something went wrong accessing the JCR repository while processing the bound component's tags *//*from w w w. j ava 2 s .c o m*/ public void generateTagCloud(JCRNodeWrapper boundComponent, int minimumCardinalityForInclusion, int maxNumberOfTags, String currentQuery, RenderContext renderContext) throws RepositoryException { // applied facets final Map<String, List<KeyValue>> appliedFacets = Functions.getAppliedFacetFilters(currentQuery); // query QueryResultWrapper filteredTags = getNodesWithFacets(boundComponent, minimumCardinalityForInclusion, maxNumberOfTags, appliedFacets); if (!filteredTags.isFacetResultsEmpty()) { // map recording which unapplied tags have which cardinality, sorted in reverse cardinality order (most numerous tags first, being more important) final NavigableMap<Integer, Set<Tag>> tagCounts = new TreeMap<Integer, Set<Tag>>(); // applied tags facets final List<KeyValue> appliedTagsValues = appliedFacets.get(Constants.TAGS); // list of applied tags List<Tag> appliedTagsList = Collections.emptyList(); if (appliedTagsValues != null) { appliedTagsList = new ArrayList<Tag>(appliedTagsValues.size()); } // action URL start final String facetURLParameterName = getFacetURLParameterName(boundComponent.getName()); final String url = renderContext.getURLGenerator().getMainResource(); final String actionURLStart = url + "?" + facetURLParameterName + "="; // process the query results final FacetField tags = filteredTags.getFacetField(Constants.TAGS); final List<FacetField.Count> values = tags.getValues(); int totalCardinality = 0; for (FacetField.Count value : values) { // facet query should only return tags with a cardinality greater than the one we specified final int count = (int) value.getCount(); // facets return value of the j:tags property which is a weak reference to a node so we need to load it to get its name final String tagUUID = value.getName(); final JCRNodeWrapper tagNode = boundComponent.getSession().getNodeByUUID(tagUUID); final String name = tagNode.getDisplayableName(); // create tag final Tag tag = new Tag(name, count, tagUUID, value); if (!Functions.isFacetValueApplied(value, appliedFacets)) { // only add tag to cloud if it's not applied // increase totalCardinality with the current tag's count, this is used to compute the tag's weight in the cloud totalCardinality += count; // add tag to tag counts Set<Tag> associatedTags = tagCounts.get(count); if (associatedTags == null) { associatedTags = new HashSet<Tag>(); tagCounts.put(count, associatedTags); } associatedTags.add(tag); } else { // get KeyValue for current tag KeyValue current = null; for (KeyValue tagsValue : appliedTagsValues) { if (tagUUID.equals(tagsValue.getKey())) { current = tagsValue; break; } } tag.setDeleteActionURL( getActionURL(actionURLStart, Functions.getDeleteFacetUrl(current, currentQuery))); appliedTagsList.add(tag); } } Tag.setTotalCardinality(totalCardinality); // extract only the maxNumberOfTags most numerous tags final Map<String, Tag> tagCloud = new LinkedHashMap<String, Tag>(maxNumberOfTags); boolean stop = false; for (Set<Tag> tags1 : tagCounts.descendingMap().values()) { if (stop) { break; } for (Tag tag : tags1) { if (tagCloud.size() < maxNumberOfTags) { String result = getActionURL(actionURLStart, Functions.getFacetDrillDownUrl(tag.getFacetValue(), currentQuery)); tag.setActionURL(result); tagCloud.put(tag.getName(), tag); } else { stop = true; break; } } } // put cloud and applied tags in their respective page context variables pageContext.setAttribute(cloudVar, tagCloud, PageContext.REQUEST_SCOPE); pageContext.setAttribute(appliedTags, appliedTagsList, PageContext.REQUEST_SCOPE); } }