Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 12053 invoked from network); 12 Mar 2009 14:26:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Mar 2009 14:26:12 -0000 Received: (qmail 19251 invoked by uid 500); 12 Mar 2009 14:26:08 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 18715 invoked by uid 500); 12 Mar 2009 14:26:07 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 18704 invoked by uid 99); 12 Mar 2009 14:26:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Mar 2009 07:26:07 -0700 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of paul.hussein@gmail.com designates 209.85.220.176 as permitted sender) Received: from [209.85.220.176] (HELO mail-fx0-f176.google.com) (209.85.220.176) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Mar 2009 14:25:58 +0000 Received: by fxm24 with SMTP id 24so436299fxm.42 for ; Thu, 12 Mar 2009 07:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:reply-to:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=47Vng3smBYdjvdVQYfwc8muslumCUfrjeYTdKo/mZlk=; b=Cjm1uvPBfcRNKBQFFMLmH83B7KiReMWHb7XYkcSW91JyFYfP+cF3jIqCyUozunJxkq IZKOM80tpTDe/X1GctWww0z9GefazuGGpbK9Pr3oIB4LneExGdFCP2noI4QUlH7snYj9 cU4x5RyFxR/lTpDgK1cpEcb2uhNuOqSW1CGv8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:content-type; b=OdT+V9khwBqwAr6jq8oXhsv8zEvxcf46KRO+nSKgXKVr0AYIP3tzkQsLRRhTfwP4nt h12HfwAT3WCxZP2MP2oPnt5Ra0cf15sGtfi3SENACABojrMQGzVqQjjXzMwknwvXtyfM hfcvSsV8k/CKA/AOd0ikX1DXOvi8v3hhI6eWs= MIME-Version: 1.0 Received: by 10.223.103.207 with SMTP id l15mr43126fao.2.1236867938086; Thu, 12 Mar 2009 07:25:38 -0700 (PDT) Reply-To: paul.hussein@hapnin.net In-Reply-To: <5f528cf40903110506t77e15ec7g3501b83a0283eb0b@mail.gmail.com> References: <396e4a880903101017k1d6a6b30w6e11790b95325f10@mail.gmail.com> <5f528cf40903110506t77e15ec7g3501b83a0283eb0b@mail.gmail.com> Date: Thu, 12 Mar 2009 15:25:38 +0100 Message-ID: <396e4a880903120725m24b01f48o8d97510239ae2886@mail.gmail.com> Subject: Re: BEAN UTILS : dealing with enumerations From: Paul Hussein To: Commons Users List Content-Type: multipart/alternative; boundary=001636c5b3ff156ed30464ecc270 X-Virus-Checked: Checked by ClamAV on apache.org --001636c5b3ff156ed30464ecc270 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Yes, but I dont have a handle to the type, I just have the string. I want beanutils to do the Type.valueOf("One") Thanks Paul. On Wed, Mar 11, 2009 at 1:06 PM, Andrew Hughes wrote: > Off the top of my head... couldn't you do something like... > > Type.valueOf("One") > > Hence do the following in your example from below... > > BeanUtils.setProperty(bean, "type", Type.valueOf("One") ); > > On Wed, Mar 11, 2009 at 3:47 AM, Paul Hussein >wrote: > > > Hi, > > > > I have a bean with an internal Enum > > > > > > public class NewEntity implements Serializable { > > > > private static final long serialVersionUID = 1L; > > public enum Type { One, Two, Three } > > > > private Type type; > > > > public Type getType() { > > return type; > > } > > > > public void setType(Type type) { > > this.type = type; > > } > > > > > > In my application I have a handle to the bean, and the method name and > > value > > as strings > > > > > > e.g. > > > > Object bean = new NewEntity(); > > String name = "type"; > > String value = "One"; > > > > > > when I call setProperty > > > > BeanUtils.setProperty(bean, "type", "One" ); > > > > I get : > > > > Exception in thread "main" java.lang.IllegalArgumentException: Cannot > > invoke > > javaapplication1.NewEntity.setType on bean class 'class > > javaapplication1.NewEntity' - argument type mismatch - had objects of > type > > "java.lang.String" but expected signature > "javaapplication1.NewEntity$Type" > > > > > > But when I call > > > > BeanUtils.setProperty(bean, "type", NewEntity.Type.One ); > > > > > > all is ok. > > > > Is there some way to set a property on a bean that is an Enum with just > the > > string name, without calling methods on the bean enum type directly, as I > > dont have these handles, just the name and value as strings ?? > > > > > > Thanks > > > > Paul. > > > --001636c5b3ff156ed30464ecc270--