Reply To: @Join, @RequestAction and dispatch

Splash Forums Rewrite Users @Join, @RequestAction and dispatch Reply To: @Join, @RequestAction and dispatch

#27560

elbow
Participant
public abstract class BaseDetailWebBean<E extends SluggableEntity, M extends SecureManager<E>> {

    protected String slug;

    public String getSlug() {
        return slug;
    }

    public void setSlug(String slug) {
        this.slug = slug;
    }

    protected E object;

    @Autowired
    private M manager;

    public void load() {
        this.object = manager.findBySlug(slug);
        if (this.object == null) {
            throw new NotFoundException();
        }
    }

}

implemented as

@Component
@Scope("view")
public class DepartmentDetailWebBean extends BaseDetailWebBean<Department, SecureDepartmentManager> {

    public Department getDepartment() {
        return object;
    }

}

with configuration

@Component
@RewriteConfiguration
public class DepartmentRewriteRules extends HttpConfigurationProvider {

    @Override
    public Configuration getConfiguration(ServletContext context) {
        return ConfigurationBuilder.begin()
                .addRule(Join.path("/department/{slug}/").to("/WEB-INF/resources/secure/department/detail.xhtml"))
                .addRule(Join.path("/department/").to("/WEB-INF/resources/secure/department/list.xhtml"));
    }

    @Override
    public int priority() {
        return 10;
    }
}

and view

<!DOCTYPE html>
<html lang="en" xml:lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

<ui:composition template="/WEB-INF/resources/templates/layout.xhtml">

    <f:metadata>
        <f:viewParam name="slug" value="#{departmentDetailWebBean.slug}" />
        <f:viewAction action="#{departmentDetailWebBean.load}" />
    </f:metadata>

    <ui:define name="title">#{departmentDetailWebBean.department.name}</ui:define>

</ui:composition>
</html>

works.

If I use annotations, then I don’t have the <f:metadata> section, nor the rules, but instead have

public abstract class BaseDetailWebBean<E extends SluggableEntity, M extends SecureManager<E>> {

    @Parameter
    @Deferred
    protected String slug;

    public String getSlug() {
        return slug;
    }

    public void setSlug(String slug) {
        this.slug = slug;
    }

    protected E object;

    @Autowired
    private M manager;

    @RequestAction
    @Deferred
    @IgnorePostback
    public void load() {
        this.object = manager.findBySlug(slug);
        if (this.object == null) {
            throw new NotFoundException();
        }
    }

}

implemented as

@Component
@Scope("view")
@Join(path = '/department/{slug}/', to = '/WEB-INF/resources/secure/department/detail.xhtml')
public class DepartmentDetailWebBean extends BaseDetailWebBean<Department, SecureDepartmentManager> {

    public Department getDepartment() {
        return object;
    }

}

works in ‘happy days’ cases, but not when I’m attempting a dispatch on the joined URL.