Passing nullable parameters to a Page via PageParameters in Wicket 6 - java

I need to pass a parameter to my page and I can't find a way to pass parameters that might be null.
If I do:
PageParameters pageParameters = new PageParameters ();
pageParameters.add ("key", null);
This will result in an exception
java.lang.IllegalArgumentException: Argument 'value' may not be null.
at org.apache.wicket.util.lang.Args.notNull(Args.java:41)
If I use Google Guava's Optional, I can't find any way to cast the object even if the the Optional object is not holding a null ie not equals to Optional.absent() :
In my landing page's constructor I do
StringValue sv = parameters.get ("key");
sv.to ( Optional.of (MyEnum.SOME_ENUM_CONSTANT).getClass () );
and when I run it I get this error:
org.apache.wicket.util.string.StringValueConversionException: Cannot
convert 'Optional.of(SOME_ENUM_CONSTANT)'to type class
com.google.common.base.Present.
Am I doing something wrong?
Is there any other way to pass a possibly null object in wicket 6?
I noticed in wicket 1.4 they have PageParameters.NULL which seems to have dissapeared in wicket 6.
Thank you

This might be too simple, but what's wrong with
Object value = ?
if (value != null) {
pageParameters.add ("key", value);
}
and
StringValue sv = pageParameters.get("key");
if (!sv.isNull()) {
// process string value
}

All page parameters in wicket will be treated as Strings eventually. The idea is that a page parameter will be on the URL of the request.
From the javadoc:
Suppose we mounted a page on /user and the following url was accessed /user/profile/bob?action=view&redirect=false. In this example profile and bob are indexed parameters with respective indexes 0 and 1. action and redirect are named parameters.
If you add something like x=y&x, the parameter x will appear twice, once with the String y and another with the empty string.
Depending on what you are trying to accomplish I would suggest to either
Don't pass the parameter at all when there is a null value required and use the isNull or toOptional methods.
Use indexed parameters and test for presence of a certain word

Related

Unable to get a variable value in drools and use it to set in another field

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.

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 ");

JSP Request Parameter truncated after passing to javascript function

I have an issue with a parameter that I'm trying to pass into a Javascript function where the parameter gets cut off.
In my Servlet, I have set a parameter request.setAttribute("questions", service.getQuestions("123"))
It sets a list of questions with each question containing several values;
I loop through them with a JSTL loop <c:forEach var="data" items="${questions}">...</c:forEach> which I can then access the values as so ${data.question}, ${data.options} etc.
console.log(${data.question}) returns a value of the form 123,45,35|43,94,73|23,91,34 which is as expected.
But when I try to pass this ${data.question} into a javascript function such as <script>MyFunction(${data.question})</script>, it only receives 123.
MyFunction(data) {
console.log(data); //Only shows 123
//Split the string into arrays for processing
}
You receive first element becouse your function expect one parameter, and your value 123,45,35|43,94,73|23,91,34 is split by comma so it looks for function like diferent parametrs. Use arguments property insted or pass all value as string in '' like this
<script>MyFunction('${data.question}')</script>
Sorry for my english.. still working on it

InnerHTML doesn't brings the value to servlet

cell = this.getElementsByTagName("td")[3];
uname = cell.innerHTML;
i get the value of the particular cell through innerHTML and pass that value to Servlet
xmlhttp.open("POST","UserServlet",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("uname="+uname);
in Servlet
uname = request.getParameter("uname");
out.print(uname);
System.out.println(uname);
i get "undefined" in console.......
is there any way get the value and pass that to servlet
i tried .innerHTML,.innerText,.value nothing worked,i tried in array too....but nothing worked......Help me thanks in advance.....
Please refer to https://stackoverflow.com/a/15312976/1031191. That implies that your xmlhttp code is just fine. Try and use javascript console in the browser to verify that uname is a string and contains the right data.
Receiving "undefined" means that the value of uname is exactly "undefined" on the client side. See getParameter's reference: http://docs.oracle.com/javaee/1.3/api/javax/servlet/ServletRequest.html.
It says that you must receive either a String or null. (so in your case the argument of xmlhttp.send() is "uname=undefined" for some reason.)
UPDATE 2:
Probably you need document.getElementsByTagName('td')[3] instead of "this".
But hey, if you use jQuery anyway, why don't you write $('td').get(3) instead of getElementsByTagName?
UPDATE 3:
I think you have less than 4 td elements in your html. Please note that javascript arrays are indexed from 0. You receive "undefined" if you accidentally try to access an index in an array that is out of bounds.

Get param from html to java function call

I am working with a java generated dynamic webpage, and I'm printing links from a query to a JDO. But I don't understand how can I get and use the parameter from the url.
My html objects are printed like this
print = print + "Nome:<a href='displayFotos?album="+results.get(i).nome+ "'>"+
results.get(i).nome+ "</a></br>";
The results in having for example:
Nome:<a href='displayFotos?album=album1'>album1</a>
So, in my head when clicked it should be calling the address of the dynamic webpage album like this and should get the parameter. In this case it would be the album1.
else if (address.indexOf("/dinamicas/album") != -1) {
String album = param1;
System.out.println("did it work? "+album);
}
And I have in the beginning of the class a general parameter that I use to get text from html forms.
String param1 = req.getParameter("param1");
I understand this might be an easy question but I'm not getting there by myself.
Nome:<a href='displayFotos?album=album1'>album1</a>
Here, you're using a parameter name of album.
However, you're attempting to get it by a parameter name of param1. This does obviously not match.
String param1 = req.getParameter("param1");
You need to use the same parameter name as is been definied in the request.
String album = req.getParameter("album");
// ...

Categories

Resources