You can use the Assembler eventing framework as an extension point for navigation cartridges in cases where extending an existing cartridge handler is insufficient.

If you are making modifications to the navigation cartridges, you can trigger processing logic based on Assembler events instead of subclassing the core cartridge handlers.

Using an event listener instead of extending a cartridge handler introduces the following considerations:

The Assembler provides an empty implementation of the AssemblerEventListener, AssemblerEventAdapter. You can extend this implementation to create a listener that triggers on an Assembler event.

To create an event listener:

  1. Create a new Java class that extends the AssemblerEventAdapter.

    For example:

    public class ResultsListListener extends AssemblerEventAdapter {
    }
  2. Override the methods that correspond to the events for which you wish to trigger custom processing logic:

    public class ResultsListListener extends AssemblerEventAdapter {
        @Override
        public void cartridgePreprocessStarting(AssemblerEvent event){
        ...
        }
    
        @Override
        public void cartridgeProcessComplete(AssemblerEvent event){
        ...
        }
    }

    For a list of Assembler events, see the Assembler event framework reference or refer to the Assembler API Reference (Javadoc).

  3. Add conditional logic to restrict processing to a specific cartridge handler:

    public class ResultsListListener extends AssemblerEventAdapter {
        ...
    
        @Override
        public void cartridgeProcessComplete(AssemblerEvent event){
            if(event.getContentItem() != null && "ResultsList".equals(event.getContentItem().getType()){
    
                ...
            }
        }
    }
  4. Add processing logic.

    The example below prefixes the max_price property on a record with a dollar sign:

    public class ResultsListListener extends AssemblerEventAdapter {
    
        ...
    
        @Override
        public void cartridgeProcessComplete(AssemblerEvent event){
            if(event.getContentItem() != null && "ResultsList".equals(event.getContentItem().getType()){
                ResultsList resultsList = (ResultsList) event.getContentItem();
                for(Record record : resultsList.getRecords()){
                    Attribute price = record.getAttributes().get("product.max_price");
                    if(price != null){
                        for(int i = 0 ; i < price.size(); i++){
                            price.set(i, "$" + price.get(i).toString());
                        }
                    }
                }
            }
        }
    }

After creating a new listener, you must register it by including it in the list of listeners for the assemblerFactory object.


Copyright © Legal Notices