Return-Path: X-Original-To: apmail-struts-issues-archive@minotaur.apache.org Delivered-To: apmail-struts-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 891CCEE19 for ; Mon, 4 Feb 2013 14:00:15 +0000 (UTC) Received: (qmail 3352 invoked by uid 500); 4 Feb 2013 14:00:15 -0000 Delivered-To: apmail-struts-issues-archive@struts.apache.org Received: (qmail 3274 invoked by uid 500); 4 Feb 2013 14:00:15 -0000 Mailing-List: contact issues-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list issues@struts.apache.org Received: (qmail 3263 invoked by uid 99); 4 Feb 2013 14:00:14 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Feb 2013 14:00:14 +0000 Date: Mon, 4 Feb 2013 14:00:14 +0000 (UTC) From: "Lukasz Lenart (JIRA)" To: issues@struts.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (WW-3936) Custom Struts2 type converter is only called in one direction MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/WW-3936?page=3Dcom.atlassian.j= ira.plugin.system.issuetabpanels:all-tabpanel ] Lukasz Lenart updated WW-3936: ------------------------------ Fix Version/s: (was: 2.3.x) 2.3.10 =20 > Custom Struts2 type converter is only called in one direction > ------------------------------------------------------------- > > Key: WW-3936 > URL: https://issues.apache.org/jira/browse/WW-3936 > Project: Struts 2 > Issue Type: Bug > Components: Core Actions > Affects Versions: 2.3.4.1 > Environment: JDK 1.7, Tomcat 7.0.26 > Reporter: Sebastian G=C3=B6tz > Fix For: 2.3.10 > > > We have a custom converter implemented that should convert select items f= rom and to id. Now it seems that only when submitting the form the convertF= romString method gets called. Upon rendering the page the convertToString g= ets never called. So while we can submit values to the model the initial se= lection of the select list is wrong. After some googling I found a work aro= und by overriding the toString() method to return the id to make it work. B= ut this is not an option in other cases where we face the same problems. > More strange is, that if I render the same into a textfield tag, the conv= erter is triggered in both directions. > {code:title=3DThemeDscriptor.java} > public class ThemeDescriptor implements Serializable, Cloneable, Comparab= le > { > =09private final String id; > =09private final String displayName; > =09private final File directory; > =09private final String contextPath; > =09public ThemeDescriptor(final String p_id, final String p_displayName, = final File p_directory, final String p_contextPath) > =09{ > =09=09id =3D p_id; > =09=09displayName =3D p_displayName; > =09=09directory =3D p_directory; > =09=09contextPath =3D p_contextPath; > =09} > =09public String getId() > =09{ > =09=09return id; > =09} > =09public String getDisplayName() > =09{ > =09=09return displayName; > =09} > =09public File getDirectory() > =09{ > =09=09return directory; > =09} > =09public String getContextPath() > =09{ > =09=09return contextPath; > =09} > } > {code} > {code:title=3DThemeDescriptorConverter.java} > package eu.inform.integration.converter; > import java.util.Map; > import org.apache.log4j.LogMF; > import org.apache.log4j.Logger; > import com.opensymphony.xwork2.conversion.TypeConversionException; > import eu.inform.presentation.ThemeDescriptor; > import eu.inform.presentation.UIConstants; > public class ThemeDescriptorConverter extends AbstractBaseConverter > { > =09private final static Logger log =3D Logger.getLogger(ThemeDescriptorCo= nverter.class); > =09@SuppressWarnings("rawtypes") > =09@Override > =09public Object convertFromString(final Map p_context, final String[] p_= values, final Class p_toClass) > =09{ > =09=09if ((p_values !=3D null) && (p_values.length > 0)) > =09=09{ > =09=09=09try > =09=09=09{ > =09=09=09=09Map themes =3D UIConstants.getThemes= (); > =09=09=09=09if (themes.containsKey(p_values[0])) > =09=09=09=09{ > =09=09=09=09=09return themes.get(p_values[0]); > =09=09=09=09} > =09=09=09=09throw new RuntimeException("No theme with id: " + p_values[0]= ); > =09=09=09} > =09=09=09catch (Exception e) > =09=09=09{ > =09=09=09=09LogMF.error(log, e, "Unable to convert {0} into a ThemeDescri= ptor", new Object[] { p_values[0] }); > =09=09=09=09throw new TypeConversionException("Unable to convert into a T= hemeDescriptor: " + p_values[0], e); > =09=09=09} > =09=09} > =09=09return null; > =09} > =09@SuppressWarnings("rawtypes") > =09@Override > =09public String convertToString(final Map p_context, final Object p_o) > =09{ > =09=09try > =09=09{ > =09=09=09return ((ThemeDescriptor) p_o).getId(); > =09=09} > =09=09catch (Exception e) > =09=09{ > =09=09=09LogMF.error(log, e, "Unable to convert {0} into a string", new O= bject[] { p_o }); > =09=09} > =09=09return null; > =09} > } > {code} > {code:xml|title=3DJSP} > >
> =09 > =09=09 > =09=09=09 > =09=09=09 > =09=09=09 > =09=09 > =09
> =09
>
> {code} > {code:xml|title=3Dxwork-conversion.properties} > eu.inform.presentation.ThemeDescriptor=3Deu.inform.integration.converter.= ThemeDescriptorConverter > {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrato= rs For more information on JIRA, see: http://www.atlassian.com/software/jira