Skip to content

Instantly share code, notes, and snippets.

@dekz
Created August 11, 2010 13:51
Show Gist options
  • Select an option

  • Save dekz/519007 to your computer and use it in GitHub Desktop.

Select an option

Save dekz/519007 to your computer and use it in GitHub Desktop.
private void setPropertyOfObject(Object obj, String propname, String text)
{
if (obj == null) return;
Class<?> cl = obj.getClass();
try {
BeanInfo info = Introspector.getBeanInfo(cl);
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
if (pd.getName().equals(propname))
{
Method m = pd.getWriteMethod();
if (m == null)
{
System.out.println("NULL method " + propname);
return;
}
Class<?>[] params = m.getParameterTypes();
Object casted = createParameter(text,params[0]);
m.invoke(obj, casted);
}
}
} catch (Exception e)
{
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment