Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Illegal Argument in Custom Converter

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm attempting to create a custom converter that limits the amount of text displayed in an output field. I am currently getting an IllegalArgumentException - argument type mismatch, when the page loads which I cannot figure out. I've tried it with the argument as a String, int, and Integer with the same result. Here are the pieces:




<description>Max number of digits displayed before being replaced with ...</description>


package converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

* Will replace characters after MAX_CHARS_DISPLAYED with an elipsis (...)
public class LimitTextDisplayedConverter implements Converter {
public static final String CONVERTER_ID = "limitTextDisplayed";
private static final String CONTINUATION_CHARS = "...";
private String maxCharsDisplayed;

public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
return null;

public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
String displayText = (String)arg2;
Integer maxChars = new Integer(getMaxCharsDisplayed());
if (displayText == null) return displayText;
if (displayText.length() < maxChars) return displayText;

StringBuffer sb = new StringBuffer(maxChars + CONTINUATION_CHARS.length());
int length = displayText.length();
if (length > 0 && length > maxChars)
sb.append(displayText.substring(0, maxChars));
return sb.toString();


public String getMaxCharsDisplayed() {
return this.maxCharsDisplayed;

public void setMaxCharsDisplayed(String maxCharsDisplayed) {
this.maxCharsDisplayed = maxCharsDisplayed;



package converters;

import javax.faces.convert.Converter;
import javax.servlet.jsp.JspException;

import com.sun.faces.taglib.jsf_core.ConverterTag;

public class LimitTextDisplayedConverterTag extends ConverterTag {
private static final long serialVersionUID = -8976816060599681131L;

private String maxCharsDisplayed;

* Default Constructor.
public LimitTextDisplayedConverterTag() {

public void release() {

private void init() {
maxCharsDisplayed = "0";

//METHODS FROM ConverterTag
protected Converter createConverter() throws JspException {
LimitTextDisplayedConverter result = (LimitTextDisplayedConverter) super.createConverter();
assert (null != result);


return result;

public void setMaxCharsDisplayed(String maxCharsDisplayed) {
this.maxCharsDisplayed = maxCharsDisplayed;

public String getMaxCharsDisplayed() {
return maxCharsDisplayed;



<ice:outputText value="#{title}" title="#{title}">
<blima:limitTextDisplayedConverter maxCharsDisplayed="50"/>

Am I missing something? Any help is much appreciated!
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic