Pass string variable to struts tag - struts

I want to pass a string variable to an struts tag.
alert('<bean:message key="${result}"/>');
This tag is responsible to extract message from ApplicationResources.properties. Result contains the key for this message. the system tries to use the same result string itself rather than its content. Here is the error I get.
"Missing message for key "${result}"
I see this question and I got an idea but the problem still exist.
Variable in an attribute in Struts custom tag
My application is base on struts.
I use sth like this but I think its ugly and smelly
if(result == 'a.b.c' )
alert('<bean:message key="a.b.c"/>');
else if(result == 'a.b.c' )
alert('<bean:message key="a.b.d"/>');
else if(result == 'a.b.d' )
alert('<bean:message key="a.b.d"/>');

Try the following instead:
alert('<bean:message name="result"/>');
http://struts.apache.org/1.2.x/userGuide/struts-bean.html#message

Related

Applescript Get value of property by string name of property

In AppleScript. Let's say I have a record with a property called Title.
Let's say I set a variable to the text "Title"; can I use that variable to get the value of the property Title? Basically, is there any way to do something like this:
set result to property named "Title" of myRecord
Instead of:
set result to Title of myRecord
I found the answer. I also realize I didn't ask the correct question. The value I'm trying to obtain is from a property list item.
Here's what I learned, and how to accomplish this:
use framework "Foundation"
set _plist to ...
set _objcPlist to GetAppleScriptObjectAsObjcObject(_plist)
set _value to GetObjcPropertyValueByName("MyProperty", item 1 of _objcPlist)
on GetAppleScriptObjectAsObjcObject(asObject)
set a to current application
set cClass to class of asObject
if (cClass is record) then
return a's NSDictionary's dictionaryWithDictionary:asObject
else if (cClass is list) then
return a's NSArray's arrayWithArray:asObject
else
error "Unexpected Class Type"
end if
end GetAppleScriptObjectAsObjcObject
on GetObjcPropertyValueByName(propertyName, objcItem)
return (objcItem's valueForKey:propertyName) as text
end GetObjcPropertyValueByName
you may try the try ... on error approach:
set aRecord to {title:"hello world", author:"who's who"}
try
aRecord as Unicode text
on error error_message
set err to error_message
end try
err
-- "Can’t make {title:\"hello world\", author:\"who's who\"} into type Unicode text."
then parse err (it's text now). it depends on the complexity of aRecord, if it's a record of nested lists, or records; the parsing would be very complicated. have fun :)

ZK : Using a custom Id generator for selenium while having dynamic ids

I'm using a custom Id generator, the one listed here in the article
It works fine, however I've dynamic ID that i generate for my tabs:
<tabpanels children="#load(vm.myTabsList) #template('myTemplate')" >
<template name="myTemplate" var="each">
<tabpanel id="tabPanel${each.key}">
<include src="zul/myTabZul.zul/>
</tabpanel>
</template>
</tabpanels>
I'm getting this exception :
org.zkoss.zk.ui.UiException: Illegal character, }, not allowed in uuid,
The method that throws Error doesn't leave much room actualy ... Not sure how I can bypass that.
public static void checkUuid(String uuid) {
int j;
if (uuid == null || (j = uuid.length()) == 0)
throw new UiException("uuid cannot be null or empty");
while (--j >= 0) {
final char cc = uuid.charAt(j);
if ((cc < 'a' || cc > 'z') && (cc < 'A' || cc > 'Z')
&& (cc < '0' || cc > '9') && cc != '_')
throw new UiException("Illegal character, "+cc+", not allowed in uuid, "+uuid);
}
}
Although the original generator seems to do just fine but it probably doesn't generate the Id at the same time.
If someone has expering on selenium and ZK, thanks for your input.
I don't think it's Selenium related.
The final '}' is considered part of your id string because 'tabPanel${each.key}' is not a valid EL expression. Have a look here on how to write valid EL expressions.
I would advise you to concatenate the two parts (tabPanel and ${each.key}) using the core's cat method. Your code would become:
<!-- at the beginning of your file -->
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
...
<tabpanel id="${c:cat('tabPanel',each.key)}">
'each.key' will be properly interpreted thanks to the surrounding ${.} (it does not have to be in direct contact).
I hope this is not too late and it still helps.
I think it's because you try to use a dynamic id, but it doesn't take it.
tabPanel${each.key} contains the '}' spoke of (and mark up that they check from right to left, so that's the first one we come across)
With a little more of the zul I could advise how you can change it.

Output alternate field in case bound field is null on a Kendo MVC Grid ClientTemplate

I have a cell in a kendo MVC grid that I'd like to take one of two data fields depending on the value of one:
#(Html.Kendo().Grid(Of RTFVM)().Name("RealTimeFinancials") _
.Columns(Sub(c)
c.Bound(Function(x) x.Line.LineItem).HtmlAttributes(New With {.style = "text-align:left"})
c.Bound(Function(x) x.Line.Months(0).Total).Format("0:#,##0}").ClientTemplate("#if(data.Line.Months[0].Message == null) {data.Line.Months[0].Total} else {data.Line.Months[0].Message} #")
End Sub) _
etc
The cell is rendering as blank every time regardless of the result of the null comparison. I must be missing something obvious!
The #...# template markup just executes JS but does not output anything.
Instead, try #:...# or #=...# which both output a value back to the HTML, or this template:
#if(data.Line.Months[0].Message == null) {##:data.Line.Months[0].Total##} else {##:data.Line.Months[0].Message##}#
(it looks weird on 1 line, but if you were to insert line breaks it would make more sense:)
#if(data.Line.Months[0].Message == null) {#
#:data.Line.Months[0].Total#
#} else {#
#:data.Line.Months[0].Message#
#}#
I think this template might also work:
#: data.Line.Months[0].Message ?? data.Line.Months[0].Total #
Which would use the null-coalescing operator to use Total in the case where Message is falsey.

If condition not working in Bean shell sampler

I am writing following script in Bean Shell sampler but it is not executed properly,
JMeter never enters in 'if' condition, what I m doing wrong?
*WRIDTEMP is a variable, WRId is a variable having value retrieved from a csv file.
if((vars.get("WRIDTEMP")==vars.get("WRId")) || vars.get("WRIDTEMP")==0)
{
String i = vars.get("C");
int counter = Integer.parseInt(i);
counter++;
vars.put("C", "" + counter);
if(counter<10 )
{
vars.put("Message",temp+authString);
}
}
You are comparing String using == , you must use .equals() method to compare them.
to compare to 0, you should do .equals("0")
I think I can confirm this issue.
I'm not sure if it's a bug or not, but what I have found is that when running this code:
String jira_version = vars.get("jiraVersion");
if (jira_version =="7") ) {
vars.put("closeIssueTitle_local","Done");
vars.put("isJIRA6_local","false");
vars.put("isJIRA7_local","true");
} else if ( jira_version.equals("6") ) {
vars.put("closeIssueTitle_local","Close Issue");
vars.put("isJIRA6_local","true");
vars.put("isJIRA7_local","false");
} else {
vars.put("closeIssueTitle_local","CLOSEISSUETITLE_BEANSHELL_FAILURE");
vars.put("isJIRA6_local","ERROR");
vars.put("isJIRA7_local","ERROR");
}
Where the value of jira_version is either literally 6 or 7, then the if condition always evaluates to it's last, no-match case.
when I change my evaluation condition to
if ( jira_version.equals("6") ) {
then it evaluates as expected.
Here's the rub for me. When I run this in the standalone beanshell environment, bsh-2.0b5.jar for example, it my code example works as expected. It's only within JMeter that I have to rely on .equals("X").
This does feel a bit like a bug.
This seems to be a bug with beanshell interpreter in jmeter. The regular beanshell shell does support string comparison using == . In fact, it is one of the features of beanshell.

Recognizing multiple string values in a single action

Thanks again for the help.
I have a simple action that checks the stringValue of a textField, and if it matches - a status message prints in a second textField:
if
(textField.stringValue == (#"Whatever" )){
[outputDisplay setStringValue:#"Success"];
My question is how do I implement multiple input stringValue options in this method? For example "Whatever" "Whatever1, Whatever2" all return "Success" in the outputDisplay.
thanks.
Paul
Create a set of answers you're looking for and test if the string in question is in there.
NSSet *successStrings = [NSSet setWithObjects:#"Whatever1",
#"Whatever2",
#"Whatever3",
nil];
if ([successStrings containsObject:st]) {
[outputDisplay setStringValue:#"Success"];
}
(An array would also work, but a set is specialized for testing membership, so it's a better fit for what we're doing here.)
Firstly, to check for equality of NSString-s you should use -isEqualToString:. == compares the pointer values which often returns NO even if the two strings' contents are the same.
To check if the text field match multiple strings, you connect them with the || (or) operator, so you get
NSString* st = textField.stringValue;
if ([st isEqualToString:#"Whatever"] || [st isEqualToString:#"Whatever1"] || [st isEqualToString:#"Whatever2"]) {
[outputDisplay setStringValue:#"Success"];