简体   繁体   中英

How to extend a converter in JSF 1.2

I don't like the way f:convertNumber display NaN ( "\�" ) and both of the infinities ( "\∞" ).

Is there a way to extend the out-of-the-box converter in order to inject my own display logic? Thank you.

To do this:

  1. Create a class that extends NumberConverter .
  2. Override the getAsString method by explicitly handling your special values, and deferring to super for all others. Pseudocode:

     getAsString(FacesContext ctx, UIComponent component, Object value) { if (value is NaN) { return your-own-NaN-string; } if (value is infinity) { return your-own-infinity-string; } return super.getAsNumber(ctx, component, value); } 
  3. Register the class as a converter and use it instead of f:convertNumber .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM