If your options are well known (if you were going to use a switch they
are), create a Map with the strings as the key and the integer as the
value, store in application scope; load them from a properties file or
some other source; this will give you more flexibility.

Would that work? A little bit more coding, but useful in the end.


>>-----Original Message-----
>>From: Kamholz, Keith (corp-staff) USX [mailto:[EMAIL PROTECTED]
>>Sent: Thursday, June 05, 2003 11:52 AM
>>To: 'Struts Users Mailing List'
>>Subject: RE: switch statement
>>
>>Because having descriptive values for parameters helps make your code
more
>>understandable, both for yourself and for others.
>>
>>It's not a big deal, I'll just use the if statements.
>>
>>
>>Keith Kamholz
>>Programming and Architecture
>>Moog Inc.
>>
>>Phone: (716) 687-7001
>>
>>
>>
>>-----Original Message-----
>>From: Yee, Richard K,,DMDCWEST [mailto:[EMAIL PROTECTED]
>>Sent: Thursday, June 05, 2003 11:49 AM
>>To: 'Struts Users Mailing List'
>>Subject: RE: switch statement
>>
>>
>>Why don't you send a parameter that can be converted into an int then?
>>
>>-Richard
>>
>>
>>> -----Original Message-----
>>> From:       Kamholz, Keith   (corp-staff) USX
[SMTP:[EMAIL PROTECTED]
>>> Sent:       Thursday, June 05, 2003 8:42 AM
>>> To: 'Struts Users Mailing List'
>>> Subject:    RE: switch statement
>>>
>>> The reason I wanted to do this was to make my Action classes
cleaner.  I
>>> send a parameter to the Action to determine which item to pull from
a
>>> database, then forward to a certain page.
>>>
>>> I didn't think I could get the switch to work, it was worth a try
though.
>>> For a situation like mine, what do you all find to be the best way
of
>>> doing
>>> this?  I know I can use a series of if statements, it's just not
very
>>> pretty...
>>>
>>>
>>> Keith Kamholz
>>> Programming and Architecture
>>> Moog Inc.
>>>
>>> Phone: (716) 687-7001
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: Erik Price [mailto:[EMAIL PROTECTED]
>>> Sent: Thursday, June 05, 2003 11:38 AM
>>> To: Struts Users Mailing List
>>> Subject: Re: switch statement
>>>
>>>
>>>
>>>
>>> Kamholz, Keith (corp-staff) USX wrote:
>>> > Hey everyone,
>>> > This is more of a Java question than a Struts question, I hope you
all
>>> don't
>>> > mind.
>>>
>>> Not really, but for future reference I have found this resource to
be
>>> more helpful for such questions:
>>>
>>> http://forum.java.sun.com/forum.jsp?forum=31
>>>
>>> > I'm just wondering if there is any way to use a String for a
switch
>>> > statement, or if you are restricted to the true primitive types.
>>> > I haven't found a way, but it seems like something that lots of
people
>>> would
>>> > want that wouldn't be hard for the Java developers to allow for.
>>> > Wouldn't you agree?
>>>
>>> The reason why it doesn't work is probably specific to the
>>> implementation of the language (maybe performance reasons), but a
lot of
>>> people don't miss it -- nor would they agree, I suspect.  The reason
is
>>> that you can usually add behaviors to objects so that a single
>>> polymorphic method call can usually eliminate all of the
infrastructural
>>> work of writing a switch statement, so doing a switch on an object
>>> doens't make much sense in that context.  Of course, this is not
>>> applicable in all senses, such as your case with String which is
final....
>>>
>>>
>>>
>>>
>>>
>>> Erik
>>>
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to