Spring boot +taglibs+ java.util.NoSuchElementException - spring-boot

I am using Spring Boot with web mvc tiles. Also using Bootsrap CSS for front end
I have a main layout page named basic.jsp as
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<title><tiles:getAsString name="title" /></title>
</head>
<body>
<!-- Header -->
<tiles:insertAttribute name="header" />
<!-- Body -->
<tiles:insertAttribute name="body" />
<!-- Footer -->
<tiles:insertAttribute name="footer" />
</body>
</html>
and the tiles.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<!-- Templates -->
<definition name="layout.basic" template="/pages/layout/basic.jsp">
<put-attribute name="header" value="/pages/jsps/header.jsp" />
<put-attribute name="leftmenu" value="/pages/jsps/lmenu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/pages/jsps/footer.jsp" />
</definition>
<!-- Pages -->
<definition name="home" extends="layout.basic">
<put-attribute name="body" value="/WEB-INF/tiles/view/home/home.jsp" />
</definition>
<definition name="greet" extends="layout.basic">
<put-attribute name="body" value="/WEB-INF/tiles/view/home/register.jsp" />
</definition>
</tiles-definitions>
I want to include the spring form taglib in my register.jsp
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<div>
<div class="col-md-9 personal-info">
<form:form method="POST" id="frm" class="form-horizontal" role="form" commandName="box" action="Register">
<div class="form-group">
<label class="col-lg-3 control-label">Box Id:</label>
<div class="col-lg-8">
<form:input class="form-control" path="strBoxId" type="text" placeholder="Box Id"></form:input>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Box Name:</label>
<div class="col-lg-8">
<form:input class="form-control" type="text" path="strBoxName" value="" placeholder="Box Name"></form:input>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Address:</label>
<div class="col-lg-8">
<form:textarea class="form-control" placeholder="Address" path="strAddress"></form:textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input type="submit" class="btn btn-primary" id="register" value="Register" onclick="callMe()">
<span></span>
<input type="reset" class="btn btn-default" value="Cancel">
</div>
</div>
</form:form>
</div>
</div>
When I am running the application without including the taglib it is displaying the form, but when I am including the taglib in register.jsp, It is throwing error in cosole as well as Whitelabel Error Page in browser. Th error displayed is
2015-03-05 15:23:45.296 ERROR 8056 --- [nio-8080-exec-8] o.a.c.c.C.[. [localhost].[/].[jsp] : Servlet.service() for servlet jsp threw exception
java.util.NoSuchElementException: null
at java.util.ArrayList$Itr.next(Unknown Source)
at org.apache.jasper.compiler.Validator$ValidateVisitor.getJspAttribute(Validator.java:1385)
at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1262)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:876)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1538)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2429)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:895)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1538)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2429)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2435)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1841)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:217)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:688)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:682)
at org.apache.tiles.request.jsp.JspRequest.doInclude(JspRequest.java:123)
at org.apache.tiles.request.AbstractViewRequest.dispatch(AbstractViewRequest.java:47)
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:47)
at org.apache.tiles.request.render.ChainedDelegateRenderer.render(ChainedDelegateRenderer.java:68)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:188)
at org.apache.tiles.template.InsertAttributeModel.execute(InsertAttributeModel.java:132)
at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:299)
at org.apache.jsp.pages.layout.basic_jsp._jspx_meth_tiles_005finsertAttribute_005f2(basic_jsp.java:198)
at org.apache.jsp.pages.layout.basic_jsp._jspService(basic_jsp.java:112)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
at org.apache.tiles.request.servlet.ServletRequest.forward(ServletRequest.java:265)
at org.apache.tiles.request.servlet.ServletRequest.doForward(ServletRequest.java:228)
at org.apache.tiles.request.AbstractClientRequest.dispatch(AbstractClientRequest.java:57)
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:47)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:397)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:221)
at org.apache.tiles.renderer.DefinitionRenderer.render(DefinitionRenderer.java:59)
at org.springframework.web.servlet.view.tiles3.TilesView.renderMergedOutputModel(TilesView.java:114)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:8 37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1720)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
I don't know where it went wrong. Kindly help :(

