Creating business logic components - Using defaults

You can call PersonLogic.add.logic if you create the following code:

package org.vraptor.examples.first;

import org.vraptor.annotations.Component;
import org.vraptor.annotations.Parameter;

@Component
public class PersonLogic {

        public void add(Person person) {
                System.out.printf("Adding %s to the database!%n", person);
        }

}

Overriding component name

To override the component name, simply change the component tag:

people.add.logic is ok when using the following code:

package org.vraptor.examples.first;

import org.vraptor.annotations.Component;
import org.vraptor.annotations.Parameter;

@Component("people")
public class PersonLogic {

        public void add(Person person) {
                System.out.printf("Adding %s to the database!%n", person);
        }

}

Overriding logic name

To override the logic name, simply use the logic tag:

person.addNewPersonPlease.logic is ok when using the following code:

package org.vraptor.examples.first;

import org.vraptor.annotations.Component;
import org.vraptor.annotations.Logic;
import org.vraptor.annotations.Parameter;

@Component("person")
public class PersonLogic {

        @Logic("addNewPersonPlease")
        public void add(Person person) {
                System.out.printf("Adding %s to the database!%n", person);
        }

}

Overriding logic parameter names

Receiving an Person as argument, would expect a web parameter named person.name, person.age, etc. You cannot change this name only by changing the argument's name since java has no reflection for argument names at this time (only java 7).

You can use @Logic(parameters=...) for this. It is also useful when you need two arguments of the same type.

@Component("person")

public class PersonLogic {

        @Logic(parameters="importantPerson")
        public void add(Person x) {
                System.out.println("importantPerson.name will be used");
        }

}