Search in sources :

Example 1 with PageContext

use of jakarta.servlet.jsp.PageContext in project tomcat by apache.

the class ScopedAttributeELResolver method getValue.

@Override
public Object getValue(ELContext context, Object base, Object property) {
    Objects.requireNonNull(context);
    Object result = null;
    if (base == null) {
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context.getContext(JspContext.class);
            result = page.findAttribute(key);
            if (result != null) {
                context.setPropertyResolved(base, property);
            }
        }
    }
    return result;
}
Also used : JspContext(jakarta.servlet.jsp.JspContext) PageContext(jakarta.servlet.jsp.PageContext)

Example 2 with PageContext

use of jakarta.servlet.jsp.PageContext in project tomcat by apache.

the class ScopedAttributeELResolver method getFeatureDescriptors.

@Deprecated(forRemoval = true, since = "JSP 3.1")
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
    PageContext ctxt = (PageContext) context.getContext(JspContext.class);
    List<FeatureDescriptor> list = new ArrayList<>();
    Enumeration<String> e;
    Object value;
    String name;
    e = ctxt.getAttributeNamesInScope(PageContext.PAGE_SCOPE);
    while (e.hasMoreElements()) {
        name = e.nextElement();
        value = ctxt.getAttribute(name, PageContext.PAGE_SCOPE);
        FeatureDescriptor descriptor = new FeatureDescriptor();
        descriptor.setName(name);
        descriptor.setDisplayName(name);
        descriptor.setExpert(false);
        descriptor.setHidden(false);
        descriptor.setPreferred(true);
        descriptor.setShortDescription("page scoped attribute");
        descriptor.setValue("type", value.getClass());
        descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
        list.add(descriptor);
    }
    e = ctxt.getAttributeNamesInScope(PageContext.REQUEST_SCOPE);
    while (e.hasMoreElements()) {
        name = e.nextElement();
        value = ctxt.getAttribute(name, PageContext.REQUEST_SCOPE);
        FeatureDescriptor descriptor = new FeatureDescriptor();
        descriptor.setName(name);
        descriptor.setDisplayName(name);
        descriptor.setExpert(false);
        descriptor.setHidden(false);
        descriptor.setPreferred(true);
        descriptor.setShortDescription("request scope attribute");
        descriptor.setValue("type", value.getClass());
        descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
        list.add(descriptor);
    }
    if (ctxt.getSession() != null) {
        e = ctxt.getAttributeNamesInScope(PageContext.SESSION_SCOPE);
        while (e.hasMoreElements()) {
            name = e.nextElement();
            value = ctxt.getAttribute(name, PageContext.SESSION_SCOPE);
            FeatureDescriptor descriptor = new FeatureDescriptor();
            descriptor.setName(name);
            descriptor.setDisplayName(name);
            descriptor.setExpert(false);
            descriptor.setHidden(false);
            descriptor.setPreferred(true);
            descriptor.setShortDescription("session scoped attribute");
            descriptor.setValue("type", value.getClass());
            descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
            list.add(descriptor);
        }
    }
    e = ctxt.getAttributeNamesInScope(PageContext.APPLICATION_SCOPE);
    while (e.hasMoreElements()) {
        name = e.nextElement();
        value = ctxt.getAttribute(name, PageContext.APPLICATION_SCOPE);
        FeatureDescriptor descriptor = new FeatureDescriptor();
        descriptor.setName(name);
        descriptor.setDisplayName(name);
        descriptor.setExpert(false);
        descriptor.setHidden(false);
        descriptor.setPreferred(true);
        descriptor.setShortDescription("application scoped attribute");
        descriptor.setValue("type", value.getClass());
        descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE);
        list.add(descriptor);
    }
    return list.iterator();
}
Also used : JspContext(jakarta.servlet.jsp.JspContext) FeatureDescriptor(java.beans.FeatureDescriptor) ArrayList(java.util.ArrayList) PageContext(jakarta.servlet.jsp.PageContext)

Example 3 with PageContext

use of jakarta.servlet.jsp.PageContext in project tomcat by apache.

the class ScopedAttributeELResolver method setValue.

@Override
public void setValue(ELContext context, Object base, Object property, Object value) {
    Objects.requireNonNull(context);
    if (base == null) {
        context.setPropertyResolved(base, property);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context.getContext(JspContext.class);
            int scope = page.getAttributesScope(key);
            if (scope != 0) {
                page.setAttribute(key, value, scope);
            } else {
                page.setAttribute(key, value);
            }
        }
    }
}
Also used : JspContext(jakarta.servlet.jsp.JspContext) PageContext(jakarta.servlet.jsp.PageContext)

Example 4 with PageContext

use of jakarta.servlet.jsp.PageContext in project tomcat by apache.

the class ImplicitObjectELResolver method getValue.

@Override
public Object getValue(ELContext context, Object base, Object property) {
    Objects.requireNonNull(context);
    if (base == null && property != null) {
        int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());
        if (idx >= 0) {
            PageContext page = (PageContext) context.getContext(JspContext.class);
            context.setPropertyResolved(base, property);
            switch(idx) {
                case APPLICATIONSCOPE:
                    return ScopeManager.get(page).getApplicationScope();
                case COOKIE:
                    return ScopeManager.get(page).getCookie();
                case HEADER:
                    return ScopeManager.get(page).getHeader();
                case HEADERVALUES:
                    return ScopeManager.get(page).getHeaderValues();
                case INITPARAM:
                    return ScopeManager.get(page).getInitParam();
                case PAGECONTEXT:
                    return ScopeManager.get(page).getPageContext();
                case PAGESCOPE:
                    return ScopeManager.get(page).getPageScope();
                case PARAM:
                    return ScopeManager.get(page).getParam();
                case PARAM_VALUES:
                    return ScopeManager.get(page).getParamValues();
                case REQUEST_SCOPE:
                    return ScopeManager.get(page).getRequestScope();
                case SESSION_SCOPE:
                    return ScopeManager.get(page).getSessionScope();
            }
        }
    }
    return null;
}
Also used : JspContext(jakarta.servlet.jsp.JspContext) PageContext(jakarta.servlet.jsp.PageContext)

Example 5 with PageContext

use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.

the class ArgumentTagTests method setUp.

@BeforeEach
public void setUp() throws Exception {
    PageContext context = createPageContext();
    parent = new MockArgumentSupportTag();
    tag = new ArgumentTag();
    tag.setPageContext(context);
    tag.setParent(parent);
}
Also used : PageContext(jakarta.servlet.jsp.PageContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

PageContext (jakarta.servlet.jsp.PageContext)70 Test (org.junit.jupiter.api.Test)62 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)28 NestedTestBean (org.springframework.beans.testfixture.beans.NestedTestBean)27 TestBean (org.springframework.beans.testfixture.beans.TestBean)27 ServletRequestDataBinder (org.springframework.web.bind.ServletRequestDataBinder)22 BindStatus (org.springframework.web.servlet.support.BindStatus)19 Errors (org.springframework.validation.Errors)17 DateFormat (java.text.DateFormat)6 SimpleDateFormat (java.text.SimpleDateFormat)6 CustomDateEditor (org.springframework.beans.propertyeditors.CustomDateEditor)6 JspContext (jakarta.servlet.jsp.JspContext)4 DefaultMessageSourceResolvable (org.springframework.context.support.DefaultMessageSourceResolvable)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 MessageSourceResolvable (org.springframework.context.MessageSourceResolvable)2 RequestContext (org.springframework.web.servlet.support.RequestContext)2 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 JspException (jakarta.servlet.jsp.JspException)1 FeatureDescriptor (java.beans.FeatureDescriptor)1