Martin, thanks a lot for the great code - you're right, mixing logic and presentation isn't the ideal way.
Wolfgang >>> [EMAIL PROTECTED] 2004-03-24 08:34:07 >>> Hey Wolfgang, How do you represent an IP address as a long? Do you make 192.168.0.12 192168000012? In that case, if you don't mind the zeroes, you could still use formatNumber and use . as the grouping operator. I admit it's ugly, but you'd get 192.168.000.012. As said, ugly. There is an alternative and that is creating your own custom tag. This kind of logic is very definitely presentational logic and personally I think it doesn't really belong in a servlet. Here's what you might do: <[EMAIL PROTECTED] prefix="wolf" uri="http://DOMAIN/taglibs/wolf"%> <c:forEach var="myVar" ..> <wolf:ip value="${myVar}" /> </c:forEach> The wolf:ip tag would be created: *** LongToIPTag.java: *** import java.io.IOException; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.TagSupport; public class LongToIPTag extends TagSupport { private String unformatted; public void setValue(String string) { unformatted = string; } public void release() { unformatted = null; } public int doStartTag() throws JspException { //Do your formatting on the unformatted var here try { pageContext.getOut().print("The formatted string"); } catch(IOException e) { throw new JspException(e); } return SKIP_BODY; } } *** / LongToIPTag.java *** *** WEB-INF/tld/wolf.tld *** <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> <taglib> <tlibversion>1.0</tlibversion> <jspversion>1.1</jspversion> <shortname>wolf</shortname> <uri>http://DOMAIN/taglibs/wolf</uri> <tag> <name>ip</name> <tagclass>LongToIPTag</tagclass> <bodycontent>empty</bodycontent> <attribute> <name>value</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib> *** / WEB-INF/tld/wolf.tld *** *** WEB-INF/web.xml *** <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app> <taglib> <taglib-uri>http://DOMAIN/taglibs/wolf</taglib-uri> <taglib-location>/WEB-INF/tld/wolf.tld</taglib-location> </taglib> </web-app> *** / WEB-INF/web.xml *** Good luck! Martin --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
