|
Struts example source code file (AddressTypeConverter.java)
The Struts AddressTypeConverter.java source codepackage com.opensymphony.xwork2.test.annotations; import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter; import java.util.Map; public class AddressTypeConverter extends DefaultTypeConverter { @Override public Object convertValue(Map<String, Object> context, Object value, Class toType) { if(value instanceof String) { return decodeAddress((String)value); } else if(value instanceof String && value.getClass().isArray()) { return decodeAddress(((String[])value)[0]); } else { Address address = (Address)value; return address.getLine1() + ":" + address.getLine2() + ":" + address.getCity() + ":" + address.getCountry(); } } private Address decodeAddress(String encodedAddress) { String[] parts = ((String)encodedAddress).split(":"); Address address = new Address(); address.setLine1(parts[0]); address.setLine2(parts[1]); address.setCity(parts[2]); address.setCountry(parts[3]); return address; } } Other Struts examples (source code examples)Here is a short list of links related to this Struts AddressTypeConverter.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.