I have written a custom taglib to extend the converters already utilized in JSF. The page is rendered, but with out the desired conversion. Debugging results in the invocation of the class, but the getAsString() or getAsObject methods do not get called. Can someone tell me what I am missing? The objective is to read a long from a database, convert it to hex and display. No exceptions are thrown, the debugger just hits the class declaration and returns.
// class ------------------------------------------------------------- HTMLColor // ----------------------------------------------------------------------------- class HTMLColor implements Serializable { private String asColor = new String(); private String original = new String();
// ================================================================ toString() public String toString() { return asColor; }
// ============================================================= setOriginal() public void setOriginal( String ocolor ) { original = ocolor; } // method
// ============================================================= setHexColor() public void setHexColor( String longStr ) { String result = new String(); int color = Integer.parseInt(longStr); result = Integer.toHexString( color ); asColor = padColor( result ); } // method
// ================================================================ padColor() // pad value with zeros is cases where string length less than 6 private String padColor( String result ) { String padded = new String(); switch (result.length()) { case 1: padded = "00000"+result; break; case 2: padded = "0000"+result; break; case 3: padded = "000"+result; break; case 4: padded = "00"+result; break; case 5: padded = "0"+result; break; case 6: padded = result; break; default: return "not web color"; } return padded; } // method
Let me re-post your code with the correct CODE tags so that the indentation stays. The CODE tags get created when you click the CODE button below the Add Reply button when posting to a thread
Here's my answer for extending a converter in JSF. An additional tld is not required. Don't let the fact that your using a sun dataProvider to populate a table with strings from objects create confusion. Just implement the converter in appropriate components in your jsp. - Lou Caudell