I have a DB connection using separated properties.
serverName=MyServerName
databaseName=MyDbName
instance=MyInstance
I want to override these with env.properties and this is working however the 'instance' property needs to be left blank. I've tried passing in the env.properties with a blank entry for 'instance' however it does not override the default 'MyInstance' (others are overridden fine).
Is this possible? If so, please may you give an example?
Related
As part of my test base class, I have something like this:
seleniumJupiter.getConfig().setDefaultBrowser(BROWSER.getStringValue());
seleniumJupiter.getConfig().setScreenshotAtTheEndOfTests("whenfailure");
SeleniumJupiter.getConfig().takeScreenshotAsBase64AndPng();
and potentially 10-20 more config parameters. Could I somehow overwrite the whole selenium-jupiter.properties file and change some of the properties and other left default?
You can maintain your own copy of selenium-jupiter.properties in your project classpath, changing the values you need, and leaving the default values for the others. Then, you have two options to configure Selenium-Jupiter to use that properties:
Using a JVM property: -Dsel.jup.properties=/my-sel-jup.properties
Using an environmental variable: SEL_JUP_PROPERTIES=/my-sel-jup.properties
I have a properties file that i create manualy.
I can to get the propert in the file by getProperty() function, but I can't change it!
I try with setProperty() function, but the file isn't changed.
can u help me?
thanks!
zipi
You need to write the properties file again using store() (of which there are two variants). The setProperty() method changes the value of property stored in memory, not the value of the property in the file the properties were loaded from.
For further reading see the Properties Tutorial.
SetProperty() will only set the property during the runtime. It will not go and override your file property. It wont modify your file.
Did you try to call something like
prop.store(new FileOutputStream("config.properties"), null);after calling prop.setProperty method? Because it's the way you flush changes to file.
Without calling store changes are visible only in application memory.
I have a resource bundle which consist of a few files, lets say:
address_en_us.properties
address_nl_nl.properties
address_fr_ca.properties
How do I obtain and merge two of the properties file with en_us being the 'default' property file?
Some background:
When I use one of the localized property, say, fr_ca, for each keys that are not localized in fr_ca, I want to use the default value specified in en_us
Just rename your "address_en_us.properties" to "address.properties" and this file is always used as 'default' property file.
One way I have seen work is to have the default values set in code, where it is hard-coded in java class. That way any property not set in properties file but used in code will always get the default value.
And from an architecture perspective this is also a really good idea, shipping products with default properties values in code, overridden by the values in properties file. And if you make it so that the product (Android app in my perspective) makes a server call at start-up to check and overwrite the values of properties files then you can add a lot of flexibility to the product.
We are currently developing a project with Struts2. We have a module on which we display a large amount of data on read-only fields from a group of beans via the "property" Struts 2 data tag (i.e. <s:property value="aBeanProperty" />) on a jsp file. In some cases most of the fields might come empty, so a blank is being displayed on screen.
Our customer is now requesting us to display default string (i.e. "N/A") whenever a property comes empty, so that it is displayed in place of the blank spaces currently shown.
We are looking for a way to achieve this in a clean and maintainable way. The 'property' tag comes with a 'default' attribute on which one can define a default value in cases when the accessed property comes as null. However, most of our properties are empty strings, therefore it does not work in our case.
Another solution we are thinking of is to define a base class for all of our beans, and define a util method which will validate if a string is null or empty and then return the default value. Then we would call this method from each bean getter. And yes this would be tiresome and kind of ugly :), therefore we are holding out on this one in case of a better solution.
Now, we have in mind a solution which we think would be the best but have not had luck on how implement it. We are planning on extending the 'property' tag some way, defining a new 'default' attribute so that besides working on null properties, it also do so on empty strings ("", " ", etc). Therefore we would only need to replace the original s:property tag with our new custom tag, and the desired result would be achieved without touching java code.
Do you have an idea on how to do this? Also, any other clever solution (maybe some sort of design pattern?) on how to default the values of a large amount of property beans are welcome too!
(Or maybe, even there might be some tag that does this already in Struts2??)
Thanks in advance.
Shorter version in case you don't want to read all of the above! :)
Currently Struts2 provides a property tag (<s:property value="someValue" />), it is used to display the content of a value, e.g. a String variable on an Action class. This tag contains an attribute called "default" where you can define a default value to be displayed IF the variable is set to NULL, e.g. you can set it to display "N/D" for these values.
We now need to do the same, but that it also works on empty Strings ("", " ", etc), not only on nulls. We plan on extending this tag so that we have our own (maybe something like <s:propertyEmpty value="someValue" />) and accomplish this behavior. Can you guide how to accomplish this?
Your help is greatly appreciated. Thanks!
Interesting. I believe you are on the right track.
Only that I would try to extend/modify the property tag so that the new behaviour is explicitly set in the jsp code. I mean, I would not like that each in the web app automatically gets the new behaviour, because perhaps there are some bean properties for which I want the original struts2 behaviour.
I would prefer to have a new tag nane (eg: ... or something shorter) or a new attribute (eg )
Perhaps this helps: http://bodez.wordpress.com/2009/03/13/customising-struts2-jsp-tags/
I've trying to move parameters from axis2.xml to be specific to a single service by putting them in services.xml
I've tried this by moving false
and it doesn't work.
Any tips on what I'm doing wrong? Is there any reason why parameters can't be moved in this way?
Instead of moving the parameter from axis2.xml try to override that same parameter by adding parameter with the same name and a different value in services.xml
Also refer this small tutorial.