Play!: How to place property value in groovy expression - java

I have such code in my play! view
<button type="submit">${edit ? 'edit' : 'init'}</button>
I want to replace 'edit' and 'init' with property value. like
&{'button.edit'}
How can I do it?

I'm not exactly sure what you mean by "property value" but here are two interpretations:
Use &{''} if button.edit is defined in your conf/messages.en file (or whatever language).
&{'button.edit'}
Use ${} if button is an object and you are reading the edit field from its class.
${button.edit}

Related

Update attribute value using vtd-xml

Given an xpath to an attribute and a new value, I am looking to update the attribute value to the new value.
I have followed the example here: http://vtd-xml.sourceforge.net/codeSample/cs7.html and come up with the following:
autoPilot.selectXPath(xpath);
modifier.updateToken(vtdNav.getAttrVal(vtdNav.toString(autoPilot.evalXPath())), newContent);
...my tests all pass but perhaps because I am not used to the "tokenized" way that vtd-xml works, it doesn't "feel" right so I am just looking for affirmation that I've done the correct thing.
Your code will work just fine... assume you will call modifier.output().
but it is not optimal...
This statement
modifier.updateToken(vtdNav.getAttrVal(vtdNav.toString(autoPilot.evalXPath())), newContent);
Can be written as
modifier.updateToken(autoPilot.evalXPath()+1, newContent);
Because if the attribute name has an index value of i (!=-1), then the attrinute value is always i+1... as attr val immediately follows an attr name. No conditional check is needed.

How to get the Chinese name of a security in blpapi?

I have a BDP function that looks like this.
BDP("Glen Ln Equity","NAME_CHINESE_SIMPLIFIED")
It is to update the Chinese name of a security.
I have to translate it to Java blpapi but I am not sure how.
Since this is a BDP function, I think I should use Reference Data Request but you can only specify the ticker and field mnemonic when creating a Reference Data Request. I also know I can use override but to use an override, based on my understanding, I will need a fieldID so that I can set that fieldID's value to be "NAME_CHINESE_SIMPLIFIED".
However, I am not sure what fieldID to use.
What fieldID should I use for the override?
Also, where can I find a list of fieldIDs that can set for overrides?
It should work fine with a reference data request - you don't need to override anything here:
Element security = request.getElement("securities");
security.appendValue("GLEN LN Equity");
Element field = request.getElement("fields");
field.appendValue("NAME_CHINESE_SIMPLIFIED ");

How to iterate and load property file values in UI using ZK?

I have a property file named "ABC.properties" having values such as
A="APPLE"
B="BALL"
C="CAT"
Now i need to get these values and load in my UI. Have iterate and then need to load because like wise there may be more than 50 values in that property file.
Can anyone please help me with this?
In your zk.xml file, give the path of properties file you wanted to read.
<zk>
<system-config>
<label-location>/path/to/ABC.properties</label-location>
</system-config>
</zk>
If you want to read them in zul file, for example you want to show label having value as A then
< label value="${labels.A}" />
If you want to read properties file's value in listener class then do
Labels.getLabel("A");
First of all, I don't know if there are more items in the property file then you need to fetch.
Note : Multiple properties files all readed in this way and are accessible in the same map.
If yes :
Convert the key's with subsections :
FRUIT.APPLE = apple
FRUIT.ORANGE = orange
TOYS.BALL = ball
TOYS.DOLL = doll
and so on.
The next thing is as #BhushanPatil already mentioned :
In your zk.xml file, give the path of properties file you wanted to read.
<zk>
<system-config>
<label-location>/path/to/ABC.properties</label-location>
</system-config>
</zk>
Then you have the following method getSegmentedLabels under Labels.
This is the method we will use.
So if you want to declare it only in the zul, the next step is what you have to do :
<?xel-method
prefix="prop" name="all" class="org.zkoss.util.resource.Labels"
signature="java.util.Map getSegmentedLabels()"?>
<vlayout forEach="${prop:all().get('FRUIT')}">
<label value="${each.key} : ${each.value}"/>
</vlayout>
The Xel-method is for declaring the static method (only way to acces a static method before ZK 8).
Now we want to get all our FRUIT labels, so we call the getSegmentedLabels with the Xel-method name all().
This return a Map<String,Object> where all the labels are in.
We are interested only in the subsection FRUIT so we get the value behind the key FRUIT.
This object is again a Map<String,Object> wich contains every key under the FRUIT.
In this example it contains <'APPLE','apple'>,<'ORANGE','orange'>.
The next thing we need to do is iterating over the Map and showing all the values of the Map.
This we do with the forEach attribute.
So the each object's value is now an Object of class Entry<String,Object>.
The only thing to show it now is showing the value, with is Entry.getValue().

Strange OGNL behaviour when using #this in s:select

Consider the following where availableExclusions is an array of Date objects.
<s:select listValue="(new java.text.SimpleDateFormat('MM/dd/yyyy')).format(new java.util.Date(#this[0].time))" size="25" id="inputExclusionDates" name="available" list="availableExclusions" multiple="true" cssClass="multi-select" />
I created the above in response to this question How would I format a list of dates within a struts 2 select tag? (and I also recommended that the other solution may be the better way to go). Regardless if using such long OGNL expression is a good idea or not, I can't see the need for: new java.util.Date(#this[0].time) despite creating that fragment out of frustration and to my surprise found it worked where the seemingly equivalent #this[0] did not (produced no output).
If we substitute in listValue="#this[0].class" we see what we would expect: class java.util.Date
Creating a new Date behaves as expected, and calling the deprecated properties of Date such as listValue="#this[0].day" produces the expected output.
Why must I use the redundant expression new java.util.Date(#this[0].time) instead of #this[0] in this select statement?
Using Struts 2.3.1.2
Because #this[0] is automatically converted to String. If you turn log level to debug you can see an exception message that's normally suppressed.

Bean Validation + Resource Bundle ideas?

Here is what i want to be able to do with bean validation in my JPA entities :
Instead of #NotNull, i would like to do #NotNull(message="keyInMyResourceBundleFile")
I would like also to parameterize the resourceBundle, and i dont know the syntax for it, because it seems to me the message attribute contains only a string.
The parameter itself could be i18n-ed. For example, assuming there's a param attribute for the resourcebundle parameters, in English, #NotNull(message="missing.value", params={"credit card"}) String creditCard; It will be displayed something like this : "Missing required value for field credit card. In Indonesia, it'll be something like "Nilai harus di isi untuk Kartu Kredit. In this example, i cant hardcode the "credit card" because in Indonesia, it's "Kartu Kredit"
Displays the error message defined in the resource bundle on the log file or UI. Im not sure the way on how to do it, should i catch the ConstraintViolationException, get the message, and process the resource bundle by my own code ?
Please share your thoughts on this ?
Thank you !
Regarding 1 + 2
#NotNull(message="{keyInMyResourceBundleFile}")
Curly brackets are the indicator of a parameter substitution
Regarding 3
No idea what you are after. There is no params attribute for #NotNull. I guess you would do
#NotNull(message="{missing.credit.card}")
And of if you place it on another property you would call the key {missing.name}
Regarding 4
The ConstraintViolationException contains the set of *ConstraintViolation*s. Each ConstraintViolation contains the interpolated message as well as the message template. If you want to log it, do it ...

Categories

Resources