Navigator7: Annotated Parameter Injection

I’ve developped a Navigator7 interceptor that injects values in the fields of a Page.

Example:


@Page
public class ProductPage extends VerticalLayout implements ParamChangeListener {

    @Param(pos=0, required=true) Product p;          // "34"
    @Param(pos=1)                String value1;      // "AAAA"
    @Param(pos=2)                String value2;      // "BBBB"
    
    @Param                       String namedValue;  // "namedValue=CCCC"

    
    @Override
    public void paramChanged(NavigationEvent navigationEvent) {
        removeAllComponents();
        
        setSpacing(true);
        addComponent( new Label("Demo of the EntityUriAnalyzer with the @Param annotation."));
        addComponent( new Label("This is product " + p.getLabel()));
        addComponent( new Label("The product id is " + p.getId()));
        addComponent( new Label("value1 = "+value1));
        addComponent( new Label("value2 = "+value2));
        addComponent( new Label("namedValue = "+namedValue));
        

        // a lot of UI code (biggest part of the page) should follow here.
        // .....
    }
    
}

In this example, p is injected automatically. The url to get the page is:
http://mycompany.com/#Product/34/AAAA/BBBB/namedValue=CCCC

“34” is converted into an instance of Product (it’s probably the primary key of Product). EntityUriAnalyzer can do that. That product is injected in ProductPage.p.
“AAAA” is injected in ProductPage.value1.

p, value1 and value2 are positional: they must be at a specific position in the URI (1st, second,…).
namedValue is named: it must have a name with the “=” sign in the URI. By default, it’s the name of the field.
All parameters can be required or optional.

There are extra features as page specific customized validation/convertion code entry point (not shown here and typically not needed).

Parameter injection makes the following very nice feature possible: strongly typed links.
From another page, you don’t build a link like that anymore:

Link link = new PageLink("This is a link to product.", ProductPage.class, 
    p.getId().toString + "/AAAA/BBBB/namedValue=CCCC");

but like this instead:

Link link = new ParamPageLink("This is a link to product.", ProductPage.class, p, "AAAA", "BBBB")
                .addParam("namedValue", "CCCC");

(note the chained method call à la Hibernate).
This link generation reads the @Param annotations of ProductPage and throws a RuntimeException if a required parameter is missing, or if they are given in the wrong order or if anything else is wrong. This was the main reason that triggered this develpment.

It’s in Navigator7 version 7.3.