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

Initial support new messages grouped by severity #736

Merged
merged 9 commits into from
Aug 13, 2014

Conversation

garcia-jj
Copy link
Member

As discussed in dev mailing list many months ago.

At this time we have only errors. These errors is a List of Messages. But some applications needs to messages like warning and info. We have a Severity enum with properties like INFO and WARN, but this messages is not used by VRaptor.

With this pull request we can simple add a Message into Messages managed bean. So in the view we can use someting like this:

<c:forEach items="${messages.errors}" ... />
<c:forEach items="${messages.warn}" ... />

Categorized messages are available too: ${messages.warn.from('client.name')}, and more.

This change has backward compatibility because messages.errors is exported to view with alias errors, that is the same object.

This is an initial suggestion, and we can improve it. After, javadocs and site docs will write.

Thank you.

public List<Message> getErrors() {
return get(Severity.ERROR);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if pluralization of info and warn are right, so I wrote in singular. Suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm not wrong, info can be used in singular and plural...

Copy link
Member

Choose a reason for hiding this comment

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

I'd pluralize all of them

Copy link
Member

Choose a reason for hiding this comment

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

or use errorList, warnList, infoList

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll leave info because as @renanigt said, already in plural. But warn can be renamed to warnings.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer warnings too.

@renanigt
Copy link
Contributor

renanigt commented Aug 8, 2014

Cool ! 👍

@rponte
Copy link
Contributor

rponte commented Aug 8, 2014

This is a good feature!

On Thu, Aug 7, 2014 at 10:41 PM, Renan Montenegro notifications@github.com
wrote:

Cool ! [image: 👍]


Reply to this email directly or view it on GitHub
#736 (comment).

Rafael Ponte
TriadWorks | Formação Java
http://cursos.triadworks.com.br

@RequestScoped
public class Messages {

private Map<Severity, List<Message>> messages = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

you could use a guava Multimap here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer using core Java libraries. But you right, because it's too uggly signature Map<X, List<Y>>. I'll change it soon. Thank you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I'm not able to use ListMultimap because this class creates an ArrayList, but we need to create a MessageList(ArrayList) as you can see here: https://github.com/caelum/vraptor4/pull/736/files#diff-3c30e5f5d8b7bd61d2561087bc62a05fR41

Suggestions?

@garcia-jj
Copy link
Member Author

A method to get all messages can be useful?

public List<Message> getAll() {
    List<Message> all = new ArrayList<>();
    all.addAll(getErrors());
    all.addAll(getInfo());
    all.addAll(getWarnings());
    return all;
}

@renanigt
Copy link
Contributor

renanigt commented Aug 8, 2014

I think can be useful, may be someone wants to get all errors without by Severity.

@renanigt
Copy link
Contributor

renanigt commented Aug 8, 2014

Since now we have info, warnings and errors, what about to create methods, something like onWarnRedirectTo(...), onInfoRedirectTo(...) ?

So, with this we can treat each messages differently...

@renanigt
Copy link
Contributor

renanigt commented Aug 9, 2014

Or we can also create something like:

validator.on(INFO).redirectTo(...)
validator.on(WARN).redirectTo(...)
validator.on(ERROR).redirectTo(...)

@garcia-jj
Copy link
Member Author

Or something like validator.on(Severity.INFO, Severity.ERROR).redirectTo(...). The same for forwardTo, pageOf and badRequest. But we can improve in another pull request, to delivery this pull request as soon as possible.

@Turini
Copy link
Member

Turini commented Aug 11, 2014

@garcia-jj this feature should come in RC2?

A method to get all messages can be useful?

totally

note: this is a really nice PR! Thanks for remember about it :)

@garcia-jj
Copy link
Member Author

@garcia-jj this feature should come in RC2?

I'm not sure. By this feature can wait if necessary.

@garcia-jj
Copy link
Member Author

If I'm not wrong, this pull request blocks #725

@renanigt
Copy link
Contributor

@garcia-jj, in conversation with @lucascs, he asked to wait your merge, because we need this PR to fix the bug.

So, you can merge it for we can fix #725.

@renanigt
Copy link
Contributor

The comment is here.

@garcia-jj
Copy link
Member Author

Regarding method List<Message> getAll() I think in message order. When a Message is added, we store in a map grouped by Severity. So we can't have information about original order. There is a problem to return errors first, info and in the last positions, warn?

@Turini
Copy link
Member

Turini commented Aug 11, 2014

There is a problem to return errors first, info and in the last positions, warn?

the order: errors, info and warns looks fair enough 👍

@rponte
Copy link
Contributor

rponte commented Aug 12, 2014

Hoje about using the same order of Log4j? Errors, warnings and info?

On Monday, August 11, 2014, Rodrigo Turini notifications@github.com wrote:

There is a problem to return errors first, info and in the last positions,
warn?

the order: errors, info and warns looks fair enough [image: 👍]


Reply to this email directly or view it on GitHub
#736 (comment).

Rafael Ponte
TriadWorks | Formação Java
http://cursos.triadworks.com.br

@renanigt
Copy link
Contributor

I agree with @rponte. 👍

@Turini
Copy link
Member

Turini commented Aug 12, 2014

for me, the bullet point is errors being the first one :)

