How can to use fn:contains case-insensitive in JSL EL? - jsf

I trying to find out if one string contains another. But, unfortunately, fn:contains function is case-sensitive. Are there are any ways to make it case-insensitive?
I tried to put both into one case:
fn:contains(car.color.toLowerCase(), smartBean.txt.toLowerCase()) ? 'true' : 'false'
But it didn't work due to method's brackets. I also can't use f:to-upper inside f:contains function.

There's a fn:containsIgnoreCase(). Just use it instead.
#{fn:containsIgnoreCase(car.color, smartBean.txt)}
By the way, your failed toLowerCase() attempt should have been done as follows:
#{fn:contains(fn:toLowerCase(car.color), fn:toLowerCase(smartBean.txt))}
Using toUpperCase() works as good as well:
#{fn:contains(fn:toUpperCase(car.color), fn:toUpperCase(smartBean.txt))}
Perhaps you just made an EL syntax error.
Note that the ? 'true' : 'false' part is completely superfluous as that's already returned by the function.

For those just finding this, #BalusC's answer is correct - but structure has changed, see just fn:upper-case, fn:lower-case - don't see the ignoreCase option anymore but if you cast it one way or the other to compare, it will work.

Related

JSF 2.0 EL #{param.XXX} dynamic?

Is there a way to fetch params in the .xhtml dynamically?
the normal way would be: #{param.PARAMETERNAME}
now this PARAMETERNAME sometimes not certain and can change.
Is there a way to make e.g.:
{param.#{id}}
i tried it with additional ui:param like
but #{param.paramname} doesn't work... (returns always null like it searches for the absolute "paramname")
The brace notation ([]) was introduced for this very reason. So, if you have a paramName parameter then the following will do the trick:
#{param[paramName]}

proper syntax for bpel bpel:doXslTransform

I am trying to do an XSL transform on an xml structure in a bpel assignment statement. There is a syntax problem, but I am having trouble finding official documentation. There are examples all over the internet but I have not found a clear explanation. Here is my best shot. What do the last two parameters do? Why is eclipse saying the first argument must be a literal, even though test3.xsl is a string?
<bpel:assign validate="yes" name="Assign">
<bpel:copy keepSrcElementName="no">
<bpel:from>
<![CDATA[bpel:doXslTransform("test3.xsl", $personalInfoServiceOutput.parameters), "middle", $positionSkillManagementInput]]>
</bpel:from>
<bpel:to variable="positionSkillManagementInput"></bpel:to>
</bpel:copy>
</bpel:assign>
The signature of doXSLTransform looks as follows:
object bpel:doXslTransform(string, node-set, (string, object)*)
The first parameter is the name of the XSLT script, the second parameter is an XPath identifying the source document (e.g. a variable, part, nodeset, node). The third and the fourth parameter is a key-value pair, the string is the key and the object is the value. Those pairs are mapped into the script's parameter context so that you can access these values by their name in the script. There can be any number of these pairs.
The best resource to look up such things is the WS-BPEL 2.0 specification, doXSLTransform is described in Sect. 8.4
When I use the following code :
<bpel:copy keepSrcElementName="no">
<bpel:from>
<![CDATA[bpel:doXslTransform("parseSample.xsl", $output.payload)]]>
</bpel:from>
<bpel:to variable="output"></bpel:to>
</bpel:copy>
I also get the error, that first argument must be literal string.
But, when I deploy my service (with error) to wso2 bps, it works fine.
You can try with this.
I faced the same issue. Agree with NGoyal. Shows error in BPEL but works when deployed.

How do you specify range to end of list?

Consider the following statement:
process.text.readLines[3..<-1]
It seems like it should work. Essentially, strip off the first two elements of the array. However, the range operator is confused by the ending -1, since its less than -1. You can easily solve this problem by storing the array as a variable and replacing -1 with size() but that requires an extra line and the definition of a variable. Any other ideas how to express this easily?
I believe you could do:
process.text.readLines()[ 2..-1 ]
or:
process.text.readLines().drop( 2 )
This will also do the trick:
process.text.readLines().with { it[2..size()-1] }
It's longer than simply calling drop as suggested above, but it might read a little better depending on the larger context. with lets you get around defining a new variable.

Select substring between two characters in Scala

I'm getting a garbled JSON string from a HTTP request, so I'm looking for a temp solution to select the JSON string only.
The request.params() returns this:
[{"insured_initials":"Tt","insured_surname":"Test"}=, _=1329793147757,
callback=jQuery1707229194729661704_1329793018352
I would like everything from the start of the '{' to the end of the '}'.
I found lots of examples of doing similar things with other languages, but the purpose of this is not to only solve the problem, but also to learn Scala. Will someone please show me how to select that {....} part?
Regexps should do the trick:
"\\{.*\\}".r.findFirstIn("your json string here")
As Jens said, a regular expression usually suffices for this. However, the syntax is a bit different:
"""\{.*\}""".r
creates an object of scala.util.matching.Regex, which provides the typical query methods you may want to do on a regular expression.
In your case, you are simply interested in the first occurrence in a sequence, which is done via findFirstIn:
scala> """\{.*\}""".r.findFirstIn("""[{"insured_initials":"Tt","insured_surname":"Test"}=, _=1329793147757,callback=jQuery1707229194729661704_1329793018352""")
res1: Option[String] = Some({"insured_initials":"Tt","insured_surname":"Test"})
Note that it returns on Option type, which you can easily use in a match to find out if the regexp was found successfully or not.
Edit: A final point to watch out for is that the regular expressions normally do not match over linebreaks, so if your JSON is not fully contained in the first line, you may want to think about eliminating the linebreaks first.

Pass by reference problem with PHP 5.3.1 [duplicate]

This question already has answers here:
mysqli bind_param() expected to be a reference, value given
(3 answers)
Closed 12 months ago.
Ok, this is a weird problem, so please bear with me as I explain.
We upgraded our dev servers from PHP 5.2.5 to 5.3.1.
Loading up our code after the switch, we start getting errors like:
Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in /home/spot/trunk/system/core/Database.class.php on line 105
the line mentioned (105) is as follows:
call_user_func_array(Array($stmt, 'bind_param'), $passArray);
we changed the line to the following:
call_user_func_array(Array($stmt, 'bind_param'), &$passArray);
at this point (because allow_call_time_pass_reference) is turned off, php throws this:
Deprecated: Call-time pass-by-reference has been deprecated in /home/spot/trunk/system/core/Database.class.php on line 105
After trying to fix this for some time, I broke down and set allow_call_time_pass_reference to on.
That got rid of the Deprecated warning, but now the Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference warning is throwing every time, with or without the referencing.
I have zero clue how to fix this. If the target method was my own, I would just reference the incoming vars in the func declaration, but it's a (relatively) native method (mysqli).
Has anyone experienced this? How can I get around it?
Thank you.
I just experienced this same problem, calling bind_param via call_user_func_array and passing an array of parameters. The solution is to modify the values in the array to be referenced. It's not elegant but it works.
call_user_func_array(array($stmt, 'bind_param'), makeValuesReferenced($passArray));
function makeValuesReferenced($arr){
$refs = array();
foreach($arr as $key => $value)
$refs[$key] = &$arr[$key];
return $refs;
}
You are passing an array of elements ($passArray). The second item inside the passed array needs to be a reference, since that is really the list of items you are passing to the function.
Actually, be aware that there is a bug with PHP 5.3.1 concerning references and all call family of functions:
PHP Bugs #50394: Reference argument converted to value in __call
The behavior you are seeing might be a result of this bug and any attempt to fix it code wise may cause problems in the long run.
The problem has been fixed in the SVN version of PHP. Until 5.3.2 is released, you may compile a new version for use, or downgrade to an earlier version.
We were experiencing this same problem with this code:
call_user_func(array($strCartHandler, 'CartPurchaseEvent'), $strCartEvent, $objToUser, null, $this);
My solution was to just skip call_user_func altogether and do this:
$strCartHandler::CartPurchaseEvent($strCartEvent, $objToUser, null, $this);
I think what is deprecated is passing a reference through a function. In the function definition you do something like:
function(&$arg) {
}
This doesn't help you much but you probably need not pass the reference anyway. I guess you could try a wrapper function.
function wrapper($stmt, &$passArray) {
call_user_func_array($stmt, $passArray);
}
I think the mysqli_bind_param() and mysqli_bind_result() functions are very awkward to use. I've encountered the same difficulty as you describe using them in combination with call_user_func_array()
My workaround was to stop using mysqli and instead use PDO_mysql. It has a much easier usage:
$pdoStmt->execute( $passArray );
This will helps:
<?php
call_user_func_array(Array($stmt, 'bind_param'), array(&$passArray));
function bind_param ($val)
{
$val = (is_array($val)) ? $val[0] : $val;
// operations...
}
?>
The second paramer Must be an array. apparently this was only enforced in 5.3
I've got a similar problem, the current code didnt work:
$query="Select id,name FROM mytable LIMIT ?,?";
$params=Array('ii');
array_push($params,$from_var);
array_push($params,$to_var);
...
$stmt=$link->prepare("$query");
$ref=new ReflectionClass('mysqli_stmt');
$method=$ref->getMethod("bind_param");
$method->invokeArgs($stmt,$params);
...
It told that "Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given"
And then, in despair, I've tried to take $from_var and $to_var in quotes. And it worked!
$params=Array('ii');
array_push($params,"$from_var");
array_push($params,"$to_var");
Hope, it will help somebody, good luck :)

Resources