You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2002/11/01 16:55:52 UTC

DO NOT REPLY [Bug 14150] - Allow to use any subclass of java.text.Format

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14150>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14150

Allow <bean:write/> to use any subclass of java.text.Format





------- Additional Comments From sandymac@ufl.edu  2002-11-01 15:55 -------
Below is code that I think gets real close to how to implement my RFE, I've
never used reflection like this before so give it a once over. I've chanaged the
attribute formatter to formatClass as that seems more consistant and added
formatClassKey attribute. The code below goes near the top of
formatValue(Object) in org.apache.struts.taglib.bean.WriteTag. Some bean
getter/setters and the taglib defination would need to be added too.

        if (formatClass != null) {
            try {
                Class clazz;
                Constructor clazzConstructor;
                Class[] paramTypes;
                Object[] params;
                
                // Try to retrieve format string from resources by the key from
formatKey.
                if( ( formatClass==null ) && ( formatClassKey!=null ) ) {
                    formatClass = retrieveFormatString( this.formatClassKey );
                    if( formatClass!=null )
                        formatClassFromResources = true;
                }
                // Try to retrieve format string from resources by the key from
formatKey.
                if( ( formatString==null ) && ( formatKey!=null ) ) {
                    formatString = retrieveFormatString( this.formatKey );
                    if( formatString!=null )
                        formatStrFromResources = true;
                }
                
                clazz = Class.forName(formatClass);
                
                if (formatString == null) {
                    paramTypes = new Class[0];
                    params = new Object[0];
                } else {
                    paramTypes = new Class[2];
                    paramTypes[0] = String.class;
                    paramTypes[1] = Locale.class;
                    
                    params = new Object[2];
                    params[0] = formatString;
                    params[1] = locale;
                }
                
                clazzConstructor = clazz.getConstructor(paramTypes);
                format = (Format)clazzConstructor.newInstance(params);
            } catch (Exception e) {
                // TODO: What message should this be
                JspException jE = new
JspException(messages.getMessage("write.format", formatString), e);
                RequestUtils.saveException(pageContext, jE);
                throw jE;
            }
        } else {
            // Return String object as is.
// [...snip...]
        }
        if( format!=null )
            return format.format( value );
        else
            return value.toString();

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>