4-Oct-03 (Created: 4-Oct-03) | More in 'Java-Portlets'

How do you know if a request is intended for the current portlet?


//Taken from PortletSessionState.java
    /**
     * Returns true if the request pertains to current portlet instance. It assumes that the portlet interested in
     * recognizing its own requests, has a hidden input "js_peid". For backwards compatibility, if "js_peid" was
     * not set, this method will return TRUE.
     * 
     * @param rundata
     * @return boolean
     */
    public static boolean isMyRequest(RunData rundata, Portlet portlet) {

        // If the request does not contain "js_peid", assume that the portlet is not interested 
        // in isMyRequest functionality and return TRUE.
        String requestPeid = rundata.getParameters().getString("js_peid");
        if (requestPeid == null || requestPeid.equalsIgnoreCase(""))
        {
            return true;
        }

        // If the portlet does not have its id set, assume that the portlet is not interested
        // in isMyRequest functionality and return TRUE.
        if (portlet == null || portlet.getID() == null)
        {
            return true;
        }

        // Retrieve portlet instance
        String peId = null;
        PortletInstance instance = PersistenceManager.getInstance(portlet, rundata);
        if (instance != null)
        {
            peId = instance.getPortlet().getID();
        }

        // Compare the ids
        if (peId != null && peId.equals(requestPeid))
        {
            return true;
        }
        else
        {
            return false;
        }
    }