Get request object anywhere

In portalLib you have getContent and getComponent that is usable anywhere inside an execution context. I’m trying to get something similar for the request object that is passed to the initial get entry function. This is so to avoid having to always pass req as a function param everywhere. A function may get req as a param when it is only used by a function a lot further down the chain.

This java class almost does the job:

import com.enonic.xp.script.bean.BeanContext;
import com.enonic.xp.script.bean.ScriptBean;
import com.enonic.xp.portal.PortalRequest;
import com.enonic.xp.portal.impl.mapper.PortalRequestMapper;

public final class Request implements ScriptBean {
    private PortalRequest request;

    public PortalRequestMapper getRequest( ) {
        final PortalRequestMapper requestMapper = new PortalRequestMapper( request );
        return requestMapper;

    public void initialize( final BeanContext context )
        this.request = context.getBinding( PortalRequest.class ).get();

But it is dependent on the PortalRequestMapper from impl. Is there another way to do this except using PortalRequestMapper?

This can also be considered a feature request for a getRequest function in portal lib.

PortalRequest is a quite composite class, including properties that are not allowed for users without particular permissions, like a parent site. So looks like the best way is to implement your own PortalRequestMapper by implementing com.enonic.xp.script.serializer.MapSerializable interface.
Then you will get a possibility to decide which portal request properties will be visible in the result depending on your particular case and current user permissions.

1 Like