You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Mads Riise Rasmussen (JIRA)" <ji...@apache.org> on 2008/12/08 09:47:37 UTC

[jira] Commented: (WW-2744) My custom type converter does not work anymore

    [ https://issues.apache.org/struts/browse/WW-2744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45159#action_45159 ] 

Mads Riise Rasmussen commented on WW-2744:
------------------------------------------

My best guess is 2.0.9 which I used before 2.0.11 ... I've tried in 2.0.12 but with no success. Anyway I found out that if changed the signatures of my converters to the ones in com.opensymphony.xwork2.util.EnumTypeConverter, it worked again. So maybe the Type conversion page in Struts 2 guide needs to be changed.

> My custom type converter does not work anymore
> ----------------------------------------------
>
>                 Key: WW-2744
>                 URL: https://issues.apache.org/struts/browse/WW-2744
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.0.11
>            Reporter: Mads Riise Rasmussen
>             Fix For: 2.1.3
>
>
> My custom type converter does not work anymore. I can see in the log that convertFromString i called but the setter for the corresponding bean property is never called. I have done some different testing and simply cannot get it to work anymore.
> package com.softscan.service.web.converter;
> import java.net.Inet4Address;
> import java.net.InetAddress;
> import java.net.UnknownHostException;
> import java.util.ArrayList;
> import java.util.Iterator;
> import java.util.List;
> import java.util.Map;
> import org.apache.log4j.Logger;
> import org.apache.struts2.util.StrutsTypeConverter;
> import com.opensymphony.xwork2.util.TypeConversionException;
> public class Inet4AddressConverter extends StrutsTypeConverter {
> 	@SuppressWarnings("unused")
> 	private static final Logger log = Logger.getLogger(Inet4AddressConverter.class);
> 	
> 	@SuppressWarnings("unchecked")
> 	@Override
> 	public Object convertFromString(Map context, String[] values, Class toClass) throws TypeConversionException {
> 		List<InetAddress> result = new ArrayList<InetAddress>();
>         for (int i = 0; i < values.length; i++) {
>         	try {
> 				log.debug("# Inet4Address: " + Inet4Address.getByName(values[i]));
>         		result.add(Inet4Address.getByName(values[i]));
> 			} catch (UnknownHostException e) {
> 				throw new TypeConversionException("Unknown host");
> 			}
>         }
>         return result;
> 	}
> 	@SuppressWarnings("unchecked")
> 	@Override
> 	public String convertToString(Map context, Object o) {
> 		List l = (List)o;
>         String result = "<";
>         for (Iterator i = l.iterator(); i.hasNext(); ) {
>             result = result + "[" + i.next() + "]";
>         }
>         result = result + ">";
>         return result;
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.