MyFaces Core
  1. MyFaces Core
  2. MYFACES-2857

Its not possible to change the summary/ detail message of a ParametrizableFacesMessage

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.8
    • Fix Version/s: 1.1.9, 1.2.10, 2.0.4
    • Component/s: General
    • Labels:
      None

      Description

      We are using a PhaseListener in the render response phase to change the summary message of a FacesMessage

      public void beforePhase(PhaseEvent phaseEvent) {
         ...
        Iterator componentMessages = facesContext.getMessages(clientId);
      
         while (componentMessages.hasNext()) {
           FacesMessage message = (FacesMessage)componentMessages.next();
           StringBuilder builder = new StringBuilder();
           builder.append(label);
           builder.append(message.getSummary());
           message.setSummary(builder.toString());
        }
      }
      

      The problem is that since MyFaces 1.1.8 a ParametrizableFacesMessage is used for required messages. While doing a getSummary() the _evaluatedSummary is evaluated once, so effectively you can not change the _evaluatedSummary after one call to getSummary().

      My questions:
      1. Is this desired behaviour?
      2. In MyFaces 1.1.7 a FacesMessage was used instead of a ParametrizableFacesMessage, is there a configurable way to runtime use a FacesMessage instead of a ParametrizableFacesMessage?
      3. I suppose another workaround would be to add a label argument to each component which will be evaluated by the ParametrizableFacesMessage, is there any documentation how this functionality is intended to work?

        Issue Links

          Activity

          Hide
          Leonardo Uribe added a comment -

          1. Is this a desired behavior?

          Ans: I checked it and it is a bug. Since FacesMessage provide setDetail and setSummary methods, it should be possible to change the summary and detail.

          2. In MyFaces 1.1.7 a FacesMessage was used instead of a ParametrizableFacesMessage, is there a configurable way to runtime use a FacesMessage instead of a ParametrizableFacesMessage?

          Ans: Maybe the best we can do is provide some public methods to manipulate the params that were used to construct ParametrizableFacesMessage. The tricky part is this class is spread everywhere, from myfaces core, shared, commons and tomahawk, so it is necessary to unify it in all possible places. In that way, it should be possible to call those methods using reflection or if there is access to the one in shared, cast and call them.

          3. I suppose another workaround would be to add a label argument to each component which will be evaluated by the ParametrizableFacesMessage, is there any documentation how this functionality is intended to work?

          Ans: See JSF spec (1.2 or 2.0) section 2.5.2.4. The problem is the label is added as a param but the order is not always the same.

          To solve the problem described, it is necessary to override setSummary() and setDetail() to reset the evaluated summary and detail one and add two methods getUnformattedSummary() and getUnformattedDetail(). It is not necessary to reset evaluatedArgs array, because the change that needs to be supported is on summary and detail message. In this way it is possible to provide an alternate summary and detail that could use the original parameters. I think this is the most consistent behavior.

          Show
          Leonardo Uribe added a comment - 1. Is this a desired behavior? Ans: I checked it and it is a bug. Since FacesMessage provide setDetail and setSummary methods, it should be possible to change the summary and detail. 2. In MyFaces 1.1.7 a FacesMessage was used instead of a ParametrizableFacesMessage, is there a configurable way to runtime use a FacesMessage instead of a ParametrizableFacesMessage? Ans: Maybe the best we can do is provide some public methods to manipulate the params that were used to construct ParametrizableFacesMessage. The tricky part is this class is spread everywhere, from myfaces core, shared, commons and tomahawk, so it is necessary to unify it in all possible places. In that way, it should be possible to call those methods using reflection or if there is access to the one in shared, cast and call them. 3. I suppose another workaround would be to add a label argument to each component which will be evaluated by the ParametrizableFacesMessage, is there any documentation how this functionality is intended to work? Ans: See JSF spec (1.2 or 2.0) section 2.5.2.4. The problem is the label is added as a param but the order is not always the same. To solve the problem described, it is necessary to override setSummary() and setDetail() to reset the evaluated summary and detail one and add two methods getUnformattedSummary() and getUnformattedDetail(). It is not necessary to reset evaluatedArgs array, because the change that needs to be supported is on summary and detail message. In this way it is possible to provide an alternate summary and detail that could use the original parameters. I think this is the most consistent behavior.

            People

            • Assignee:
              Leonardo Uribe
              Reporter:
              Jerry Meurs
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development