Loading different stylesheet based on your users location - java

I have a small issue.
Im trying to develop a solution with java that will allow me to load a specific stylesheet based on the users location.
I am not that well versed in scripting things myself and typically use jquery plugins.
If you could help me out with a little code to get me started or point me in the direction of some tutorials that would be of immense help.
Thanks

Have a look at http://www.jquery4u.com/tag/jquery-location-api/ together with http://www.geoplugin.com/webservices/javascript .There is a complete example on how to use it. When have the location then it's up to you how you want to add/change styling.

Actually could use a little more help wiht this one.
I created a quick else if statement that i would use to load the stylesheets based on the output of the geolocator.
<script type="text/javascript">
if (geoplugin_countryName() == CA) {
<link rel="stylesheet" type="text/css" href="main_css.css" media="screen" />
}
else if (geoplugin_countryName() == US) {
<link rel="stylesheet" type="text/css" href="main_css.css" media="screen" />
}
else if (geoplugin_countryName() == EU) {
<link rel="stylesheet" type="text/css" href="main_css.css" media="screen" />
}
</script>
If someone could take a look at this code and let me know if the syntax will work that would be awesome, as it stands im not too familiar with java.
Thanks

Related

Is there a way to declare a root resource for each jsp?

I have multiple spring MVC project that I will need to combine into one...
but say I have two folders of static resources that conflict, so i need to keep them separate:
What i do is declare two resource mapping:
<mvc:resources location="/resources/web1" mapping="/web1/**"/>
<mvc:resources location="/resources/web2" mapping="/web2/**"/>
and in my web1 jsp I do:
<link href="/web1/css/test.css" rel="stylesheet">
<link href="/web1/css/test1.css" rel="stylesheet">
<link href="/web1/css/test2.css" rel="stylesheet">
but what if i need to group my jsp, say i have web1a.jsp, web1b.jsp, web1c.jsp, and i want them all to use the web1/ resource mapping.
Is there a faster way to declare it, like a property that i can put on top of the JSP to declare that the root source is web1 instead of manually adding "web1/" for each tags? Something like:
all jsp that uses web1,
<%#root="web1/" %>
<link href="/css/test.css" rel="stylesheet">
<link href="/css/test1.css" rel="stylesheet">
<link href="/css/test2.css" rel="stylesheet">
so that i could retain the original reference without modifying each individual tags
thanks

Unable to understand how Playframework works

I installed playframework and have a question.I looked at the helloworld tutorial but it seems to use groovy.
#(message: String)
#main("Welcome to Play 2.1") {
#play20.welcome(message, style = "Java")
}
The first line is the function definition. What does play20 stand for. I am really new to Scala and I cant make head or tail out of it.
#(title: String)(content: Html)
<!DOCTYPE html>
<html>
<head>
<title>#title</title>
<link rel="stylesheet" media="screen" href="#routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="#routes.Assets.at("images/favicon.png")">
<script src="#routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script>
</head>
<body>
#content
</body>
</html>
This is just standard HTML which accepts html content and a title string. But how is this file getting called from the index.scala.html?
The #play20.welcome() part calls a Scala method, not that different from Java.
As for the HTML templates, they're compiled into Scala classes as well, a bit like JSP is compiled into servlets.
The example you are refering to sounds like it's about Play 1, while the framework you are trying out is play 2, which is a rather different thing. Play 2 has it's own template engine.
The # is the symbol that signals you're going to start a Scala expression. Like < ?php ? > or <% %> for intance in other langauges. The only difference is that you don't have a trailing symbol, because the template engine stops parsing at the end of the expression and automagicly returns to evaluating the template as html.
play20 is an object that is in scope for the template engine, like things in java.lang are in in scope in a regular java file. E.g. String.
In this case play20 is like a class with a static method in Java.
In this tutorial you have good simple introduction to how to use the Play 2 framework

Jquery Autocomplete token input does'nt work in safari and chrome

Autocomplete token input box works properly in IE and Firefox but it doesn't work in safari and crome.
this is a part of code
<script type="text/javascript" src="<%=path%>/js/jquery-1.4.4.min.js"></script>
//for auto complete
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jqueryAutocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jqueryAutocomplete/jquery.ajaxQueue.js"></script>
<link type="text/css" media="screen" rel="stylesheet" href="<%=request.getContextPath()%>/css/jqueryAutocomplete/jquery.autocomplete.css" />
$j(document).ready(function(){
$j("#id_CBRERegion").tokenInput(path + "fetchAutoCompleteResult.do?method=regionList", {
theme: "facebook",
queryParam: "search",
minChars: 1,
preventDuplicates: true,
hintText:"CBRE Region",
prePopulate: selRegCode
});
$j('#id_CBRERegion').prev().find("input").blur();
registerAutoEvent('id_CBRERegion','id_CBRERegion_Temp');
if(document.getElementById('id_CBRERegion').value != "") {
$j('#id_CBRERegion_Temp').hide();
} else if(document.getElementById('id_CBRERegion').value == "") {
$j('#id_CBRERegion_Temp').next().hide();
}
});
Please suggest..
I just visited http://jqueryui.com/demos/autocomplete/ in Chrome and Safari and it works.
Many factors could be causing the problem, from css to data.
Best way to resolve and learn the function.
start from a simple example off the site
Add in your bits slowly until you see it fail.

Regex to find <link rel="stylesheet" tag

I need to find the link tag using Regex.
I have this line in my html file.
<link rel="stylesheet" href="<c:url value="/styles/folders/masterTree.css" />" type="text/css" media="screen, print" />
I need a regex expression to find this.
This is not a homework. I need this as part of my office requirement.
Thanks to all in advance.
Using regex to parse html can be problematic as most (x)html is not actual valid.
Because of all the edge cases you end up with it breaking before long.
You don't specify what language you are developing in but if you are working in .net I would suggest looking into using HtmlAgilityPack:
http://runtingsproper.blogspot.com/2009/09/htmlagilitypack-article-series.html
You shouldn't. A real HTML parser is the only reliable way to parse HTML.

How to open print version of the site in a new page with jsf?

I need to make a link which opens print version of current page in a new tab. I already have correspondent css-file. But I don't know how to specify when this file should be used instead of standard.
The simplest way is quite good. If I was using JSP I would simply add get parameter to print-link URL. Is there any way to achieve similar results with jsf?
Use EL to specify the CSS file dynamically, here's an example which checks the presence of the print request parameter (thus, <h:outputLink value="page.jsf?print" target="_blank"> would suffice):
<link rel="stylesheet" type="text/css" href="${not empty param.print ? 'print.css' : 'normal.css'}" />
You can also retrieve it as a bean proprerty the usual JSF way:
<link rel="stylesheet" type="text/css" href="<h:outputText value="#{bean.cssFile}" /> " />
If you're on Facelets instead of JSP, then you can also use unified EL in template text:
<link rel="stylesheet" type="text/css" href="#{bean.cssFile}" />
If you actually don't need a "print preview" tab/page, then you can also just specify the media attribute in the CSS link and let the link/button invoke window.print() during onclick instead of opening in a new tab.
<link rel="stylesheet" type="text/css" href="normal.css" media="screen, handheld, projection" />
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
When the page is about to be printed, the one specified by media="print" will automatically be used instead.
You can add get parameters to any JSF link by using the f:param tag.
<h:outputLink value="/somepage.xhtml" target="_blank">
<h:outputText value="Link to Some Page"/>
<f:param name="someparam" value="somevalue">
</h:outputLink>
This will render something basically like this:
Link to Some Page
You can add multiple params with more f:param fields. Alternatively, if it's static, you can just add it as part of the outputLink itself.
<h:outputLink value="/somepage.xhtml?someparam=somevalue" target="_blank">
<h:outputText value="Link to Some Page"/>
</h:outputLink>
The problem, of course, being that you cannot do this and trigger server-side events. I've yet to figure out how to do this from a POST back and get it in a new tab.

Categories