Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating properties using wildcard

 
venkata Tekkem
Greenhorn
Posts: 5
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10111
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class java.text.MessageFormat is meant to do exactly this. See its API documentation.
 
venkata Tekkem
Greenhorn
Posts: 5
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Pie
Posts: 10111
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thank You both of you i finished my task using MessageFormat class
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic