Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor eyes only cdi and formatting of injections docs #742

Merged
merged 5 commits into from
Aug 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,23 @@
public class Error404 extends DefaultControllerNotFoundHandler {

private final Router router;

private final Result result;

/**
* @deprecated CDI eyes only
*/
protected Error404() {
this(null, null, null);
}

@Inject
public Error404(Router router, Result result, Event<ControllerNotFound> event) {
super(event);
this.router = router;
this.result = result;
}

/**
* @deprecated CDI eyes only
*/
public Error404() {
this(null, null, null);
}

@Override
public void couldntFind(FilterChain chain, MutableRequest request, MutableResponse response) {
try {
Expand Down
10 changes: 5 additions & 5 deletions vraptor-site/content/en/cookbook/avoiding-browser-cache.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

private final HttpServletResponse response;

@Inject
public NoCacheInterceptor(HttpServletResponse response) {
this.response = response;
}

/**
* @deprecated CDI eyes only
*/
protected NoCacheInterceptor(){
this(null);
}

@Inject
public NoCacheInterceptor(HttpServletResponse response) {
this.response = response;
}

@BeforeCall
public void intercept() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@
@Controller
public class EventController implements Serializable {

@Inject private EventService service;
@Inject private Result result;
@Inject
private EventService service;

@Inject
private Result result;

@Get("/events")
public void event() {
Expand Down
66 changes: 37 additions & 29 deletions vraptor-site/content/en/docs/components.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

private final Session session;

// CDI forces the existence of this default constructor
protected CustomerDao() {
this(null);
/**
* @deprecated CDI eyes only
*/
protected CustomerDao() {
this(null);
}

@Inject
Expand Down Expand Up @@ -63,13 +65,14 @@
#!java
@ApplicationScoped
public class EmailConfiguration {
private final String host = "smtp.bazinga.com"
private final String user = "foo";
private final String password = "bar";
private final String host = "smtp.bazinga.com"
private final String user = "foo";
private final String password = "bar";

public Session getHost() {
return host;
}

public Session getUser() {
return user;
}
Expand All @@ -83,11 +86,12 @@

The implemented scopes are:

* `@ApplicationScoped` - the component is a singleton, just one for the entire application.
* `@SessionScoped` - the component is the same during the http session of the container.
* `@ConversationScoped` - the component instance is kept during a conversation.
* `@RequestScoped` - the component is the same during a request.
* `@Dependent` - the component is instanciated whenever it is requested.
| @ApplicationScoped | the component is a singleton, just one for the entire application.
| @SessionScoped | the component is the same during the http session of the container.
| @ConversationScoped | the component instance is kept during a conversation.
| @RequestScoped | the component is the same during a request.
| @Dependent | the component is instanciated whenever it is requested.
{: .content-table}

For more information about scopes, check [the Java EE 7
documentation](http://docs.oracle.com/javaee/7/tutorial/doc/cdi-basic008.htm#GJBBK)
Expand All @@ -105,9 +109,11 @@
@RequestScoped
public class SessionCreator {

@Inject private SessionFactory sessionFactory;
@Inject
private SessionFactory sessionFactory;

@Produces @RequestScoped
@Produces
@RequestScoped
public Session getSession() {
return sessionFactory.openSession();
}
Expand All @@ -128,7 +134,7 @@
@ApplicationScoped
public class SessionFactoryCreator {

private final SessionFactory factory;
private SessionFactory factory;

@PostConstruct
public void init() {
Expand Down Expand Up @@ -171,12 +177,8 @@
#!java
@Controller
public class CustomerController {
private final CustomerDao dao;

@Inject
public CustomerController(CustomerDao dao) {
this.dao = dao;
}
private final CustomerDao dao;

/**
* @deprecated CDI eyes only
Expand All @@ -185,6 +187,11 @@
this(null);
}

@Inject
public CustomerController(CustomerDao dao) {
this.dao = dao;
}

@Post
public void add(Customer customer) {
this.dao.add(customer);
Expand All @@ -207,6 +214,7 @@
public void observesBootstrap(@Observes VRaptorInitialized event) {
System.out.println("My application is UP");
}
}
~~~

See the <a href="/en/docs/events/">events documentation page</a> for more
Expand Down Expand Up @@ -244,17 +252,17 @@
@Specializes
public class CustomPathResolver extends DefaultPathResolver {

/**
* @deprecated CDI eyes only
*/
protected CustomPathResolver() {
this(null);
}
/**
* @deprecated CDI eyes only
*/
protected CustomPathResolver() {
this(null);
}

@Inject
public CustomPathResolver(FormatResolver resolver) {
super(resolver);
}
@Inject
public CustomPathResolver(FormatResolver resolver) {
super(resolver);
}

@Override
protected String getPrefix() {
Expand Down
22 changes: 18 additions & 4 deletions vraptor-site/content/en/docs/environment.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,20 @@
#!java
@Controller
public class MyController {

private final Environment environment;

private final MailSender sender;

/**
* @deprecated CDI eyes only
*/
protected MyController(){
this(null, null);
}

@Inject
public MeuController(Environment environment, MailSender sender) {
public MyController(Environment environment, MailSender sender) {
this.environment = environment;
this.sender = sender;
}
Expand Down Expand Up @@ -100,7 +109,9 @@
@Controller
public class MyController {

@Inject @Property("test_email") private String email;
@Inject
@Property("test_email")
private String email;

public void sendMail(String email) {
sender.sendMailTo(email);
Expand All @@ -117,7 +128,9 @@
@Controller
public class MyController {

@Inject @Property private String email;
@Inject
@Property
private String email;

public void sendMail(String email) {
sender.sendMailTo(email);
Expand All @@ -129,6 +142,7 @@

~~~
#!java
@Inject @Property(defaultValue = "config.properties")
@Inject
@Property(defaultValue = "config.properties")
private String fileName;
~~~
15 changes: 7 additions & 8 deletions vraptor-site/content/en/docs/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@

## Events triggered by VRaptor

* `VRaptorInitialized` triggered on application startup, indicating that VRaptor was initialized.
* `RequestStarted` triggered the beginning of each request.
* `RequestSucceeded` fired at the end of the request only if it has been processed without error.
* `ControllerFound` and `ControllerNotFound` will indicate whether the Controller that answer the url was found or not.
* `InterceptorsReady` and `InterceptorsExecuted` indicate when the stack will be executed and after its completion.
* `MethodReady` and `MethodExecuted` when the controller method will run and after its completion.


|VRaptorInitialized | triggered on application startup, indicating that VRaptor was initialized.
|RequestStarted | triggered the beginning of each request.
|RequestSucceeded | fired at the end of the request only if it has been processed without error.
|ControllerFound and ControllerNotFound | will indicate whether the Controller that answer the url was found or not.
|InterceptorsReady and InterceptorsExecuted | indicate when the stack will be executed and after its completion.
|MethodReady and MethodExecuted | when the controller method will run and after its completion.
{: .content-table}

## Observing VRaptor events

Expand Down
16 changes: 12 additions & 4 deletions vraptor-site/content/en/docs/migrating-vraptor3-project.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
#!java
@Controller
public class MyController {

private final MyComponent myComponent;

/** @deprecated CDI eyes only */
/**
* @deprecated CDI eyes only
*/
protected MyComponent() {
this(null);
}
Expand All @@ -47,7 +50,8 @@
@ApplicationScoped
public class PrintLog {

@Inject private Logger logger;
@Inject
private Logger logger;

public void whenApplicationStarts(@Observes VRaptorInitialized initialized) {
logger.info("My application is UP");
Expand Down Expand Up @@ -115,8 +119,12 @@
#!java
public class MyClass {

@Inject private Locale locale;
@Inject private ResourceBundle bundle;
@Inject
private Locale locale;

@Inject
private ResourceBundle bundle;

}
~~~

Expand Down
12 changes: 6 additions & 6 deletions vraptor-site/content/en/docs/one-minute-guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@

private final ClientDao dao;

@Inject
public ClientsController(ClientDao dao){
this.dao = dao;
}

/**
* @deprecated CDI eyes only
*/
public ClientsController(){
protected ClientsController(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think should be public to CDI eyes. Why protected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope. protected is better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really. Sorry. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just need the default constructor, since it isn't private, is it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error:
WELD-001435: Normal scoped bean class ClientsController is not proxyable because it has no no-args constructor - <unknown javax.enterprise.inject.spi.Bean instance>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using injection in the constructor is needed the default constructor to CDI. Just can't be private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, get it wrong your question. That's it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @vitornp. I told just about the private default constructor, just in this case we get error.

Anyway, thanks. 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍻

this(null);
}

@Inject
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, nevermind. My bad, because the example explain how to inject via field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous example is used injection the attribute

Description of this example:
https://github.com/vitornp/vraptor4/blob/docs/vraptor-site/content/en/docs/one-minute-guide.html#L41
(As an alternative, annotate the contructor with @Inject)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

public ClientsController(ClientDao dao){
this.dao = dao;
}

// controller methods
}
~~~
Expand Down
2 changes: 2 additions & 0 deletions vraptor-site/content/en/docs/ten-minute-guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
@Controller
public class ProductsController {

@Inject
private ProductDAO dao;

public List<Product> list() {
Expand Down Expand Up @@ -185,6 +186,7 @@

@Inject
private ProductDAO dao;

@Inject
private Result result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
public class PersonController {

private final Result result;
private final Validator validator;

@Inject
public PersonController(Result result, Validator validator) {
this.result = result;
this.validator = validator;
}
private final Validator validator;

/**
* @deprecated CDI eyes only
*/
protected PersonController() {
this(null, null);
}


@Inject
public PersonController(Result result, Validator validator) {
this.result = result;
this.validator = validator;
}

}
~~~

Expand Down
3 changes: 2 additions & 1 deletion vraptor-site/content/en/docs/validation.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
#!java
public class LoginAvailableValidator implements ConstraintValidator<LoginAvailable, User> {

@Inject private UserDao userDao;
@Inject
private UserDao userDao;

public boolean isValid(User user, ConstraintValidatorContext context) {
return !userDao.containsUserWithLogin(user.getLogin());
Expand Down
Loading