Jump to content
  • Overview

    This implementation is designed to support cascading behavior based on query input controls. These controls can use parameter values from other named parameter input controls whose values can resolve to a string. These strings are substituted into the defined query for that cascading input control with the usage of tokens specified in the cascading input control's query.

    For example, a query such as:

    SELECT billing_address_state  FROM accountsWHERE billing_address_country = $P{country}   AND billing_address_state = $P{state}[/code]

    Detailed specification


    Country - State - Name cascade

    p_country input control - Single select query input control.
      SELECT distinct billing_address_country    FROM accountsORDER BY billing_address_country[/code]
    p_state input control - Single select query input control.
      SELECT distinct billing_address_state    FROM accounts   WHERE billing_address_country = $P{p_country}ORDER BY billing_address_state[/code]
    p_name input control Single select query input control.
      SELECT distinct name    FROM accounts   WHERE billing_address_country = $P{p_country}     AND billing_address_state = $P{p_state}ORDER BY name[/code]
    ....<parameter name="p_country">    <defaultvalueexpression>        <!--[CDATA["USA"]]-->    </defaultvalueexpression></parameter><parameter name="p_state">    <defaultvalueexpression>        <!--[CDATA["CA"]]-->    </defaultvalueexpression></parameter><parameter name="p_name">    <defaultvalueexpression>        <!--[CDATA["Alpha-Murraiin Communications, Inc"]]-->    </defaultvalueexpression></parameter><querystring>    <!--[CDATA[select * from accounts where name = $P{p_name}]]--></querystring>....[/code]

    Multi-select control example

    Included with sample reports.

    Country_multi_select control

    Multi-select query control. billing_address_country is the visible and value column of the control.


      SELECT DISTINCT billing_address_country    FROM accountsORDER BY billing_address_country[/code]


    Multi-select query control. billing_address_state is the value column. billing_address_state and billing_address_country are the visible columns.


      SELECT DISTINCT billing_address_state, billing_address_country    FROM accounts   WHERE $X{IN, billing_address_country, Country_multi_select}ORDER BY billing_address_country, billing_address_state[/code]



    <parameter class="java.util.Collection" name="Country_multi_select">    <defaultvalueexpression>        <!--[CDATA[new ArrayList(Arrays.asList(new String[] {"USA"}))]]-->    </defaultvalueexpression></parameter><parameter class="java.util.Collection" name="Cascading_state_multi_select">    <defaultvalueexpression>        <!--[CDATA[new ArrayList(Arrays.asList(new String[] {"CA"}))]]-->    </defaultvalueexpression></parameter><querystring>    <!--[CDATA[          select * from accounts           where $X{IN, billing_address_state, Cascading_state_multi_select}             and $X{IN, billing_address_country, Country_multi_select}        order by billing_address_country, billing_address_state, name    ]]--></querystring>[/code]


    Setting up query input controls for cascading

    Parameter substitution in query input controls follows the same approach as for JasperReports. It works for queries of all types of query connections. $P, $P! and $X (for SQL queries) parameters are supported.

    As now, single select query input controls return single values to reports and queries, and multi-select query input controls return collections.

    A number of parameters will always be available for query input controls. "Standard" controls will always be provided to reports (not queries), even if an input control is not defined for them.

    Parameter NameTypeNotesStandard?
    LoggedInUserUserNot usable in query input control, but is used as parameter to reportYes
    LoggedInUsernameStringOf logged in userYes
    LoggedInUserFullNameStringOf logged in userNo
    LoggedInUserEmailAddressStringOf logged in userNo
    LoggedInUserEnabledBooleanIs logged in user enabled?No
    LoggedInUserExternallyDefinedBooleanIs logged in user externally defined? ie. authenticated externallyNo
    LoggedInUserTenantIdStringOf logged in user. Only relevant in Pro/Enterprise.No
    LoggedInUserRolesCollection Current set of roles of logged in user. Useful for $X parameterNo
    LoggedInUserAttributesMap ,>Not usable in query input control, but is used as parameter to report. Empty map if no attributesNo
    LoggedInUserAttributeNamesCollection User profile attribute names. Useful for $X parameters. Empty collection if no attributesNo
    LoggedInUserAttributeValuesCollection  No
    LoggedInUserAttribute_ StringAttribute value for matched attribute name (like "att1") on the user. Empty string if no match. Only provided if defined in a query or as a report parameter.No


    Changes to parameters for reports in JasperServer

    The above "always available" parameters are also provided for reports if they are defined as parameters in the JRXML. This adds to the current LoggedInUser and LoggedInUsername parameters that are currently available.

    Extension point for introducing additional built-in parameters

    Classes that implement BuiltInParameterProvider can be included to provide parameters which are available to reports and queries.

    public interface BuiltInParameterProvider {     /**      * Generate a set of standard parameters      *      * Each element is a JRParameter, value      *      * @param context      * @param jrParameters unchanged      * @param parameters unchanged      * @return List<object[]> [JRParameter, value]      */     public List<object[]> getParameters(ExecutionContext context, List jrParameters, Map parameters);     /**      * Generate parameters can be requested by name that are not part of the standard set      *      * @param context      * @param jrParameters unchanged, can be null      * @param parameters unchanged      * @param name of parameter      * @return List<object[]> [JRParameter, value] or null if the given name is not set by this generator      */     public Object[] getParameter(ExecutionContext context, List jrParameters, Map parameters, String name);}[/code]

    To include your custom parameter provider, put the class into the WAR (in WEB-INF/classes or WEB-INF/lib) and add an instance of your class into the builtInParameterProviders bean in WEB-INF/applicationContext.xml, as follows:

    <bean class="java.util.ArrayList" id="builtInParameterProviders">    <constructor-arg>        <list>            <bean class="com.jaspersoft.jasperserver.api.engine.jasperreports.util.UserProfileBuiltInParameterProvider" />            <bean class="your.package.and.class.name.here" />        </list>    </constructor-arg></bean>[/code]

    Have a look at the UserProfileBuiltInParameterProvider class as an example.

    See Also


    User Feedback

    Recommended Comments

    There are no comments to display.

    This is now closed for further comments

  • Create New...