How do you include twitter bootstrap with spring mvc? - spring

I have spring mvc supplied text boxes and buttons in form page how to include twitter bootstrap in those tags. Where do I place bootstrap related files in the folder structure and which jar do I required to use bootstrap?
Example text boxes are:
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<form:form method="post" commandName="stdcmd">
username:<form:form path="txtUname">
password:<form:form path="txtPwd">
<input type="submit" value="register"/>
</form:form>

To use the bootstrap, you need to place the bootstrap files in the web folder. For example, resources/bootstrap folder. Then add the link to those files in jsp like:
<link rel='stylesheet' href='resources/bootstrap/bootstrap.min.css'>
<script type="text/javascript" src="resources/bootstrap/bootstrap.min.js"></script>
Also on your spring config file include this one:
<mvc:resources mapping="/resources/**" location="/resources/bootstrap
Check this link for more info
You should be able to access the classes from bootstrap and apply in your jsp.

Related

How to make spring mvc app run under a sub folder

I was only testing my spring-mvc as a root app on top of tomcat 7.0.50, now however I need to run at under a subfolder of the domain, like www.blabla.com/myapp
Unfortunately it does not work: all the resource files are missing and the application tries to redirect itself to root all the time.
How do i configure a spring mvc application to run under a subfolder?
I think it depends on your configuration of your HTTP Server (Apache, Nginx) and it has nothing to do with Spring.
The basic problem was that all references (including form actions) in jsp pages are absolute (a least with my current configuration) and I had to c:url them.
static resources:
<link href="<c:url value="/resources/css/bootstrap.css"/>" rel="stylesheet" type="text/css"/>
form actions:
<c:url var="proceedActionUri" value="/user/mainscreen"/>
<form:form method="post" action="${proceedActionUri}" commandName="user" role="form">

How to share JSP pages in more then one project?

I am trying to find a way to share JSP pages in more then one page?
Example we have the following projects:
commmon
projectA
projectB
The common project has all the CSS, images and two JSP pages. header.jsp and footer.jsp which all the projects in my firm is going to use.
We try adding:
<jsp:include page="/common/webapphead.jsp" />
to projectA and projectB but it still cant find the header, But if I goto
http://127.0.0.1:8080/common/webapphead.jsp
The page does display.
An easy way is to use JSTL. Use the c:import tag.
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:import url="http://127.0.0.1:8080/common/webapphead.jsp" />
Alternatively if you can enable cross context access, then you could use
<c:import url="/webapphead.jsp" context="/common" />
Look at
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Common_Attributes

Using Spring's theme resolvers and themes with a Thymeleaf template

I would like to use Spring theme resolvers' feature (see: here) in my Thymeleaf template.
What is the Thymeleaf's equivalent to the spring:theme JSP tag?
See JSP code sample below:
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<link rel="stylesheet" href="<spring:theme code='styleSheet'/>" type="text/css"/>
</head>
<body style="background=<spring:theme code='background'/>">
...
</body>
</html>
I don't think this was the case at the time that you asked your question, but the current version of thymeleaf-spring3 (2.0.18 as of this writing) has as part of the SpringStandard dialect a themes function, which can be used like this:
<body th:style="'background-color: ' + ${#themes.code('backgroundColor')}">

Spring form tag and HTML 5 still incompatible?

I am using a spring form tag
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<form:input path="name.lastName" cssClass="text" maxlength="30"/>
When I try to add the new required html5 attribute
<form:input path="name.lastName" required="required" cssClass="text" maxlength="30"/>
I get this error message when the jsp is converted to html
<pre>org.apache.jasper.JasperException: /WEB-INF/pages/admission/registration/patientForm.jsp(168,5) PWC6131: Attribute required invalid for tag input according to TLD
Are the springframework tags ready for html 5 ? If yes, how do i use them ?
I am using spring 2.5
Ok so I researched a bit more and I found out that I need to upgrade to spring mvc 3.

Spring tags and facelets

Can I use Spring tags with facelets? I have one JSP page, and there is a directive:
<%# taglib prefix="s" uri="http://www.springframework.org/tags"%>
Then I can insert the tag <s:theme code='css' /> (I'm using theme resolver.) Now I need to use theme resolver in another project using facelets instead JSP. There is a namespace declaration instead the JSP directive, isn't?
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:em="http://java.sun.com/jsf/composite/emcomp"
xmlns:st="http://www.springframework.org/tags">
But in Eclipse the namespace is labeled with the warning marker and on server it does not work, because the tag library is missing, althought I have put the library Spring Web MVC in the lib directory of Eclipse Internal Glassfish server. The JAR really contains META-INF/spring.tld.
I'm unable to find, what's wrong.
No, unfortunately you cannot. Spring tags are based on a JSP taglib. Facelet taglibs are different from JSP taglibs. The reason you can use the old-fashioned jsp core tags (c:forEach etc) in facelets is because they have been ported to facelet taglibs. AFAIK, there has not been any port done yet of the Spring JSP taglib to a facelet taglib.

Resources