This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Updating properties using wildcard Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Updating properties using wildcard" Watch "Updating properties using wildcard" New topic
Author

Updating properties using wildcard

venkata Tekkem
Greenhorn

Joined: May 25, 2012
Posts: 5

Hi

can any one tell me weather its possible to use wildcard to take values from drop down list and replace the value in properties file Using Jsp,Servlets

example

name=Welcome {1}

this {1} should get replaced with value from dropdown list
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

venkata naveenTeja wrote:can any one tell me weather its possible to use wildcard to take values from drop down list and replace the value in properties file Using Jsp,Servlets

example

name=Welcome {1}

this {1} should get replaced with value from dropdown list

It certainly can be done, but I think you need to specify your requirements a lot more clearly.

Suppose your properties file has a thousand lines: Is {1} specific to a particular line, or do you want to replace every instance of {1} with whatever you choose? The latter would suggest an 'identifier', so you'd better be sure you get it right.

Secondly: Do you actually want to replace the value in the properties file, or just its representation in memory? Again, the latter sounds more likely; otherwise you will lose all your {n} identifiers after replacement.

BTW: this type of encoding is called a 'placeholder', not a 'wildcard'.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14194
    
  20

Class java.text.MessageFormat is meant to do exactly this. See its API documentation.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
venkata Tekkem
Greenhorn

Joined: May 25, 2012
Posts: 5

@Winston Gutkowski - 1) Requirement is to overwrite the string {1} in the properties file itself not its instance in memory
2) where ever it is found as{1} its should get replaced with the string from drop down list ,My properties files contains 50 variables with {1} as sub string

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

venkata naveenTeja wrote:1) Requirement is to overwrite the string {1} in the properties file itself not its instance in memory

Seems odd, since that means it can only be once done, which may make testing a bit awkward.

2) where ever it is found as{1} its should get replaced with the string from drop down list
My properties files contains 50 variables with {1} as sub string

Fine. That was more for your information than mine, so you know exactly what you're dealing with.

For the basic translation, you should definitely follow Jesper's advice, which is why it has so many 'thumbs up' points (including one from me).

Winston
venkata Tekkem
Greenhorn

Joined: May 25, 2012
Posts: 5



Thank You both of you i finished my task using MessageFormat class
 
GeeCON Prague 2014
 
subject: Updating properties using wildcard