You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Daffin, Miles (Company IT)" <Mi...@morganstanley.com> on 2005/02/10 18:30:40 UTC
Constants for property names
Hi All,
What do people feel about using constants for property names?
In general I feel one should use constants for such things, but it is
far from easy in a web app to do so.
If I define a constants class (e.g. com.plok.app.constants.Keys) I can
use this in everywhere in java code and in *most* (not all) places in
the jsps. For example this works:
<html:text property="<%=Keys.Section0.APPLICANT_NAME%>"/>
but this does not:
<jsp:param name="<%=Keys.APPLICANT_NAME%>" value="What Ever"/>
I have the same problem if I want to refer to this property in any of
the following places:
- jstl tags
- xml files (e.g. struts-config, validation)
Do you see what I mean?
So, what am I doing/thinking wrong? Should I forget about defining
constants?
Am I getting my knickers in a twist over nothing?
-Miles
Miles Daffin
Morgan Stanley
20 Cabot Square | Canary Wharf | London E14 4QA | UK
Tel: +44 (0) 20 767 75119
miles.daffin@morganstanley.com <ma...@morganstanley.com>
--------------------------------------------------------
NOTICE: If received in error, please destroy and notify sender. Sender does not waive confidentiality or privilege, and use is prohibited.
Re: Constants for property names
Posted by Laurent <lg...@free.fr>.
Daffin, Miles (Company IT) wrote:
> What do people feel about using constants for property names?
>
> In general I feel one should use constants for such things, but it is
> far from easy in a web app to do so.
I can't really see the point. A property name is like a variable name,
it will never be displayed or localized, so why would you ever want to
change it?
> <html:text property="<%=Keys.Section0.APPLICANT_NAME%>"/>
Can you think of a case where this value won't be "applicantName"?
> - jstl tags
> - xml files (e.g. struts-config, validation)
Worse: if you have an ActionForm, you can't have a property whose name
depends on a constant!! And what about getters and setters.
> Should I forget about defining
> constants?
Yes :)
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org