@garcia-jj
Copy link
Member Author

Method added with 398c620

@garcia-jj
Copy link
Member Author

The Messages class is just a pojo. May important to add a unit test class?

@renanigt
Copy link
Contributor

I think isn't too important, but a plus.

@garcia-jj
Copy link
Member Author

@Turini we merge this pull request before new release, or wait for more comments and ideas?

@Turini
Copy link
Member

Turini commented Aug 12, 2014

lets wait for more comments :) before the release we can merge

Turini added a commit that referenced this pull request Aug 13, 2014
Initial support new messages grouped by severity
@Turini Turini merged commit 88a8434 into master Aug 13, 2014
@Turini Turini deleted the ot-messagesbyseverity branch August 13, 2014 14:21
@Turini
Copy link
Member

Turini commented Aug 13, 2014

thanks! As discussed on mail list, it will be available at RC2 version :)

*/
@Named
@RequestScoped
public class Messages {
Copy link
Member

Choose a reason for hiding this comment

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

guys, "messages" is a really generic name, it is causing some problems
at our internal projects (there is a lot of "messages" vars included to JSP)
What about change it to "VRaptorMessages" or something? It'll help a lot

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes total sense. :+1

On Friday, August 15, 2014, Rodrigo Turini notifications@github.com wrote:

In
vraptor-core/src/main/java/br/com/caelum/vraptor/validator/Messages.java:

+/**

  • * Managed class that stores all application messages like errors, warnings and info. This
  • * class is useful to display messages categorized by severity in your view. To choose a severity
  • * you can construct your message like this:
  • *
  • * Message message = new SimpleMessage("name", "An info message", Severity.INFO);
  • * validation.add(message); // will stored as INFO severity
  • *
  • * @SInCE 4.1
  • * @author Otávio S Garcia
  • */
    +@nAmed
    +@RequestScoped
    +public class Messages {

guys, "messages" is a really generic name, it is causing some problems
at our internal projects (there is a lot of "messages" vars included to
JSP)
What about change it to "VRaptorMessages" or something? It'll help a lot


Reply to this email directly or view it on GitHub
https://github.com/caelum/vraptor4/pull/736/files#r16295214.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

It also kind of breaks compatibility (other apps could have a named component with the same name)

Copy link
Member Author

Choose a reason for hiding this comment

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

errors is generic too, and we use since 3.0 version. I vote to leave as messages. Or if more people vote to rename, instead of messages we can export warnings and info, or a better name than vraptorMessages, that is too ugly and we need to use upper/lower case, because is too boring to type in JSP.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then we should also rename warnings and info, too.

In https://github.com/caelum/mamute, for example, we had were including an attribute named "messages" in our views and we broke our app when updated vraptor :-(

I think that this will happen for other users, too.

Copy link
Member

Choose a reason for hiding this comment

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

we need to solve this question before the next release... more people think we should
keep as it is? (only messages). If not, which better name instead of vraptorMessages?

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer VRaptorMessages, but I was out theses days.

Copy link
Member Author

Choose a reason for hiding this comment

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

@renanigt we won't rename the class, but only export to view with another name to avoid conflicts.

@Turini I really dislike using upper/lower in EL. And using framework name in variable is too uggly (my point, of course). May we can use vmessages that sounds something like validation messages and vraptor messages. Or we can improve this case with idea from JSF, that allow devs to configure the name of variable exported. What you think?

Copy link
Member

Choose a reason for hiding this comment

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

vmessages looks good to me :) anyone disagree with it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Now I see the point @garcia-jj. 😃

I agree with @Turini, vmessages looks nice. 👍

@felipeweb
Copy link
Contributor

vmessages nice 👍

@Turini
Copy link
Member

Turini commented Aug 20, 2014

nice, thank for the opinions guys!

* @since 4.1
* @author Otávio S Garcia
*/
@Named
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it be changed to @Named("vmessages")?

Copy link
Contributor

Choose a reason for hiding this comment

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

Was made in another PR: #749

Copy link
Member

Choose a reason for hiding this comment

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

ops

@nykolaslima
Copy link
Contributor

awesome!!!!! 👍 👍 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants