I inherited some old Cocoon code, if it's obvious, please tell me where in the docs I could find it.
I have a function to clean up some page parameters. I want to hand over the content to that function, but I can't manage to get there.
This is the original code, the value must pass my "cleanPath" function.
<jdbp:page-param name="pageToLoad" value="${{request.requestURI}}/../{#page}"/>
Attempt 1:
<jdbp:page-param name="pageToLoad" value="cleanPath(${{request.requestURI}}/../{#page})"/>
My attempt was to add the function in and leave everything like that, but it's not working.
My next attempt is these nice xsp:logic blocks, where I can't get the requestURI. "request.requestURI" is unknown, evaluate complains
"Type mismatch: cannot convert from Object to String".
<xsp:logic>
String input2 = evaluate("${{request.requestURI}}", String.class);
String input = "/../<xsl:value-of select="#page"/>";
putVariable("Hase","Test "+input);
</xsp:logic>
<jdbp:page-param name="pageToLoad" value="${{request.requestURI}}/../{#page}"/>
<jdbp:page-param name="Hase" value="${{Hase}}"/>
It's easy to just call request.getRequestURI();. No need for complicated wrappers.
Related
drl file :
rule "pendingMsgSizeModified"
when
$tibcoEMSObj : TibcoEMSData(deliveredMsgCnt.contains("MB") && pendingMsgSize \> 100)
eval (!($tibcoEMSObj.typeOfAlert != null))
then
$tibcoEMSObj.setSendEmail(true);
$tibcoEMSObj.setTypeOfAlert($tibcoEMSobj.getTypeOfAlert()+"pendingMsgSize###");
update($tibcoEMSObj)
end
It gives error at this location : $tibcoEMSobj.getTypeOfAlert()
Error : \[Error: unable to resolve method using strict-mode: org.drools.core.spi.KnowledgeHelper.$tibcoEMSobj()\]
\[Near : {... SObj.setTypeOfAlert($tibcoEMSobj.getTypeOfAlert()+ ....}\]
I am expecting to use the getter method to get it and concatenate the string to set in another variable and save/update it
Your syntax is all over the place. And without actually seeing your model, it's hard to tell what you're even trying to do.
But based on what you said:
I am expecting to use the getter method to get it and concatenate the string to set in another variable and save/update it
And the code you did provide, I think this is what you're trying to do:
rule "pendingMsgSizeModified"
when
$tibcoEMSObj : TibcoEMSData(
deliveredMsgCnt.contains("MB"),
pendingMsgSize > 100,
$alertType: typeOfAlert != null
)
then
String newAlert = $alertType + "pendingMsgSize###";
modify($tibcoEMSObj) {
setSendEmail(true)
setTypeOfAlert(newAlert)
}
end
I presumed that your eval was either typo'd or just plain wrong since it was checking that the value was actually null. Don't use eval unless you have absolutely no other choice. (And I've never actually run into a situation where there was no other choice.)
I also presumed that the alert type will not change. I don't know what your sendEmail method does, or if it has side effects; if it does have side effects that change the typeOfAlert, then you'll of course need to call getTypeOfAlert() after calling setSendEmail.
I want to convert $departureFromDate (format:yyyy-MM-dd) to date object so that I can perform increment operations on it. I have been trying to do it the following way:
#set($departureFromDate = "{{jsonPath request.body
'$.departureFromDate'}}")
#set($dateObj = $date.toDate('yyyy-MM-dd',"$departureFromDate"))
#set($calendar = $date.getCalendar())
$calendar.setTime($dateObj)
$calendar.add(6,5)
The above code works if give an actual date like:
#set($dateObj = $date.toDate('yyyy-MM-dd',"2018-09-22"))
But does not work when I try to use $departureFromDate
There are several problems in your code. First, as user7294900 noted, the right value of the first assignation seems quite weird. Then, you don't need to instanciate yourself a calendar (plus, you can write $date.calendar instead of $date.getCalendar(), and you don't need double quotes around string arguments).
#set($body = '{ "departureFromDate" : "2018-03-01" }')
$json.parse($body)
#set($departureFromDate = $json.departureFromDate)
#set($dateObj = $date.toDate('yyyy-MM-dd', $departureFromDate))
#set($calendar = $date.toCalendar($dateObj))
$calendar.add(6, 5)
The above code uses a JSON parsing tool, whose parse() method renders a json wrapper, that you shall provide in your context.
As a final advise, if you hadn't already thought of it, be sure to print $obj and $obj.class.name in your context as a trivial debugging technique if you don't understand what happens.
How can i send an Array with a HTTP Get request?
I'm Using GWT client to send the request.
I know this post is really old, but I have to reply because although BalusC's answer is marked as correct, it's not completely correct.
You have to write the query adding "[]" to foo like this:
foo[]=val1&foo[]=val2&foo[]=val3
That depends on what the target server accepts. There is no definitive standard for this. See also a.o. Wikipedia: Query string:
While there is no definitive standard, most web frameworks allow multiple values to be associated with a single field (e.g. field1=value1&field1=value2&field2=value3).[4][5]
Generally, when the target server uses a strong typed programming language like Java (Servlet), then you can just send them as multiple parameters with the same name. The API usually offers a dedicated method to obtain multiple parameter values as an array.
foo=value1&foo=value2&foo=value3
String[] foo = request.getParameterValues("foo"); // [value1, value2, value3]
The request.getParameter("foo") will also work on it, but it'll return only the first value.
String foo = request.getParameter("foo"); // value1
And, when the target server uses a weak typed language like PHP or RoR, then you need to suffix the parameter name with braces [] in order to trigger the language to return an array of values instead of a single value.
foo[]=value1&foo[]=value2&foo[]=value3
$foo = $_GET["foo"]; // [value1, value2, value3]
echo is_array($foo); // true
In case you still use foo=value1&foo=value2&foo=value3, then it'll return only the first value.
$foo = $_GET["foo"]; // value1
echo is_array($foo); // false
Do note that when you send foo[]=value1&foo[]=value2&foo[]=value3 to a Java Servlet, then you can still obtain them, but you'd need to use the exact parameter name including the braces.
String[] foo = request.getParameterValues("foo[]"); // [value1, value2, value3]
I'm trying to send an email using a javascript code in a Java project. Database connection works fine, I already tested it. I got the error:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing ) after formal parameters (#1) in at line number 1
The only information of relevance is not readily reported: the final JavaScript string executed. Make sure to look at relevant data when debugging. After inspecting the final string it will be apparent why it is incorrect and trivial to "fix".
Hint: it will look something like function sendMail(userblah, foo#bar.qux) { .., which is indeed invalid JavaScript.
The problem and solution should be self-evident from that - use fixed parameters (variable names) in the function declaration and supply arguments (values) via the invokeFunction call.
Solution:
// The following parameter names are JAVASCRIPT variable names.
String script = "function sendMail(username, email, body) { ..";
// And pass correct arguments (values), in order. The variables used
// here are JAVA variables, and align by-position with the JS parameters.
inv.invokeFunction("sendMail", username, email, "EMAIL SENT!!!!");
In addition, the getElementById (invalid ID) is wrong, the body parameter is never used, and encodeURIComponent should be used (instead of escape).
Not sure if this is a typo or not:
result = request.executeQuery("SELECT user.login, user.email "
+ "FROM user " + );
It looks like you are missing the end of your statement.
Hmmmm, your function definition:
function sendMail("username","email") {...}
doesn't look like valid JavaScript to me, apart of that, you never call the function.
Pseudocode, how to do it:
function sendMail(username, email) {
var link = "jadajada" + email; // .... etc
}
sendMail("+username+","+email+");
In XPAND template, I have a call where, the call should be done for the method which takes the String and the Object.
i.e. ,
«setData("String",Object)-»
For the above method, the String value I want to pass is the simplified value of below string:
where ,«getAddress(object)» , return dynamic value.
"/begin DATA XETK DEFAULT_RASTERS «getAddress(object)» /end DATA"
If I try to do this in the below way, i get compilation error.
«setData("/begin DATA XETK DEFAULT_RASTERS «getAddress(object)» /end DATA",Object)-»
Can anyone help me, how can I pass this string to the method?
Thanks ,
Regards,
Shwetha
Ok , I got the answer for the above question.
In XPAND , the expressions are not allowed to pass as parameter. But this is done in XTEND 2