6 Replies Latest reply on Oct 15, 2010 10:51 AM by bussard

    Need Solution

      Hi,,


                   i need to convert the number as formatted one,.,for ex,
      10000 as 10,000.00...I converted this using




      <f:converNumber pattern="##,##0.00">




      .Now i'm getting an error as argument mismatch

        • 1. Re: Need Solution

          hi, please paste the whole block of your field and the full error stacktrace.


          Here I provide you with an example that may help you:


                              <s:decorate id="c12" template="layout/edit.xhtml">
                                   <ui:define name="label">#{messages['yourfield']}</ui:define>
                                   <h:inputText id="fiq" value="#{order.asset.fiq}" required="true"
                                        label="#{messages['yourfield']}">
                                        <f:convertNumber pattern='#,##0.0000000' />
                              
                                   </h:inputText>
                              </s:decorate>
          






          • 2. Re: Need Solution


                        <s:decorate id="minAmountField" template="../layout/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.MinAmount}"/></ui:define>
                            <h:inputText id="minAmount"
                                      value="#{sysprcomponentsmstHome.instance.minAmount}"
                                       size="17">
                                <a:support event="onblur" reRender="minAmountField" bypassUpdates="true" ajaxSingle="true"/>
                                <f:convertNumber pattern="#,##,##,##,##0.00" type="currency"/>
                            </h:inputText>
                        </s:decorate>
            



            Here My code is like above...


            When the textbox lost the focus at that time the value changed to 10000 to 10,000.00....


            I'm getting error when i saving that....I got an exception like this....



            /admin/SysprcomponentsmstEdit.xhtml @226,38 value="#{sysprcomponentsmstHome.instance.minAmount}": java.lang.IllegalArgumentException: argument type mismatch  
            
            





            • 3. Re: Need Solution

              Hi,
              What kind of type is sysprcomponentsmstHome.instance.minAmount?
              do you need currency type compulsory?
              Probably you need to use type number instead of currency
              I mean:


              <f:convertNumber pattern="#,##,##,##,##0.00" type="number"/>
              


              or in the java class change the type of minAmount to something that conforms the data.
              Maybe you´ve defined a int or Integer and you need a Long.



              • 4. Re: Need Solution
                niox.nikospara.yahoo.com

                Something similar had happened to me once: There was a Double property, say #{sysprcomponentsmstHome.instance.minAmount}, that was handled by a converter. When I entered an integral value the converter transformed it to Long. Checking with the spec, it does indeed comply (see java.text.NumberFormat.parse() in the Javadocs).


                This simple class solved the problem, as described in the Javadocs:


                package xxx.web.util;
                
                import javax.faces.component.UIComponent;
                import javax.faces.context.FacesContext;
                import javax.faces.convert.NumberConverter;
                
                /**
                 * Bypass an (inconvenience? bug?) of JSF regarding parametric
                 * number conversion.
                 * <p>
                 * When using {@code <f:numberConverter>} the returned, parsed
                 * value is either {@code Double} or {@code Long}, accoring to rules in
                 * {@code java.text.NumberFormat}. Therefore when using this converter
                 * tag for a {@code Double} field and we specify e.g. {@code 123,00},
                 * the value is converted to {@code Long}, resulting in an
                 * {@code IllegalArgumentException}.
                 * <p>
                 * This class makes sure that
                 * {@link #getAsObject(FacesContext, UIComponent, String)}
                 * allways returns {@code Double}.
                 * To install it in the JSF runtime you have to add the following in
                 * {@code faces-config.xml}:<br/>
                 * <code><pre>
                 * &lt;converter>
                 *   &lt;converter-id><b>javax.faces.Number</b>&lt;/converter-id>
                 *   &lt;converter-class><b>xxx.web.util.AllwaysDoubleNumberConverter</b>&lt;/converter-class>
                 * &lt;/converter>
                 * </pre></code>
                 * 
                 * @author npara
                 */
                public class AllwaysDoubleNumberConverter extends NumberConverter
                {
                     @Override
                     public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
                          Object ret = super.getAsObject(arg0, arg1, arg2);
                          if( ret instanceof Long ) ret = new Double(((Long) ret).doubleValue());
                          return ret;
                     }
                }
                

                • 5. Re: Need Solution

                  I agree with you, sometimes a converter is needed.
                  Seetha, in that case don´t forget to define it in your faces-config.xml and to include it in your block, for instance



                  <h:inputText id="minAmount"
                                            value="#{sysprcomponentsmstHome.instance.minAmount}"
                                             size="17">
                                      <a:support event="onblur" reRender="minAmountField" bypassUpdates="true" ajaxSingle="true"/>
                                      <f:convertNumber pattern="#,##,##,##,##0.00" type="currency"/>
                  <f:converter converterId="yourConverter" />
                                  </h:inputText>
                  




                  • 6. Re: Need Solution
                    bussard

                    I'm trying to use your solution but I'm a newbe in jsf converters and I cant find javax.faces. in my Jboss Tools generated project, so I tried org.jboss.seam.faces. but it hasn,t the NumberConverter classs.


                    Do you have any tip to guide me ?


                    P.S.: I'm using Seam 2.2.1.CR2