Always Link To Actions pattern

The basic idea is that you should never create a direct html hyperlink to the presentation layer (jsp, velocity, freemarker etc).

Let's say you have direct links to a jsp file called /login.jsp.

If one day you need to do something before showing this jsp you will have to find each and every point in your application that links to this file and change it to some kind of bussiness logic: login.prepare.logic.

If you had done it earlier by creating this login.prepare.logic there would be almost no changes: the impact would be minimum...

But you do not want to create a simple component and logic that does nothing, correct?

Wrong... it's better to have such an "useless" method now than having to change loads of links later on during development or testing...

  1. Create your component:
    @Component("login")
    public class Login {
    
            public void prepare() {
                    // does nothing
            }
            
    }

    This will make vraptor go to /login/prepare.ok.jsp directly if login.prepare.logic is called.

    When the situation mentioned earlier arises, you simply implement your new business logic!

    Note: Struts used to warn people to use this pattern in its old days by creating simple tags as follows:

            <action path="/login.prepare" forward="/login.jsp"/>