TestRouteView.java 1.73 KB
package org.legrog.web.xyz;

import org.ocpsoft.rewrite.annotation.Join;
import org.ocpsoft.rewrite.annotation.Parameter;
import org.ocpsoft.rewrite.annotation.RequestAction;
import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.el.El;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.servlet.ServletContext;
import java.io.Serializable;

@Named
@RequestScoped
@Join(path = "/TestRoute/{bar}", to = "/xyz/TestRoute.jsf")
public class TestRouteView implements Serializable {

    String foo = "my first String";

    @Parameter
    String bar;

    @RequestAction
    public void init() {
        if (bar == null) {
            foo = "my modified string without bar";
        } else {
            foo = "my string modified with "+ bar;
        }

    }

    public String getFoo() {
        return foo;
    }

    public void setFoo(String foo) {
        this.foo = foo;
    }

    public String getBar() {
        return bar;
    }

    public void setBar(String bar) {
        this.bar = bar;
    }

    @RewriteConfiguration
    public static class RewriteConfig extends HttpConfigurationProvider {

        public Configuration getConfiguration(ServletContext context) {
            return ConfigurationBuilder.begin()
                    .addRule(org.ocpsoft.rewrite.servlet.config.rule.Join.path("/TestRoute2/{bar}").to("/xyz/TestRoute.jsf"))
                    .where("bar").bindsTo(El.property("testRouteView.bar"))
                    ;
        }

        public int priority() {
            return 0;
        }
    }
}