An Action object allows you to construct a link that represents a decision by an end user. The included fields and values depend on the action that the user wishes to take; they can include the action label, the root site path, the path to the destination content within the site, and the site state.

The Action class does not include a complete URL to the resulting navigation state or record; instead, the URL resulting from an Action is generally created by combining fields. For details, see "Action fields."

The Assembler splits the class into three subclasses:

All Actions include the following fields:

Additionally, certain types of Actions may include additional fields. A NavigationAction includes a field for the navigation state represented by the Action, while a RecordAction action includes a field for the corresponding record state.

To construct a useable link from an Action, the UI tier of your application (the cartridge renderers in the Discover Electronics reference application) must include logic for combining the Action fields. A typical use case consists of directly concatenating fields, depending on the type of page you wish to link to.

In the reference application, a link to a navigation state typically combines the content path and the desired navigation state:

String href = action.getContentPath() + action.getNavigationState();

A link to a record details page combines the content path with the appropriate record state:

String href = action.getContentPath() + action.getRecordState();

In an application with multiple sites where your site definition specifies URL pattern matching, a link to a navigation state combines the site state, the content path and the desired navigation state. In this example, getMatchedUrlPattern returns the portion of URL from the incoming request that matches with a pattern configured on a site.

String href = action.getSiteState().getMatchedUrlPattern() + action.getContentPath() + action.getNavigationState();

If the site definition in this application specifies domain pattern matching, then the link would be:

String href = action.getContentPath() + action.getNavigationState();

If it matches a domain pattern, getMatchedUrlPattern() is blank so you can use the following for either domain or URL pattern matching:

String href = action.getSiteState().getMatchedUrlPattern() + action.getContentPath() + action.getNavigationState(); 

This does not handle the case where the site ID is passed, such as preview passing the site ID. To handle all these cases, you can add com.endeca.infront.site.SiteUtils.getSiteUrl to return a site-specific URL.

For example:

SiteUtils.getSiteUrl(action.getSiteState(), action.getContentPath() + action.getNavigationState())

FunctionTags also has a getSiteUrl method so you can call this from a JSP file as well. For example, in the userPanel.jsp file:

<a href='<c:url value="${util:getSiteUrl(siteState, '/about-us')}" />'>
        About Us
</a>

A link to an arbitrary URL does not require combining fields, since the UrlAction object includes a method for directly retrieving a configured URL:

String href = action.getUrl();

Most of the Discover Electronics cartridge renderers use the <discover:link> tag, defined in WEB-INF\tags\discover\link.tag. The tag makes use of the getUrlForAction function declared in WEB-INF\tlds\functions.tld and defined in WEB-INF\classes\com\endeca\infront\refapp\support\FunctionTags.java.

The packaged services in Oracle Tools and Frameworks return specific actions for the included cartridges.

The following is an Experience Manager example of the results of a guided search service query for the URI http://localhost:8006/assembler-authoring/json/services/guidedsearch?Ntt=pink+camera, serialized to JSON:

{
    "@type": "GuidedSearchService",
    "name": "Guided Search Service",
    "navigation": { … },
    "breadcrumbs": { … },
    "resultsList": {
        "@type":"ResultsList",
        "totalNumRecs":228,
        "sortOptions":[
            {
                "@class":"com.endeca.infront.cartridge.model.SortOptionLabel",
                "selected":true,
                "navigationState":"?Ntt=pink+camera",
                "contentPath":"\/services\/guidedsearch",
                "siteRootPath":"\/pages",
                "siteState":{
                    "@class":"com.endeca.infront.site.model.SiteState",
                    "contentPath":"\/services\/guidedsearch",
                    "siteId":"\/DiscoverElectronics",
                    "properties":{
                                 }
                            },
                "label":"Relevance"
            },
            { … }
        ],
        "firstRecNum":1,
        "lastRecNum":12,
        "pagingActionTemplate":{ ... },
        "recsPerPage":12,
        "records":[
            {
                "@class":"com.endeca.infront.cartridge.model.Record",
                "detailsAction":{
                    "@class":"com.endeca.infront.cartridge.model.RecordAction",
                    "recordState":"\/Canon\/Digital-IXUS-80-IS\/_\/A-1439032",
                    "contentPath":"\/services\/recorddetails",
                    "siteRootPath":"\/pages",
                    "siteState":{
                        "@class":"com.endeca.infront.site.model.SiteState",
                        "contentPath":"\/services\/guidedsearch",
                        "siteId":"\/DiscoverElectronics",
                        "properties":{
                                     }
                                }
                 },
                 "numRecords":3,
                 "attributes":{},
                 "records":[ ... ]        
            },
            { content removed from this example }
        ]
    },
    "content removed from this example"
}

Note that the sortOptions returned for the Results List cartridge include the Action fields required to create a URL for the navigation state resulting from modifying the sort order. Sorting by Price (Ascending) requires constructing a URL with the appropriate navigationState and siteState, resulting in http://localhost:8006/assembler-authoring/json/services/guidedsearch?Ns=product.price|0&Ntt=pink+camera. Querying this URL returns the JSON response for the re-ordered results.

Similarly, each of the records returned in the Results List includes the Action fields for an associated record details page. Using the /services/recorddetails content root and the recordState for the Slim Camera Case results in the URL http://localhost:8006/assembler-authoring/json/services/recorddetails/Kodak/Slim-Camera-Case/_/A-2707821. Querying this URL returns the record details for the Slim Camera Case.

The following is an Oracle Commerce Guided Search (without Experience Manager) example of the results of the same guided search service query for the URI http://localhost:8006/assembler-authoring/json/services/guidedsearch?Ntt=pink+camera, serialized to JSON:

{
    "@type": "GuidedSearchService",
    "name": "Guided Search Service",
    "navigation": { … },
    "breadcrumbs": { … },
    "resultsList": {
        "@type":"ResultsList",
        "totalNumRecs":228,
        "sortOptions":[
            {
                "@class":"com.endeca.infront.cartridge.model.SortOptionLabel",
                "selected":true,
                "navigationState":"?Ntt=pink+camera",
                "contentPath":"\/guidedsearch",
                "siteRootPath":"\/services",
                "siteState":{
                    "@class":"com.endeca.infront.site.model.SiteState",
                    "contentPath":"\/guidedsearch",
                    "siteId":"\/DiscoverElectronics",
                    "properties":{
                                 }
                            },
                "label":"Relevance"
            },
            { … }
        ],
        "firstRecNum":1,
        "lastRecNum":12,
        "pagingActionTemplate":{ ... },
        "recsPerPage":12,
        "records":[
            {
                "@class":"com.endeca.infront.cartridge.model.Record",
                "detailsAction":{
                    "@class":"com.endeca.infront.cartridge.model.RecordAction",
                    "recordState":"\/Canon\/Digital-IXUS-80-IS\/_\/A-1439032",
                    "contentPath":"\/recorddetails",
                    "siteRootPath":"\/services",
                    "siteState":{
                        "@class":"com.endeca.infront.site.model.SiteState",
                        "contentPath":"\/guidedsearch",
                        "siteId":"\/DiscoverElectronics",
                        "properties":{
                                     }
                                }
                 },
                 "numRecords":3,
                 "attributes":{},
                 "records":[ ... ]        
            },
            { content removed from this example }
        ]
    },
    "content removed from this example"
}

Note the differences from the Experience Manager example for the contentPath and siteRootPath values.


Copyright © Legal Notices