Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.2
    • Component/s: Facelets/VDL
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      895

      Description

      FacesMessages do have a specific severity.
      However, those messages are currently only designed for
      failures or general notices. There's currently no way
      to specify a severity for "SUCCESS" events, but programmers are facing that
      problem every day and miss-use INFO or other severities for such a purpose.

      I propose adding a new severity "SUCCESS" that will be accessible
      through
      FacesMessage.SEVERITY_SUCCESS.
      Also adding required attributes to h:messages and h:message:
      successClass, successStyle.

        Activity

        Hide
        Ed Burns added a comment -

        I like this idea. If you could submit a patch, that would make it easier to get
        it into 2.2

        Show
        Ed Burns added a comment - I like this idea. If you could submit a patch, that would make it easier to get it into 2.2
        Hide
        Manfred Riem added a comment -

        Closing resolved issue out

        Show
        Manfred Riem added a comment - Closing resolved issue out
        Hide
        frederickkaempfer added a comment -

        Would be possible to reopen the issue? This has not yet been added to JSF. I think adding a SUCCESS severity would improve the overall usability of FacesMessage, because modern CSS frameworks like Bootstrap provide styling for it. It's probably easy to add, so if it helps I could write a patch for it.

        Thanks!

        Show
        frederickkaempfer added a comment - Would be possible to reopen the issue? This has not yet been added to JSF. I think adding a SUCCESS severity would improve the overall usability of FacesMessage, because modern CSS frameworks like Bootstrap provide styling for it. It's probably easy to add, so if it helps I could write a patch for it. Thanks!
        Hide
        muellermi added a comment -

        Just for my understanding:

        When should this message be displayed?
        The existing h:message will be displayed, when an exception is thrown. I assume, you'd like to display a success message, if no exception is thrown? How shall this be triggered? Where shall the message originate from?

        Or would you like to throw a FacesException to signal success?

        Or could it be better to define a different tag, e.g.

                        <h:inputText id="param1" value="#{bean.param1}"/>
                        <h:message for="param1" errorClass="error"/>
                        <h:successMessage for="param1" value="ok"/>
        

        successMessage will be displayed if no param1 got a value and no message is triggered by an exception.

        Show
        muellermi added a comment - Just for my understanding: When should this message be displayed? The existing h:message will be displayed, when an exception is thrown. I assume, you'd like to display a success message, if no exception is thrown? How shall this be triggered? Where shall the message originate from? Or would you like to throw a FacesException to signal success? Or could it be better to define a different tag, e.g. <h:inputText id= "param1" value= "#{bean.param1}" /> <h:message for = "param1" errorClass= "error" /> <h:successMessage for = "param1" value= "ok" /> successMessage will be displayed if no param1 got a value and no message is triggered by an exception.
        Hide
        muellermi added a comment -

        oops, typo:

        ... if param1 got a value ...

        Show
        muellermi added a comment - oops, typo: ... if param1 got a value ...
        Hide
        frederickkaempfer added a comment -

        Let me give an example that hopefully illustrates the difference between INFO and SUCCESS:

        Let's say you have a simple payment form with bootstrap styled messages

        <h:form id="paymentForm">
        
           <h:messages errorClass="alert alert-danger" successClass="alert alert-success" infoClass="alert alert-info"/>
        
           Amount: <h:inputText value="#{paymentBean.amount}"/>
        
           <h:commandButton value="Pay" action="#{paymentBean.pay()}"/>
        
        </h:form>
        

        And then in PaymentBean a method:

        public void pay(){
           try{
              paymentService.doPayment();
        
              // add a success message
              FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_SUCCESS, "Payment successful.", null));
        
              // and another info message
              FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Your remaining balance is: " + getBalance(), null));
        
           }catch(PaymentException e){
              // add an error message
              FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Payment could not be completed due to an error", null));
           }
        }
        

        When styled with bootstrap for example the success message would appear in green, the info message in blue and the error message in red.

        So the change would not require adding a new tag like h:successMessage, only an addition to the h:message(s) tags (successStyle and successClass) and adding a new Severity instance to the FacesMessage class.

        Show
        frederickkaempfer added a comment - Let me give an example that hopefully illustrates the difference between INFO and SUCCESS: Let's say you have a simple payment form with bootstrap styled messages <h:form id= "paymentForm" > <h:messages errorClass= "alert alert-danger" successClass= "alert alert-success" infoClass= "alert alert-info" /> Amount: <h:inputText value= "#{paymentBean.amount}" /> <h:commandButton value= "Pay" action= "#{paymentBean.pay()}" /> </h:form> And then in PaymentBean a method: public void pay(){ try { paymentService.doPayment(); // add a success message FacesContext.getCurrentInstance().addMessage( null , new FacesMessage(FacesMessage.SEVERITY_SUCCESS, "Payment successful." , null )); // and another info message FacesContext.getCurrentInstance().addMessage( null , new FacesMessage(FacesMessage.SEVERITY_INFO, "Your remaining balance is: " + getBalance(), null )); } catch (PaymentException e){ // add an error message FacesContext.getCurrentInstance().addMessage( null , new FacesMessage(FacesMessage.SEVERITY_ERROR, "Payment could not be completed due to an error" , null )); } } When styled with bootstrap for example the success message would appear in green, the info message in blue and the error message in red. So the change would not require adding a new tag like h:successMessage, only an addition to the h:message(s) tags (successStyle and successClass) and adding a new Severity instance to the FacesMessage class.
        Hide
        muellermi added a comment -

        Yep, understood. Thanks for clarification.
        This seems to be easy to implement if accepted.

        Show
        muellermi added a comment - Yep, understood. Thanks for clarification. This seems to be easy to implement if accepted.
        Hide
        frederickkaempfer added a comment -

        Okay, let me know if there's anything I can do to help getting this issue accepted (provide a patch etc.).

        Show
        frederickkaempfer added a comment - Okay, let me know if there's anything I can do to help getting this issue accepted (provide a patch etc.).

          People

          • Assignee:
            Ed Burns
            Reporter:
            domdorn
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: