How to get an xsp value from URL link using Java - java

I am trying to retrieve the page name(.xsp)from the URL of the current page using Java. i have been able to accomplish the same thing with the Javascript below
context.getUrl().getSiteRelativeAddress(context).toString()
and it works but i want to get the same thing don using Java.

The best way to get SSJS variable names via Java is resolveVariable. This should work:
XSPContext context = (XSPContext) ExtLibUtil.resolveVariable(FacesContext.getCurrentInstance(), "context");
String pageName = context.getUrl().getSiteRelativeAddress(context).toString();
(Updated with correct syntax for second line, thanks Knut)

Related

queryString to java parameter

So what I am trying to do was getting the url queryString to a value in java as a string, I looked up couples of solution and try it out nothing works for me.
One of the solution I tried:
Parse a query string parameter to java object
In the URL I got something like this:
http://www.somethingCool.com?AreYouCool=Y
How do I get AreYouCool as a java String
Use Pattern and Matcher classes to get the key part.
Pattern.compile("(?<=\\?).*?(?==)");
DEMO
String YouCool=(String) request.getParameter("AreYouCool")
works

How to combine two urls in selenium webdriver

I have declared two variable for url as below
Url = vars.get("http://stackoverflow.com");
url1 = vars.get("/questions");
driver.get(Url + Url1);
When I am executing it, it is opening a web browser but there is no url address in the browser and nothing is happening. Could you please let me know where I am wrong?
I think it is easiest to do if you put both urls like Strings as this:
Url = "http://stackoverflow.com";
url1 = "/questions";
And then you can combine both Strings with "+" simbol:
driver.get(Url + Url1);
But what it's exactly vars? Can you explain it please?
EDIT: .get method in Selenium Webdriver needs a String in their declaration to works properly. Look at this: http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#get-java.lang.String-
Key methods are get(String), which is used to load a new web page, and the various methods similar to findElement(By), which is used to find WebElements.

manipulate the JSON object converted from a java Map

Inside my action I've computed a json object from a map and I get:
{"angleEqual(angle(a,d,c),angle(a,e,b)).":{"allLinesId":"['DA','CD','AE','BE']","numberOfLinesWithinAGroup":2}}
When it comes to the front end it looked fine under the chrome debugging console, however, (driving me mad!!) how do I get the content of the value under the attribute of allLinesId and display, I thought it should be straightforward to do:
var object= data.angleEqual(angle(a,d,c),angle(a,e,b)).;
object.allLinesId;
object.display;
Not worked out as a solution, thanks a lot if anyone can help.
Try the bracket notation.
var object = data['angleEqual(angle(a,d,c),angle(a,e,b)).'];
object.allLinesId;
object.display;

get all values using get paremeters in java

I'm passing the some values url from flex to java example:
URL format:
../mahesh/initUser.do?method=fwdAccDetails&securityId=mUuB3/p/ky5JhZPY5T8Znf01YCcIarIalQiGEXPMMsOkWDX+KtT4fx2gMML+uup8
After I'm tiring to get "securityId" values in java like
request.getParameter("securityId")
But I'm getting following values only
mUuB3/p/ky5JhZPY5T8Znf01YCcIarIalQiGEXPMMsOkWDX KtT4fx2gMML uup8
symbol getting empty space in java side..
Here is my Flex code:
navigateToURL(new URLRequest('../mahesh/initUser.do?method=fwdAccDetails&securityId='+value+'),'_s‌​elf');
I didn't get full values.. any one can help me how I will get correct values in Java..
You should use the encodeURIComponent()-Function to properly encode your securityId.
value = encodeURIComponent(value);
navigateToURL(new URLRequest('../mahesh/initUser.do?method=fwdAccDetails&securityId='+value+'),'_s‌​elf');
That way your String will be correct on the Java side.
If you want to read more about proper escaping, have a look at When are you supposed to use escape instead of encodeURI / encodeURIComponent? (Same arguments apply for Flex and JavaScript).
i just resolve my issue for following code in a javURLDecoder.decode(param1AfterEncoding.replace("+", "%2B"), "UTF-8").replace("%2B", "+")
Now its working fine only.. i dint other special character will work fine.. i will check it later..

How do I reverse route a static file?

At first I had this link to a twitter icon:
#{'/public/images/twitter-icon.png'/}
But now I want to show a Twitter-, Facebook- or LinkedIn icon depending on type. So, I created a FastTag that takes the type as a parameter and the code looks like this:
In the view:
#{myApp.icon contact.type/}
FastTag Java Code:
String type = (String) args.get("arg");
out.print("/public/images/" + type + "-icon.png");
It works fine. But, on our build server we run the app with a prefix on the uri like this
http://ourdomain.com/appname/...
Obviously /public/images... won't work here. So I figured I have to ask the Router for the proper address. I've tried the following with no success:
Router.reverse("/public/images/" + type + "-icon.png");
Router.reverse("/public/");
Router.reverse("staticDir:public");
All three result in a NoRouteFoundException. How can I get the correct route for my icons?
In the routes file I have the default route for static files
GET /public/ staticDir:public
I believe this is what you want:
String imageUrl = Router.reverse(VirtualFile.fromRelativePath("public/images/" + type + "-icon.png"));
Router.reverse be used generate URL form one action!
maybe you can define a route which include your app name and route one action eg:
GET /appname/public/ TestController.test
now,you can use
Router.reverse("TestController.test")
get the URL.
I think it's better to do something like:
GET /img/ staticDir:public/images
And in the template just:
out.print("/img/" + type + "-icon.png");

Categories

Resources