In my struts 2.0.12 application I'm trying to use s:datetimepicker
but it does not render.
Firebug error: dojo is not defined
on dojo.require("dojo.widget.DatePicker");
My jsp page
<%#taglib prefix="s" uri="/struts-tags" %>
.
.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<s:head theme="ajax" debug="true"/>
.
.
</head>
<body>
.
.
<s:datetimepicker name="dataInizioRicerca" label="data inizio ricerca (yyyy-MM-dd)" displayFormat="yyyy-MM-dd"/>
.
.
</body>
What's wrong? Did I miss something?
For use datetimepicker you need to use struts-dojo-tags, this came into de struts-dojo-plugin.jar of struts library, now u have the tags, loaded whit
and put inside head tag
to visualize the date time picker....
... maybe this can help you....
Yes you missed the Ajax header (Ajax struts theme) tag.
This loads the Dojo Javascript files at the start of the page.
Put the following in your HTML head:
<head>
[..other stuff]
<s:head/> <!-- Struts 2 Ajax/Dojo needed for calendar -->
</head>
By the way - the above post talks about struts 2.1.x and not struts 2.0.12 (the one you are using)
I know it's a while since this thread was updated but if someone experiences the problem above and does a search they might end up here and the following observations may be useful.
I got similar issues when using Dojo with Struts 2.1 but that was down to the major changes in how struts 2 works with Dojo. A useful resource in sorting out those issues can be found here:
Toubleshootng guide for migrating from Struts 2.0.x to Struts 2.1.x
If getting Dojo working was still causing problems you could try using the Struts 2 jquery plugin, (do a search for that as I am not allowed to post 2 hyperlinks)
You need to stop using struts dojo tags and use dojo independently. struts -dojo is not supported any more.
Related
We are using CAS 5.2.3 which uses an upgraded version of Thymeleaf. Thymeleaf has restricted access to certain request features - '#request.getParameters()' being one. Is there any work around for it? I am getting the following error when trying to access it - "Access to request parameters is forbidden in this context. Note some restrictions apply to variable access. For example, direct access to request parameters is forbidden in preprocessing and unescaped expressions, in TEXT template mode, in fragment insertion specifications and in some specific attribute processors."
Good question. I face this problem a few months before, it is solvable.
After looking through their source code, I found that they are limiting the usage of #request.getParameters() only on specific tag, they didn't forbid to use #request.getParameters() in some situation.
In my use case, I am able to use CData to bypass this checking. Not sure whether it applies to your use case since you didn't provide any code example....
Anyway, the below example want to redirect user to another page, based on the parameter url
Here's an sample code that was broken in CAS 5.2.x, but worked in CAS 5.1.x :
<html>
<head>
<title> Deforestation </title>
</head>
<body th:attr="onload='window.location.href=\''+${#request.getParameter('url')}+'\''">
</body>
</html>
Here's a work around code:
<html>
<head>
<title> Deforestation </title>
</head>
<body>
Logging out. Please wait...
<script th:inline="javascript">
/*<![CDATA[*/
location.href = /*[[( ${#request.getParameter('url')} )]]*/ ;
/*]]>*/
</script>
</body>
</html>
If this didn't solve your problem, please provide your source code so we can have a better look at the problem.
Note: There is a security reason why this stuff is now banned, using this workaround might compromise the security standard, do remember to sanitize the user input if neccesary
Edit:
as per comment, although not elegant, maybe something like the following will work?
<html>
<head>
<title> Data attribute </title>
</head>
<body>
<span id="foobarid"> </span>
<script th:inline="javascript">
/*<![CDATA[*/
$('#foobarid').data('foo-bar',/*[[( ${#request.getParameter('foo') == 'bar'} )]]*/);
/*]]>*/
</script>
</body>
</html>
Apparently one can spend hours, even days on this simple requirement, which Thymeleaf introduced as a poorly dcumented annoyance in later versions. I've spent hours upgrading from an older Thymeleaf version from 5 years ago and got stuck on this very same problem. The lack of documentation didn't either. When I finally took a think break, I've realized the solution to this problem is as simple as using the <c:set> core tag with JSP.
Simply use the th:with tag in some higher level html tag where accessing request parameters is allowed, like this:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns="http://www.w3.org/1999/xhtml"
th:with="action=${param.action != null ?
param.action[0] : 'none'}">
<head>
...
In this example, the request parameter action is stored in a page context local variable named action (the name can be any unique name that you choose). This variable is now accessible anywhere bellow your high level html tag where you've defined it. It can even be used in following th:xx tags in the same html tag after the declaration. So basically, now you can do this:
<th:block th:switch="${action}">
<title th:case="'edit'" th:text="#{page.contacts.edit}"></title>
<title th:case="'delete'" th:text="#{page.contacts.delete}"></title>
<title th:case="*" th:text="#{page.contacts.add}"></title>
</th:block>
and even call a parameterized fragment by simply referring to your variable as ${action}. In this example I have a navbar template fragment, which accepts three parameters. The last of which, is a request parameter that otherwise, is inaccessible due to the newer Thymeleaf request object access restrictions.
<div id="wrapper">
<div class="nav" th:replace="html/fragments/navbar ::
navbar('html/contact','contact-html', ${action})">
</div>
<div class="content">
...
If you need more request params and more local page context variables, just use a comma to separate the declarations in the th:with tag like this:
th:with="action=${param.action == null ? 'none': param.action[0]},
self=${param.self == null ? 'none': param.self[0]}"
I hope this saves you guys some precious time and voids the frustration of refactoring older Thymeleaf html pages. It definitely beats those horrifically unmanageable CDATA scriptlets inside your pages.
I want to set language value of a gsp page dynamically . Currently I am just doing it using basic hardcoded value . I did find something with JS Onload event described here.
But I wanted to find something that is GSP driven . Is there any way ?
My current code looks like <html lang="en">
I think maybe you are thinking of this in a more complex way than it actuall is.
In grails you have your layouts/main.gsp which is your sitemesh.
The tag <html lang='en' is declared at the very top of this
If you simply edit this page and add the following:
<g:set var="locale" value="${session?.'org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE'?:java.util.Locale.UK}"/>
<html lang="${locale?.language?:'en'}" class="no-js">
Then when I visit my site:
localhost:8080/?lang=ja_JP view source shows:
<html lang="ja" class="no-js">
You need to do that for each sitemesh that requires to do this - having a read about this property it seems it doesn't do much for the browser but may help non human things such as search engines.
I'm loading achild *.xhtml file in my jsf page with ui:include. When I load this
<html>
<head/>
<body>
Testing
</body>
</html>
I get this error
One or more resources have the target of 'head', but no 'head' component has been defined within the view.
However - when I modify it to this:
<html>
<!-- <head/> -->
<body>
Testing
</body>
</html>
The error goes away. (The child *.xhtml file comes from a static content team so it can't have jsf directives in it).
What is the root cause? How can this be avoided?
Versions:
Mojarra 2.0
Java 7.0
Tomcat 7.0
Windows 7.0
It's talking about the <h:head>. Do the same for the body, which should be <h:body>.
By the way, the generated HTML output must be syntactically valid. You usually don't put <html> in an include file, but only in the parent file or the master template.
See also:
How to include another XHTML in XHTML using JSF 2.0 Facelets?
When to use <ui:include>, tag files, composite components and/or custom components?
What's the difference between <h:head> and <head> in Java Facelets?
How to programmatically add JS and CSS resources to <h:head>?
What is the JSP equivalent of ASP.NET MVC's partial views?
I'd like to separate some complicated view logic out of a page into a separate page that only handles that logic. How can I render that page as part of my page?
There isn't. JSP is not a fullworthy equivalent of ASP.NET MVC. It's more an equivalent to classic ASP. The Java equivalent of ASP.NET MVC is JSF 2.0 on Facelets.
However, your requirement sounds more like as if you need a simple include page. In JSP you can use the <jsp:include> for this. But it offers nothing more with regard to templating (Facelets is superior in this) and also nothing with regard to component based MVC (there you have JSF for).
Basic example:
main.jsp
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<h1>Parent page</h1>
<jsp:include page="include.jsp" />
</body>
</html>
include.jsp
<h2>Include page</h2>
Generated HTML result:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<h1>Parent page</h1>
<h2>Include page</h2>
</body>
</html>
See also:
What is the Java alternative to ASP.NET/PHP?
Analogues of Java and .NET technologies/frameworks
What is the difference between JSF, JSP and Servlet?
I had a grails 1.1 app working where keyword and description meta tags were dynamically generated. There was a change in how that works in 1.2, but I cannot found good documentation. I've tried numerous ways to make it work. No matter what I do the resultant html gets something like
<meta name="keywords"/>" />
instead of the actual keywords. The extra tags there are not a typo on my part. So it also creates a bug in my rendered html.
In Grails 1.2, there's a performance optimized integration to Sitemesh. You can use the old implementation if you specify grails.views.gsp.sitemesh.preprocess = false in Config.groovy.
There are several issues in Grails JIRA related to meta tags :
http://jira.codehaus.org/browse/GRAILS-5605
http://jira.codehaus.org/browse/GRAILS-5598
http://jira.codehaus.org/browse/GRAILS-5696
Some of them will be fixed in Grails 1.2.1 .
I have had problems in 1.2 with meta tags dynamically generates and found that the problems happened when the quote was followed by a $. If I put a space between the quote and the $ it worked like
<meta name="keywords" value=" ${keywords}"/>
May or may not be your problem...