Oh God!!! I wasted 3 hours in finding the solution. Thanks to the reply from 'guido' Spring boot taglibs
I just changed my spring boot version to 1.2.2.RELEASE and it worked !!!

Related

Spring Security error before logging in

I'm using thymeleaf 3.0.7 nad Spring security and trying to make a webapp. Logging and creating accounts runs well but before logging (viewing page as anonymous) i'm getting errors as below:
2018-07-24 21:09:19.124 [http-bio-8090-exec-7] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][http-bio-8090-exec-7] Exception processing template "error/general": An error happened during template parsing (template: "ServletContext resource [/WEB-INF/views/error/general.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "ServletContext resource [/WEB-INF/views/error/general.html]")
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:355)
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:188)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1325)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:489)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:467)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:338)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "#authorization.expression('isAuthenticated()')" (template: "fragments/layout" - line 34, col 21)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
... 34 common frames omitted
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#authorization.expression('isAuthenticated()')" (template: "fragments/layout" - line 34, col 21)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:290)
at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:165)
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:109)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138)
at org.thymeleaf.standard.expression.NegationExpression.executeNegation(NegationExpression.java:149)
at org.thymeleaf.standard.expression.ComplexExpression.executeComplex(ComplexExpression.java:86)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:112)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138)
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:125)
at org.thymeleaf.standard.processor.StandardIfTagProcessor.isVisible(StandardIfTagProcessor.java:59)
at org.thymeleaf.standard.processor.AbstractStandardConditionalVisibilityTagProcessor.doProcess(AbstractStandardConditionalVisibilityTagProcessor.java:61)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95)
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633)
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314)
at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205)
at org.thymeleaf.engine.Model.process(Model.java:282)
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1587)
at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleOpenElementEnd(TemplateHandlerAdapterMarkupHandler.java:304)
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleOpenElementEnd(InlinedOutputExpressionMarkupHandler.java:278)
at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleOpenElementEnd(OutputExpressionInlinePreProcessorHandler.java:186)
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleOpenElementEnd(InlinedOutputExpressionMarkupHandler.java:124)
at org.attoparser.HtmlElement.handleOpenElementEnd(HtmlElement.java:109)
at org.attoparser.HtmlMarkupHandler.handleOpenElementEnd(HtmlMarkupHandler.java:297)
at org.attoparser.MarkupEventProcessorHandler.handleOpenElementEnd(MarkupEventProcessorHandler.java:402)
at org.attoparser.ParsingElementMarkupUtil.parseOpenElement(ParsingElementMarkupUtil.java:159)
at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:710)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301)
... 36 common frames omitted
Caused by: java.lang.IllegalArgumentException: Authentication object cannot be null
at org.springframework.security.access.expression.SecurityExpressionRoot.<init>(SecurityExpressionRoot.java:61)
at org.springframework.security.web.access.expression.WebSecurityExpressionRoot.<init>(WebSecurityExpressionRoot.java:36)
at org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler.createSecurityExpressionRoot(DefaultWebSecurityExpressionHandler.java:43)
at org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler.createSecurityExpressionRoot(DefaultWebSecurityExpressionHandler.java:33)
at org.springframework.security.access.expression.AbstractSecurityExpressionHandler.createEvaluationContext(AbstractSecurityExpressionHandler.java:66)
at org.thymeleaf.extras.springsecurity4.auth.AuthUtils.authorizeUsingAccessExpression(AuthUtils.java:194)
at org.thymeleaf.extras.springsecurity4.auth.Authorization.expression(Authorization.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:120)
at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:106)
at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:52)
at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:359)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:89)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:110)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:334)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263)
... 64 common frames omitted
Since it mentions /WEB-INF/views/error/general.html here it is:
<!DOCTYPE html>
<html xmlns:th="www.thymeleaf.org">
<head>
<title>Error page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="../../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen" th:href="#{/resources/css/bootstrap.min.css}"/>
<link href="../../../resources/css/core.css" rel="stylesheet" media="screen" th:href="#{/resources/css/core.css}"/>
</head>
<body>
<div class="container">
<div th:replace="fragments/layout :: header"></div>
<div th:replace="fragments/components :: alert (type='danger', message=${errorMessage})">Error: Error</div>
<div th:replace="fragments/layout :: footer"></div>
</div>
</body>
</html>
And layout.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml">
<head>
<link href="../../../resources/css/bootstrap.min.css" rel="stylesheet" media="screen" th:href="#{/resources/css/bootstrap.min.css}"/>
</head>
<body>
<!-- Header -->
<div class="navbar navbar-inverse navbar-fixed-top" th:fragment="header">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#" th:href="#{/}">Demo project</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li th:classappend="${module == 'about' ? 'active' : ''}">
About
</li>
<li th:classappend="${module == 'calendar' ? 'active' : ''}">
Calendar
</li>
<li th:classappend="${module == 'event' ? 'active' : ''}"
sec:authorize="hasRole('ROLE_ADMIN')"
>
Formularz
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li th:if="not ${#authorization.expression('isAuthenticated()')}">
<a href="/signin" th:href="#{/signin}">
<span class="glyphicon glyphicon-log-in" aria-hidden="true"></span> Sign in
</a>
</li>
<li th:if="${#authorization.expression('isAuthenticated()')}">
<a href="/logout" th:href="#{#}" onclick="$('#form').submit();">
<span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> Logout
</a>
<form style="visibility: hidden" id="form" method="post" action="#" th:action="#{/logout}"></form>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
<!-- Footer -->
<div th:fragment="footer" th:align="center">
© <span th:text="${#temporals.format(#temporals.createNow(), 'yyyy')}">2017</span>
Demo project <span th:text="${#environment.getProperty('app.version')}"></span>
</div>
</body>
</html>
It says that line
<li th:if="not ${#authorization.expression('isAuthenticated()')}">
is the problem and in fact when i change it to return false no errors are thrown. When i change it to use !isAuthenticated() or isAnonymous() instead of "not [...] isAuthenticated()" it throws errors. I have thymeleaf-extras-springsecurity4 dependency added in my pom.xml file as well.
My bet is that i have to work on the fact the authenticated object is null. But what else it could be when i'm checking the website as anonymous?
In general you should always have an authentication object on every page of secured application. Filter org.springframework.security.web.authentication.AnonymousAuthenticationFilter is responsible for setting AnonymousAuthenticationToken in the current security context when it (token) is missing. If this filter is not called it may indicate some problems in security configuration.
BTW try to use xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4" namespace in your Thymeleaf templates. It will shorten security checks a little bit: <div sec:authorize="isAuthenticated()">.

