One quick question.
How can I use the "simple theme" () and "dojo datetimepicker" () together?
I have read that if you only want to use the simple theme, then manually import all the required dojo files using the code in head.ftl...
The thing is all those js are in struts dojo jar file which is included in the class path. How can I include them in the jsp? What should be the whole path? Any example will be helpful.
Performance Tuning
1. Enable Freemarker template caching
In Struts versions prior to 2.0.10,
you had to copy the /template
directory from the Struts 2 jar in
your WEB_APP root to utilize
Freemarker's built in chaching
mechanism in order to achieve similar
results.
The built in Freemarker caching
mechanism fails to properly cache
templates when they are retrieved from
the classpath. Copying them to the
WEB_APP root allows Freemarker to
cache them correctly. Freemarker looks
at the last modified time of the
template to determine if it needs to
reload the templates. Resources
retrieved from the classpath have no
last modified time, so Freemarker will
reload them on every request.
2. When overriding a theme, copy all necessary templates to the theme
directory.
There's a performance cost when a
template cannot be found in the
current directory. The reason for this
is that Struts 2 must check for a
template in the current theme first
before falling back to the parent
theme. In the future, this penalty
could be eliminated by implementing a
missing template cache in Struts 2.
Example
YourWebApp
|-- WebContent
|-- templates
|-- ajax
|-- controlheader.ftl, datetimepicker.ftl, dojoRequire.js, head.ftl
|-- simple
|-- [All files]
|-- xhtml
|-- controlfooter.ftl, controlheader-core.ftl, controlheader.ftl, tooltip.ftl, validation.js
<struts>
<constant name="struts.ui.templateDir" value="templates" />
<constant name="struts.ui.theme" value="simple" />
</struts>
<%# taglib prefix="sx" uri="/struts-dojo-tags" %>
<head>
<sx:head />
</head>
<body>
<sx:datetimepicker name="date" />
</body>
The Datetimepicker of Ajax Tags is bad, did you consider jQuery UI Timepicker/Datetimepicker?
Related
I have two html files, one contains a navbar and a sidebar. I would like to include that to another html file using thymeleaf.
Now I use jquery, the following way:
<script src="jquery.js"></script>
<script>
$(function(){
$("#includedCommonParts").load("/common_webpage_parts.html");
});
</script>
...
<div id="includedCommonParts"></div>
So I need the two html files merged to one, using only thymeleaf. I cannot use php, and I shouldn't use jquery either.
My file structure is the following:
├───public
│ common_webpage_parts.html
│ jquery.js
│ main.js
│
└───templates
login.html
users.html
The common_webpage_parts.html should be included in users.html
The common_webpage_parts.html contains multiple divs and css tags in <style> tags, so I don't want to include divs one-by-one.
This is a spring project by the way.
Thank you!
Ideally use thymeleaf layout dialect as Metroids commented: thymeleaf layout dialect, chapter 4. This is the best solution to avoid duplicated work in every file (which is prone to error) and to achieve cleanliness.
Alternatively (for example once I couldn't add the layout dialect library due to project restrictions), you can place each common part in the common_webpage_parts.html file inside <th:fragment> tags and load them with <th:include> or <th:replace> in your other html files wherever you need them. You can look at this is done in thymeleaf standard layouts, chapter 3.
I'm a Grails 2.x developer and I'm trying to jump to Grails 3.x and Java 8. But I feel disappointed with the scaffolding process results. It generates these views (GSP files): create.gsp, edit.gsp, show.gsp and index.gsp.
So, some things have changed:
The form.gsp file is missing. I think it's been replaced (to
generate the form) in the create.gsp and edit.gsp files with this code: <f:all bean="myDomainClass"/>.
IMHO this is really sad. Customizing our forms is the most natural
thing.
The same has happened with the show.gsp and index.gsp files, replacing the customizable generated code with <f:display bean="myDomainClass" /> and <f:table collection="${myDomainClassList}" /> respectively.
So, how can I customize the form or generate a form.gsp like file? How can I customize the show.gsp and index.gsp files? Is there a way to generate views as Grails 2.x does? Can we avoid the usage of <f:all />, <f:display /> and <f:table/> tags?
I have a Durandal 2 app based on ASP.NET MVC 5 and Web API, with the initial Index.cshtml (on HomeController) being served through the MVC router. From then on it's all regular html views being handled by the Durandal router.
Anyway, I'm trying to use gulp-useref to concatenate all css and js files. I've got everything working and gulp-useref drops the newly concatenated files and an index.cshtml with the updated script and stylesheet references in a dist folder.
Of course, for the application to work I need the updated index.cshtml back in Views/Home/. I have created a "copy" task with gulp that does just that; it overwrites the original index.cshtml and fixes the paths to the concatenated js and css files.
That works as well, but since useref removes the html comments that mark the spot where it should insert the references to the concatenated files, the process is not repeatable.
Let me illustrate with some code.
In my Index.cshtml I have:
<html>
<head></head>
<body>
<!-- build:js js/lib.js-->
<script src="/bower_components/numeral/languages.js"></script>
<script src="/scripts/bootstrap.js"></script>
<script src="/scripts/typeahead.js"></script>
<script src="/scripts/knockout-bootstrap.js"></script>
<script src="/scripts/knockout-extenders.js"></script>
<!-- endbuild -->
</body>
</html>
This is where gulp-useref will place the updated script reference so it will end up looking like this:
<html>
<head></head>
<body>
<script src="/js/lib.js"></script>
</body>
</html>
As you can see, useref removes the html comments so if I overwrite the original index.cshtml with this file, useref will not know where to place the updated script tag. And if I don't overwrite the original index.cshtml, the application will not be using the concatenated files.
I'm new to gulp so I might be going at this in the completely wrong way, but how can I make sure that my /Views/Home/index.cshtml uses the concatenated files in an automated manner?
Or, alternatively, is there a better approach for what I'm trying to do, namely, get everything ready for deployment?
Here are my relevant gulp tasks, for reference:
gulp.task("optimize-for-deployment", function () {
var assets = $.useref.assets({ searchPath: "./" });
var cssFilter = $.filter("**/*.css");
var jsFilter = $.filter("**/*.js");
return gulp
.src(config.index)
.pipe($.plumber())
.pipe(assets)
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(assets.restore())
.pipe($.useref())
.pipe(gulp.dest(config.appDist));
});
// copy the updated index.cshtml to Views/Home/
gulp.task("copy-for-deployment", ["optimize-for-deployment"], function () {
return gulp.src(config.appDist + "index.cshtml")
.pipe($.replacePath(/js\/lib.js/, "/app/dist/js/lib.js"))
.pipe($.replacePath(/style\/app.css/, "/app/dist/style/app.css"))
.pipe(gulp.dest(config.indexLocation));
});
Don't know if this is 'better' approach or the best solution but you could use something like a template for your index file. So you would have an Index-template.cshtml with al your html comments which you use to create your Index.cshtml every time in your gulp tasks.
This way you can overwrite your Index.cshtml and keep your template with al your html comments.
I am new to .net mvc and trying to do the exact thing Sergi. If you modified the default view location scheme to include your dist folder (How to change default view location scheme in ASP.NET MVC?), would .net know to include the dist folder and compile those .cshtml files?
I use <link type="text/css" href="${resource(dir: 'css', file: 'calender.css')}" />
i don't know why this tag not working.
I have to go back to my recent projects because this is something you set up once and never need to change again. I usually use this line at the top of my gsp files:
<link rel="stylesheet" type="text/css" href="<g:createLinkTo dir='css' file='style.css'/>" />
But for this to work just double check that you have the CSS directory inside web-app:
<YourProject>
|--> web-app
|--> css
|--> images
|--> js
|--> META-INF
|--> WEB-INF
That is normally the directory structure that Grails expects when you tell it to build your WAR file.
This is not how you're supposed to include CSS files in a page when using the resources plugin. You're supposed to define resource bundles/modules in a file grails-app/conf/AppResources.groovy. Then you use the r:require tag to include whole modules in your page. See the resource plugin docs for more details.
Please use this it will solve your problem:-
<g:resource dir="css" file="calender.css" />
For further information go to grails documentation: click here
in my grails app, I'm using the awesome resource plugin which wires all the dependencies. When I'm doing the ajax calls I always use <r:layoutResources disposition="defer"/> in order to render all scripts <r:script>... and other dependencies property.
The problem is if I use <r:require module="myModule"/> and the module specify a JS file which was not loaded before (when the page was not loaded). After the AJAX call the JS file is not loaded, what is more or less expected because all JS file should be loaded when the page is rendered.
My question is how to solve it properly? Should I put my r:require to the gsp which is rendered during the first request? Or are there any plans to make the r:require deal with "external" JS files when AJAX?
Thanks,
Mateo
Create a layout ajaxInternal.gsp and put in something like:
<r:require module="gaScript" />
<r:layoutResources />
<g:layoutBody />
<r:layoutResources disposition="defer" />
And in your ajax action of controller render this:
render(template:"aTemplateIfRequired", model:[yourModel],layout:'ajaxInternalContentBox')
So all your js will work properly and all your modules also.