[seam-issues] [JBoss JIRA] (SEAMINTL-70) Document usage of BundleTemplateMessage/TemplateMessage

Gerald Turner (JIRA) jira-events at lists.jboss.org
Thu Mar 1 18:41:39 EST 2012

    [ https://issues.jboss.org/browse/SEAMINTL-70?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12672962#comment-12672962 ] 

Gerald Turner commented on SEAMINTL-70:

I apologize about my bad attempt to use the Messages bean, I understand Seam3 and CDI a lot better now than I did months ago.  This bug still holds true that there should be better documentation.

My understanding is that Messages should work like the following:

  private Messages m;

  public void doSomething() {
    // Messages with severity and fixed summary
    m.info("Info message");
    m.warn("Warning message!");

    // Interpolated summary
    m.error("There is an error with {0}", foo);

    // Summary and detail
    m.info("Info").detail("Process complete");

    // Interpolated summary and detail
    m.info("Stored {0}", foo)
     .detail("{0} has been stored to the database")

...none of this nonsense I had originally posted about injecting a TemplateMessage.

There are a few caveats (bugs?) which sent me down the wrong path:

  1. Interpolation is homebrew and doesn't work like java.text.MessageFormat (formatting not supported, e.g. "{1,time}", and no brace escape with archaic apostrophe problem, e.g. "array='{'{2}'}'").

  2. org.jboss.seam.faces.status.MessagesAdapter explicitly ignores the detail message (overriding with null), making some of my use cases not work with JSF, code:

  void convert(@Observes @Before @RenderResponse final PhaseEvent event, Messages messages) {
    Set<Message> savedMessages = (Set<Message>) context.get(FLASH_MESSAGES_KEY);
    if (savedMessages != null) {
      for (Message m : savedMessages) {
         new FacesMessage(getSeverity(m.getLevel()), m.getText(), null));

  ... note that null at the end!

FYI I'm using Seam 3.1.0.Final now.

> Document usage of BundleTemplateMessage/TemplateMessage
> -------------------------------------------------------
>                 Key: SEAMINTL-70
>                 URL: https://issues.jboss.org/browse/SEAMINTL-70
>             Project: Seam International
>          Issue Type: Feature Request
>          Components: Messages
>    Affects Versions: 3.1.0.Beta3
>            Reporter: Gerald Turner
>            Assignee: Ken Finnigan
>            Priority: Optional
>             Fix For: 3.1.1.Beta1
>   Original Estimate: 3 hours
>  Remaining Estimate: 3 hours
> As a user, the current documentation is sufficient for severity+text messages, however on closer inspection of the Message class, I see that detail and targets properties are available, much like FacesMessage.
> I dug around the seam-international source and experimented with a bean having fields/method like the following:
>   @Inject
>   private Messages messages;
>   @Inject
>   private transient TemplateMessage message;
>   public void doSometing() {
>     messages.add(message.level(Level.WARN).text("Text {0}, {1}, {2}").textParams('a', 'b', 'c').detail("Detail {0}, {1}, {2}").detailParams(1, 2, 3).targets("message").build());
>     messages.add(message.level(Level.FATAL).text("Fatality!").targets("message").build());
>   }
> This works.  A few caveats:
> * TemplateMessage field has to be marked transient, otherwise get WELD error during deployment about Serializable bean having non-Serializable field.
> * Make sure to call add(Message) signature (invoke build()) instead of add(MessageBuilder), otherwise only the most recent message is added.
> * doSomething method is not reentrant/thread-safe because of the builder.
> I'd prefer to use Messages instead of the builders, perhaps have a methods like info(String text, String details, String targets, Object... args), however that gets ugly with the varargs, having to cast Object[], etc.  Perhaps I should stick with FacesMessages.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the seam-issues mailing list