Spring MVC: Controller function not getting called on form submit

I am new to using Spring MVC framework and have designed a html page which has two forms. One is login(form id: loginform) and other is for signup((form id:signupform). The controller is being called correctly for the login page but for the signup, nothing happens (no controller is called) and the page just refreshes. I am not able to find out the source of the problem. Here is my JSP page:
Login.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%#page session="true"%>
<html>
<head>
<title>Login Page</title>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous">
</script>
<spring:url value="/resources/css/mylogin.css" var="mainCss" />
<link href="${mainCss}" rel="stylesheet" />
<%-- <link href="<spring:url value='/resources/css/mylogin.css'/>" rel="stylesheet"> --%>
</head>
<body>
<div class="container">
<div id="loginbox" style="margin-top: 50px;"
class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">Sign In</div>
</div>
<div style="padding-top: 30px" class="panel-body">
<c:if test="${not empty error}">
<!-- Invalid Username Password -->
<div class="error">${error}</div>
</c:if>
<c:if test="${not empty msg}">
<!-- Logged out successfully -->
<div class="msg">${msg}</div>
</c:if>
<div style="display: none" id="login-alert"
class="alert alert-danger col-sm-12"></div>
<form id="loginform" class="form-horizontal" role="form"
name="loginform"
action="<c:url value='/j_spring_security_check' />" method='POST'>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i
class="glyphicon glyphicon-user"></i></span> <input id="login-username"
type="text" class="form-control" name="username" value=""
placeholder="username">
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i
class="glyphicon glyphicon-lock"></i></span> <input id="login-password"
type="password" class="form-control" name="password"
placeholder="password">
</div>
<div style="margin-top: 10px" class="form-group">
<div class="col-sm-12 controls">
<input class="btn btn-success" id="btn-login" name="submit"
type="submit" value="LOG IN" /> <input type="hidden"
name="${_csrf.parameterName}" value="${_csrf.token}" />
</div>
</div>
<div class="form-group">
<div class="col-md-12 control">
<div
style="border-top: 1px solid #888; padding-top: 15px; font-size: 85%">
Don't have an account! <a href="#"
onClick="$('#loginbox').hide(); $('#signupbox').show()">
Sign Up Here </a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<div id="signupbox" style="display: none; margin-top: 50px"
class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">Sign Up</div>
</div>
<div class="panel-body">
<form:form id="signupform" class="form-horizontal" role="form"
method="POST" modelAttribute="userForm"
action="<c:url value='/adduser' />">
<div id="signupalert" style="display: none"
class="alert alert-danger">
<p>Error:</p>
<span></span>
</div>
<form:hidden path="id" />
<spring:bind path="name">
<div class="form-group">
<label for="name" class="col-md-3 control-label">Name</label>
<div class="col-md-9">
<form:input path="name" type="text" class="form-control"
name="name" placeholder="Name" />
</div>
</div>
</spring:bind>
<spring:bind path="email">
<div class="form-group">
<label for="email" class="col-md-3 control-label">Email</label>
<div class="col-md-9">
<form:input path="email" type="text" class="form-control"
name="email" placeholder="Email Address" />
</div>
</div>
</spring:bind>
<spring:bind path="username">
<div class="form-group">
<label for="username" class="col-md-3 control-label">Username</label>
<div class="col-md-9">
<form:input path="username" type="text" class="form-control"
name="username" placeholder="Username" />
</div>
</div>
</spring:bind>
<spring:bind path="password">
<div class="form-group">
<label for="password" class="col-md-3 control-label">Password</label>
<div class="col-md-9">
<form:input path="password" type="password"
class="form-control" name="passwd" placeholder="Password" />
</div>
</div>
</spring:bind>
<spring:bind path="dob">
<div class="form-group">
<label for="date" class="col-md-3 control-label">Date of
Birth</label>
<div class="col-md-9">
<form:input path="dob" type="date" name="bday"
class="form-control" />
</div>
</div>
</spring:bind>
<spring:bind path="image">
<div class="form-group">
<label for="pic" class="col-md-3 control-label">Profile
Picture</label>
<div class="col-md-9">
<form:input path="image" type="file" name="pic"
class="form-control" />
</div>
</div>
</spring:bind>
<spring:bind path="genreName">
<div class="form-group">
<label for="genre" class="col-md-3 control-label">Favorite
Genres</label>
<div class="col-md-9">
<!-- <input type="file" name="pic" class="form-control"> -->
<form:select multiple="" path="genreName" name="genreNames"
class="form-control">
<c:forEach items="${genres}" var="genre" varStatus="ctr">
<option id="${genre.id}" value="${genre.name}">${genre.name}</option>
</c:forEach>
</form:select>
</div>
</div>
</spring:bind>
<div class="form-group">
<!-- Button -->
<div class="col-md-offset-3 col-md-9">
<input class="btn btn-info" id="tn-signup" name="submit"
type="submit" value="Sign Up" />
</div>
</div>
<div class="form-group">
<div class="col-md-12 control">
<div
style="border-top: 1px solid #888; padding-top: 15px; font-size: 85%">
Already have an account? <a id="signinlink" href="#"
onClick="$('#signupbox').hide(); $('#loginbox').show()">
Sign In </a>
</div>
</div>
</div>
</form:form>
</div>
</div>
</div>
</div>
</body>
</html>
Controller:
package com.moviebase.web.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.moviebase.web.model.user.UserDao;
import com.moviebase.web.model.genre.Genre;
import com.moviebase.web.model.genre.GenreDao;
import com.moviebase.web.model.user.User;
#Controller
public class MainController {
#Autowired
public UserDao userDao;
#Autowired
public GenreDao genreDao;
#RequestMapping(value = { "/", "/welcome**" }, method = RequestMethod.GET)
public ModelAndView defaultPage() {
ModelAndView model = new ModelAndView();
model.addObject("title", "Moviebase");
model.addObject("message", "This is default page!");
model.setViewName("hello");
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String username = auth.getName(); //get logged in username
User user = userDao.findByUsername(username);
System.out.println(user.toString());
return model;
}
#RequestMapping(value = "/admin**", method = RequestMethod.GET)
public ModelAndView adminPage() {
ModelAndView model = new ModelAndView();
model.addObject("title", "Moviebase");
model.addObject("message", "This page is for ROLE_ADMIN only!");
model.setViewName("admin");
return model;
}
#RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(#RequestParam(value = "error", required = false) String error,
#RequestParam(value = "logout", required = false) String logout) {
ModelAndView model = new ModelAndView();
if (error != null) {
System.out.println(" error:"+error);
model.addObject("error", "Invalid username and password!");
}
if (logout != null) {
model.addObject("msg", "You've been logged out successfully.");
}
List<Genre> genreList = genreDao.getAllGenres();
model.addObject("genres", genreList);
User user = new User();
model.addObject("userForm", user);
model.setViewName("login");
return model;
}
#RequestMapping(value = "/adduser", method = RequestMethod.POST)
public ModelAndView createUser(#ModelAttribute("userForm") User user,
BindingResult result) {
// ModelAndView model = new ModelAndView();
// model.setViewName("redirect:/");
System.out.println("Came here");
userDao.insert(user);
return new ModelAndView("redirect:/admin");
}
//for 403 access denied page
#RequestMapping(value = "/403", method = RequestMethod.GET)
public ModelAndView accesssDenied() {
ModelAndView model = new ModelAndView();
//check if user is login
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (!(auth instanceof AnonymousAuthenticationToken)) {
UserDetails userDetail = (UserDetails) auth.getPrincipal();
System.out.println(userDetail);
model.addObject("username", userDetail.getUsername());
}
model.setViewName("403");
return model;
}
}
Web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>MovieBase</display-name>
<!-- Spring MVC -->
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml,
/WEB-INF/spring-database.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>database</groupId>
<artifactId>moviebase</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Moviebase</name>
<properties>
<jdk.version>1.7</jdk.version>
<spring.version>3.2.8.RELEASE</spring.version>
<spring.security.version>3.2.3.RELEASE</spring.security.version>
<jstl.version>1.2</jstl.version>
<mysql.connector.version>5.1.30</mysql.connector.version>
</properties>
<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
</dependency>
<!-- Spring Security JSP Taglib -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring.security.version}</version>
</dependency>
<!-- jstl for jsp page -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.version}</version>
</dependency>
</dependencies>
<build>
<finalName>moviebase</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
</plugins>
</build>
</project>
mvc-dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.moviebase.*" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
</beans>
Your singup form has the http method POST but your controller is form http method GET
Your JSP:
<form:form id="signupform" class="form-horizontal" role="form"
method="POST" modelAttribute="userForm"
action="<c:url value='/adduser' />">
Your controller:
#RequestMapping(value = "/adduser", method = RequestMethod.GET)
public ModelAndView createUser(#ModelAttribute("userForm") User user,
BindingResult result) {

i18n issue using servlet 3 and spring 3.2.3

Im working with spring 3.2.3, servlet 3 and maven 3.1, so i'm trying to use i18n, but for some dark reason i can't start my app saying:
javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'login.button.signin' for locale 'pt_BR'.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
but my default lang is "EN" and i have both properties with this message.
Code:
WebConfig.java
#Configuration
#EnableWebMvc
#ComponentScan(basePackages = { "com.codesenior.oaon.controller" })
public class WebConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
#Override
public void addInterceptors(InterceptorRegistry registry) {
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("lang");
registry.addInterceptor(localeChangeInterceptor);
}
#Bean
public LocaleResolver localeResolver() {
CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
cookieLocaleResolver.setDefaultLocale(StringUtils.parseLocaleString("en"));
return cookieLocaleResolver;
}
#Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
source.setBasename("classpath:messages");
source.setDefaultEncoding("UTF-8");
return source;
}
#Bean
public InternalResourceViewResolver templateResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/pages/");
resolver.setSuffix(".jsp");
resolver.setCache(false);
return resolver;
}
index.jsp
<body>
<div class="container">
<div class="content">
<div class="row">
<span style="float: right">
en
|
pt
</span>
<div class="login-form">
<h2>Login</h2>
<form action="/login">
<fieldset>
<div class="clearfix">
<input id="username" type="text" placeholder="Username">
</div>
<div class="clearfix">
<input id="password" type="password" placeholder="Password">
</div>
<button class="btn btn-primary" onclick="return signin();" value="<spring:message code="login.button.signin"/>" ></button>
</fieldset>
</form>
</div>
</div>
</div>
</div> <!-- /container -->
</body>
messages (current path:src/main/resources)
messages_en.properties
login.label.username=Username
login.label.password=Password
login.button.signin=Signin
messages_pt.properties
login.label.username=Usuário
login.label.password=Senha
login.button.signin=Entrar
Since my default lang is EN, i don't know why it are asking for PT, although even if i ignore this point, i have messages_pt.properties that contains the correct message.
Full stacktrace:
2014-01-14 15:30:49 ERROR MessageTag:83 - No message found under code 'login.button.signin' for locale 'pt_BR'.
javax.servlet.jsp.JspTagException: No message found under code 'login.button.signin' for locale 'pt_BR'.
at org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:185)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
at org.apache.jsp.WEB_002dINF.pages.index_jsp._jspx_meth_spring_005fmessage_005f0(index_jsp.java:191)
at org.apache.jsp.WEB_002dINF.pages.index_jsp._jspService(index_jsp.java:155)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Jan 14, 2014 3:30:49 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/checkpointweb] threw exception [An exception occurred processing JSP page /WEB-INF/pages/index.jsp at line 86
83: <div class="clearfix">
84: <input id="password" type="password" placeholder="Password">
85: </div>
86: <button class="btn btn-primary" onclick="return signin();" value="<spring:message code="login.button.signin"/>" ></button>
87: </fieldset>
88: </form>
89: </div>
Stacktrace:] with root cause
javax.servlet.jsp.JspTagException: No message found under code 'login.button.signin' for locale 'pt_BR'.
at org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:185)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
at org.apache.jsp.WEB_002dINF.pages.index_jsp._jspx_meth_spring_005fmessage_005f0(index_jsp.java:191)
at org.apache.jsp.WEB_002dINF.pages.index_jsp._jspService(index_jsp.java:155)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

