• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Eclipse not generating gettters and setters properly?

 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Weird problem.

I have a data member called mName. I tell Eclipse to generate getters and setters for it. They are setMName() and getMName(). Unfortunately, the proper accessors and mutators should be

getmName() and setmName(String mName)

JSF, which uses reflection to determine accessors and mutators, using setMName() and getMName() results in errors about not finding the data member.

Anyone else see this?
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never had Eclipse fail generating setters and getters, and according to what you've posted, it didn't fail here, either.

However, the introspection mechanism and the services in beanutils (used by JSF) does require getMName() and setMName(), not getmName(). The mechanism is very simplistic. It expects the first character of the member variable to be lower case and it will flip it to upper case and prefix it with "set" or "get".
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I'd say it there is a problem somewhere. In IntelliJ IDEA if I have the following member:

mName

And tell IDEA to generate getters and setters I get

getmName and setmName

So who is right? Eclipse or IDEA?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tim Holloway:

However, the introspection mechanism and the services in beanutils (used by JSF) does require getMName() and setMName(), not getmName(). The mechanism is very simplistic. It expects the first character of the member variable to be lower case and it will flip it to upper case and prefix it with "set" or "get".



I don't think that is totally accurate. In one of my JSF apps I tested with mName and getmName and setmName. My JSF page had value="#{someBean.mName}" and it worked perfectly.
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gregg Bolinger:


I don't think that is totally accurate. In one of my JSF apps I tested with mName and getmName and setmName. My JSF page had value="#{someBean.mName}" and it worked perfectly.



And conversely, I had a data member mName and getter getMName() and a value in my JSF of "#{someBean.mName}" and it didn't work. If I changed the JSF call to "#{someBean.MName}" it does work. Is Eclipse or IntelliJ right? Or is there a bug in JSF or the JDK perhaps? I don't know where to look in the spec for this one...
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the JavaBeans spec on Intorspector.decapitalize:

Utility method to take a string and convert it to normal Java variable name capitalization. This normally means converting the first character from upper case to lower case, but in the (unusual) special case when there is more than one character and both the first and second characters are upper case, we leave it alone.


This doesn't seem to relate directly to the problem though.

[fixed URL]
[ September 08, 2005: Message edited by: Jeanne Boyarsky ]
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


/**
* This constructor constructs an IndexedPropertyDescriptor for a property
* that follows the standard Java conventions by having getFoo and setFoo
* accessor methods, for both indexed access and array access.
*

* Thus if the argument name is "fred", it will assume that there
* is an indexed reader method "getFred", a non-indexed (array) reader
* method also called "getFred", an indexed writer method "setFred",
* and finally a non-indexed writer method "setFred".
*
* @param propertyName The programmatic name of the property.
* @param beanClass The Class object for the target bean.
* @exception IntrospectionException if an exception occurs during
* introspection.
*/
public IndexedPropertyDescriptor(String propertyName, Class beanClass)
throws IntrospectionException {
this(propertyName, beanClass,
"get" + capitalize(propertyName),
"set" + capitalize(propertyName),
"get" + capitalize(propertyName),
"set" + capitalize(propertyName));
}

which calls

private static String capitalize(String s) {
char chars[] = s.toCharArray();
chars[0] = Character.toUpperCase(chars[0]);
return new String(chars);
}





Apparently, all this does is capitalize the first letter so in the case of mName it would indeed produce getMName(). If this is the case, it would appear that both the JSF and IntelliJ were handled improperly according to this spec.
 
Tim Holloway
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Acutally, the names of accessors can be anything, providing that the system doing the accessing understands what those names will be. For a standard bean container, that means either the default capitalization rules or use of a Bean Descriptor class. The BeanUtils used By JSF honors Bean Descriptors, I believe. For beans without descriptors, it simply deferes to the Sun JavaBean services.

Here's the exact text for a default PropertyDescriptor as of JDK 1.4.2:


PropertyDescriptor

public PropertyDescriptor(String propertyName,
Class beanClass)
throws IntrospectionException

Constructs a PropertyDescriptor for a property that follows the standard Java convention by having getFoo and setFoo accessor methods. Thus if the argument name is "fred", it will assume that the writer method is "setFred" and the reader method is "getFred" (or "isFred" for a boolean property). Note that the property name should start with a lower case character, which will be capitalized in the method names.



No mention made of alternate rules for when the second character is uppercase.
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic