2 Replies Latest reply on Sep 5, 2011 11:29 AM by laurentg

    h:outputFormat and f:param with complex value

    laurentg Newbie

      Hello,

       

      I would like format a message with 2 parameters. One of the parameters cannot be given to f:param directly in the value attribute since I need to format it also. See example below :

       

      JSF :

       

      <h:outputFormat value="#{messages['my.message']}">
           <f:param value="#{myBean.stringValue]}" />
           <f:param>
                <h:outputText value="#{myBean.aNumericValue}">
                     <f:convertNumber maxFractionDigits="0" />
                </h:outputText>
           </f:param>
      </h:outputFormat
      

       

      messages.properties :

      my.message=A test message {0} {1}

       

      How can I do this ?

       

      Thanks for your help.

        • 1. Re: h:outputFormat and f:param with complex value
          Sreemanth Pulagam Newbie

          hi  tried to solve this problem,

           

          approach 1

          -----------------

           

          aNumericValueFormatted is a new getter method which will return the formatted value.

           

          <h:outputFormat value="#{messages['my.message']}">
               <f:param value="#{myBean.stringValue]}" />
               <f:param value="#{myBean.aNumericValueFormatted}">
               </f:param>
          </h:outputFormat>
          

           

           

           

          approach 2(This has some issue)

          ----------------

          can you try the following snippet

           

                 

          <h:outputText value="1234.123466666666666" binding="#{requestScope.simple}" rendered="false">
                      <f:convertNumber maxFractionDigits="6" ></f:convertNumber>
                  </h:outputText>
                  <h:outputFormat value="A test message {0} {1}">
                      <f:param value="Simple zero"></f:param>
                      <f:param value="#{requestScope.simple.value}">
                      </f:param>
                  </h:outputFormat>
          
          • 2. Re: h:outputFormat and f:param with complex value
            laurentg Newbie

            Thank you for your suggestions.

            Of course, approach 1 works but I don't like it since I have to modify my model and introduce presentation concerns in Java code.

            Approach 2 doesn't work : the value stores in the binding property is of type "javax.faces.component.html.HtmlOutputText".

             

            Finally, I added a new method in a bean :

             

            public String formatNumber(double number, String format) {

                    final DecimalFormat decimalFormat = new DecimalFormat(format);

                    return decimalFormat.format(number);

                }