user1283791
user1283791

Reputation: 279

tapestry properties file + injection , implement support for parameter[n]

I am rather new to tapestry. In tapestry project here such case

parameters are in X.properties file, e.g.

SomeService.urlDoOnething=http://etc/etc1
SomeService.urlDoOtherthing=http://etc/etc2

in 1.java

@Inject
@Value("SomeService.urlDoOnething")
private String SomeServiceurlDoOnething
@Inject
@Value("SomeService.urlDoOtherthing")
private String SomeServiceurlDoOtherthing

in 2.java

request = new ClientRequest(SomeServiceurlDoOnething); ....

I must implement SomeService[N].url*thing parameters. User can choose service from combobox (thinking also how to implement combobox thing elegantly).

As I don't know tapestry much and searching docs/google hasn't been very helpful yet.. maybe I can find good advice here - how can I do this in the most elegant / least coding way?

Upvotes: 0

Views: 978

Answers (1)

pstanton
pstanton

Reputation: 36640

I'm not sure I understand your question completely, can you further explain this part:

I must implement SomeService[N].url*thing paremeters. User can choose service from combobox (thinking also how to implement combobox thing elegantly).

what I think i do understand is that you have two phases to your problem:

  1. how to ingest a properties file
  2. how to access the key/value pairs via injection

to solve 1:

Add the following to your Module (AppModule.java):

public void contributeSymbolSource(OrderedConfiguration<SymbolProvider> providers)
{
    providers.add("ExtraConfiguration", new ClasspathResourceSymbolProvider("extra.properties"), "after:SystemProperties", "before:ApplicationDefaults");
}

to solve 2:

In your Page.java, use @Symbol instead of @Value:

@Inject
@Symbol("SomeService.urlDoOnething")
private String urlDoOnething;

Upvotes: 2

Related Questions