Spring 3.2.4 + Tiles 3 = infinite loop when resolving view?

I'm trying to use Spring MVC 3.2.4 & Tiles 3.0.1 with Regexp prefixes in my tiles.xml file. I'm a newbie with Tiles, so I might be doing something wrong, but have been trying to follow things I have read on in the Tiles doc site as well as apply stuff from the tech.finn.no blog.
Unfortunately, when I use completeAutoLoad=true with RegExp prefix in my tiles.xml file, I get stuck in an infinite loop when trying to resolve the view.
Stack Trace:
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.StackOverflowError
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
....
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapper.encodeURL(SaveContextOnUpdateOrErrorResponseWrapper.java:181)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
....
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at org.springframework.web.servlet.tags.UrlTag.createUrl(UrlTag.java:227)
at org.springframework.web.servlet.tags.UrlTag.doEndTag(UrlTag.java:174)
at org.apache.jsp.tag.webutil.load_002dscripts_tag._jspx_meth_spring_005furl_005f0(load_002dscripts_tag.java:300)
at org.apache.jsp.tag.webutil.load_002dscripts_tag.doTag(load_002dscripts_tag.java:113)
at org.apache.jsp.WEB_002dINF.views.tiles.layouts.default_jsp._jspx_meth_util_005fload_002dscripts_005f0(default_jsp.java:176)
at org.apache.jsp.WEB_002dINF.views.tiles.layouts.default_jsp._jspService(default_jsp.java:93)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
pom.xml:
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.1</version>
</dependency>
webmvc-config.xml:
<bean class="org.springframework.web.servlet.view.tiles3.SpringWildcardServletTilesApplicationContext" autowire="constructor" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver" >
<property name="cache" value="false"/>
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="completeAutoload" value="true"/>
</bean>
Tiles.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="REGEXP:(.+)" template="/WEB-INF/views/tiles/layouts/default.jsp">
<put-attribute name="meta" value="/WEB-INF/views/tiles/{1}/meta.jsp"/>
<put-attribute name="head" value="/WEB-INF/views/tiles/{1}/head.jsp"/>
<put-attribute name="header" value="/WEB-INF/views/tiles/{1}/header.jsp"/>
<put-attribute name="menu" value="/WEB-INF/views/tiles/{1}/menu.jsp"/>
<put-attribute name="body" value="/WEB-INF/views/tiles/{1}/body.jsp"/>
<put-attribute name="footer" value="/WEB-INF/views/tiles/{1}/footer.jsp"/>
</definition>
</tiles-definitions>
default.jsp:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib prefix="util" tagdir="/WEB-INF/tags/util"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:directive.page pageEncoding="UTF-8" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<tiles:insertAttribute name="meta" ignore="true" />
<util:load-scripts />
<tiles:insertAttribute name="head" ignore="true" />
<spring:message code="application_name" var="app_name" htmlEscape="false"/>
<title><spring:message code="welcome_h3" arguments="${app_name}" /></title>
</head>
<body class="tundra spring">
<div id="wrapper">
<div id="header"><tiles:insertAttribute name="header" ignore="true" /></div>
<div id="menu"><tiles:insertAttribute name="menu" ignore="true" /></div>
<div id="main">
<div id="body"><tiles:insertAttribute name="body"/></div>
<div id="footer"><tiles:insertAttribute name="footer" ignore="true"/></div>
</div>
</div>
</body>
</html>
/WEB-INF/views/tiles/secure/login/body.jsp:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib prefix="util" tagdir="/WEB-INF/tags/util"%>
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<div class="container">
<form name="login" class="form-signin" action='<spring:url value="/j_spring_security_check"/>' method="POST">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" class="form-control" name="j_username" placeholder="Email address" autofocus>
<input type="password" class="form-control" name="j_password" placeholder="Password">
<label class="checkbox"> <input type="checkbox" value="remember-me"> Remember me</label>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
I don't think there is anything specifically special in this configuration, so am not sure why I get into an infinite loop. If I replace the CompleteAutoTilesInitializer class with the BasicTilesInitializerClass and use Wildcards (ie: /) instead and replace {1} with {1}/{2}, then the view loads properly (no infinite loop).
Any ideas what I am doing wrong, or is this a Tiles problem?
Found a similar SO issue (https://stackoverflow.com/a/6617343/827480) that pointed out that the regexp is too greedy and tries to match all attributes as well forever, hence causing the StackOverflow. Work around at the moment is to use a less greedy regexp.
Getting some traction under https://issues.apache.org/jira/browse/TILES-572 and http://thread.gmane.org/gmane.comp.apache.tiles.user/612

java.lang.UnsupportedOperationException with ICEFaces

Im getting this exception when the view try to renders, im using the icefaces validators tags in a simple ice form, also im using spring to instantiate the managed beans but it is working correctly in other pages, SO i dont feel spring is the problem ... this is the exception :
java.lang.UnsupportedOperationException: Implement SWF integration at
com.icesoft.util.SeamUtilities.getSpringFlowId(SeamUtilities.java:542)
at
com.icesoft.faces.renderkit.dom_html_basic.FormRenderer.encodeBegin(FormRenderer.java:146)
at
com.icesoft.faces.component.ext.renderkit.FormRenderer.encodeBegin(FormRenderer.java:42)
at
org.icefaces.impl.renderkit.RendererWrapper.encodeBegin(RendererWrapper.java:50)
at
javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:824)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1641)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1646)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1646)
at
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:389)
at
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:127)
at
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:117)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) at
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:135)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:309) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at etc.....
This the code of my page:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:include src="generic-modules/header.xhtml" />
<h:body>
<ui:include src="generic-modules/header-navigation.xhtml" />
<div id="bd">
<div class="registration">
<div class="form">
<ice:form>
<ice:inputText id="Name" value="#{applicant.name}" partialSubmit="true">
<f:validateLength maximum="45" minimum="5" />
</ice:inputText>
<ice:message style="color: red;" id="nameError" for="name" />
<br />
<ice:inputText id="Address" value="#{applicant.address}" partialSubmit="true">
<f:validateLength maximum="45" minimum="10" />
</ice:inputText>
<ice:message style="color: red;" id="addressError" for="address" />
<br />
<ice:inputText id="Workplace" value="#{applicant.workplace}" partialSubmit="true">
<f:validateLength maximum="45" minimum="10" />
</ice:inputText>
<ice:message style="color: red;" id="workplaceError" for="workplace" />
<br />
<ice:inputText id="Telephone" value="#{applicant.telephone}" partialSubmit="true">
<f:validateLength maximum="10" minimum="8" />
</ice:inputText>
<ice:message style="color: red;" id="telephoneError" for="telephone" />
<br/>
<ice:inputText id="Photo" value="#{applicant.photo}" partialSubmit="true">
<f:validateLength maximum="80" minimum="2" />
</ice:inputText>
<ice:message style="color: red;" id="photoError" for="photo" />
<br/>
<ice:inputText id="Username" value="#{applicant.username}" partialSubmit="true">
<f:validateLength maximum="10" minimum="8" />
</ice:inputText>
<ice:message style="color: red;" id="usernameError" for="username" />
<br/>
<ice:inputText id="Password" value="#{applicant.password}" partialSubmit="true">
<f:validateLength maximum="10" minimum="8" />
</ice:inputText>
<ice:message style="color: red;" id="passwordError" for="password" />
<br/>
<ice:commandButton value="Register" actionListener="#{applicant.save}" />
<br />
<!-- <ice:outputText value="Age: " />
<ice:outputText value="" /> -->
</ice:form>
</div>
</div>
</div>
</h:body>
</html>
I dont know what is wrong because im only using the code of the icefaces tutorials, i appreciate if anyone can help me
Presently, I don't believe there is a solution to this issue. I was working on the same thing yesterday for about 8 hours. See this page on the icefaces bug tracker: . They actually have the issue marked resolved, and have tutorials that claim that icefaces integrates with SWF 2.X, but the simple fact of the matter is this little line of code in their seamutilities.java class:
if (true)
{
throw new UnsupportedOperationException("Implement SWF integration");
}
I've tried running various version of icefaces before the fix was implemented on up through the current beta, and I still have issues. I'm going to say presently, the two are not compatible.
i am getting this exception with ice forums, and as a workaround i use jsf form instead of iceforums and so far it's working fine with me.

Resources