Struts2 ajax theme problem in IE9 - ajax

We have an running application that is developed in struts-2.0.14. In this we used Ajax theme for displaying contents.
This ajax theme is running properly in all browsers except IE9 browsers, In IE9 this ajax theme making problem . The result is showing in new tab instead of showing in target element(div) specified by targets property.
Parent Page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<s:head theme="ajax" debug="false" />
</head>
<body>
<s:url id="changePwd" action="changePassword" />
<s:div theme="ajax" id="pwdDiv" executeScripts="true" href="%{changePwd}" loadingText="Loading..."/>
</body>
</html>
Inner page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<%# taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<s:form action="changePassword" id="resetPassword" name="resetPassword">
<s:textfield name="username" id="username" />
<s:password showPassword="true" name="newpassword" id="newpassword" value="%{newpassword}"/>
<s:password showPassword="true" name="confirmpassword" id="confirmpassword" value="%{confirmpassword}"/>
<s:submit value="Confirm" showLoadingText="false" onclick="clearMsg();" theme="ajax" targets="pwdDiv" executeScripts="true" cssClass="userbutton" />
</s:form>
When Submitting the form in Inner Page the resulting page is popup into new tab. actually it should replace the content of pwdDiv.
Note: the same working properly in other browsers including (IE7,8)
Update:
making showLoadingText as true making the request as Ajax but the values are passed as null (password,confirm password ect,. -all fields)

Adding type="button" in s:submit button solve the problem. Don't know what is behind this !
<s:submit **type="button"** value="Confirm" showLoadingText="false" onclick="clearMsg();" theme="ajax" targets="pwdDiv" executeScripts="true" cssClass="userbutton" />

Related

Spring MVC serve static file when submit a form

I'm running through weird behavior in Spring MVC. I try to make custom login page with spring security.
Here is my simple login page with a link to a style sheet login.jsp:
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Title</title>
<link href="/resources/css/style.css" rel="stylesheet"/>
</head>
<body>
<h1>Login Form</h1>
<form:form action="/authuser" method="post">
<c:if test="${param.logout != null}">
<i>You have been logout!</i>
</c:if>
<c:if test="${param.error != null}">
<i>Invalid username or password!</i>
</c:if>
<p>
User name: <input type="text" name="username"/>
</p>
<p>
Password: <input type="password" name="password"/>
</p>
<input type="submit" value="Login"/>
</form:form>
</body>
</html>
when I fill out the form and hit submit it redirect me to http://localhost:8080/resources/css/test.css and serves me with stylesheet file!
when I remove the stylesheet link, it works fine and redirects me to the home page.

Attribute modelAttribute invalid for tag form according to TLD

I am trying to create a form:form but every time I have the model Attributr tag I get the following error!
There was an unexpected error (type=Internal Server Error, status=500).
/WEB-INF/views/start.jsp (line: 17, column: 0) Attribute modelAttribute invalid for tag form according to TLD
Here is my JSP code
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Official Sars-CoV3 Test Report</title>
</head>
<body>
<form:form action="addResults" modelAttribute="results">
<label for="tTN">TTN: </label><br>
<input type="text" id="tTN" name="tTN"><br>
<label for="fullname">Full Name:</label><br>
<input type="text" id="fullname" name="fullname">
<label for="email">Email:</label><br>
<input type="text" id="email" name="email">
<label for="age">Age:</label><br>
<input type="text" id="age" name="age">
<label for="gender">Please select Gender:</label>
<input type="submit" value="submit">
</form:form >
Admin Login
</body>
</html>

request.contextPath not resolved inside Apache Tiles JSP fragments

I have a Spring + Apache Tiles 3 Aplication.
I have a layout and inside of this, the header, the body and the footer:
defaultLayout.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# page isELIgnored="false" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><tiles:getAsString name="title" /></title>
<link href="<c:url value='/static/css/bootstrap.css' />" rel="stylesheet"></link>
<link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
</head>
<body>
<header id="header">
Web Application Context Path="${pageContext.request.contextPath}"
<tiles:insertAttribute name="header" />
</header>
<section id="sidemenu">
<tiles:insertAttribute name="menu" />
</section>
<section id="site-content">
<tiles:insertAttribute name="body" />
</section>
<footer id="footer">
<tiles:insertAttribute name="footer" />
</footer>
</body>
</html>
The "${pageContext.request.contextPath}" works fine inside the Layout, but not on the JSP children's:
menu.jsp
<nav>
<img class="logo" src="${pageContext.request.contextPath}/static/img/Linux-icon.png">
<ul id="menu">
<li>Home</li>
<li>Products</li>
<li>Contact Us</li>
</ul>
This prints the "${pageContext.request.contextPath}" "as is" in the result HTML.
Try to use <%# page isELIgnored="false" %>. It will solve your problem
Since you mentioned HTML code and say that the context path is printed "as-is", is this code in HTML file? Then it will not work.
Check this question - ${pageContext.request.contextPath} is not working on plain HTML

unable to pass variables between jsp templates

I'm unable to pass variables from a.jsp to b.jsp, following is what I tried and the output. Can someone please help? Thanks.
a.jsp
start including
<jsp:include page="b.jsp">
<jsp:param name="somevar" value="zzzz" />
</jsp:include>
stop including
b.jsp
${somevar}
${param.somevar}
<%=request.getParameter("somevar")%>
output
start including
null
stop including
You have to set your param before include.
start including
<jsp:params>
<jsp:param name="somevar" value="zzzz" />
</jsp:params>
<jsp:include page="b.jsp">
</jsp:include>
stop including
And can u try this in b.jsp:
<%=request.getParameter("somevar");%>
What is output?
Try the following code:
home.jsp
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# page session="false"%>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Hello world!</h1>
<jsp:include page="b.jsp">
<jsp:param name="something" value="something" />
</jsp:include>
<h1>Bye World</h1>
</body>
</html>
In the b.jsp page use the following code.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Param example</title>
</head>
<body>
<h1>
<c:out value="${param.something}" />
</h1>
</body>
</html>
The output must be
Hello world!
something
Bye World
Try to avoid java code in JSP pages as it is not advisable. For more details, have a look at this answer How to avoid Java Code in JSP-Files?

Can Anyone Explain This Struts 2 AJAX Strange Refresh Behaviour?

We have the following code (listed below) in our JSP. We are seeing the action configured in the href of the div id=pwcercontainer being called twice. Can't work out exactly why. Replacing the containing sx:div label="Admin Record Deployment" with a plain non-struts div causes the action to be called only once. We can't see anything in the documentation for sx:div that explains this behavior.
Does anyone know anything about this or have similar experience?
Thanks.
NCF
<%# page language="java" %>
<%# taglib uri="/WEB-INF/tags/c.tld" prefix="c" %>
<%# taglib prefix="s" uri="/struts-tags" %>
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%# taglib uri="/WEB-INF/tags/arcade.tld" prefix="arcade" %>
<%# taglib prefix="sx" uri="/struts-dojo-tags" %>
<s:url id="pwcerAjax" action="pwcerajax" method="start" includeParams="none"/>
<s:url id="pwAjax" action="pwajax" method="start" includeParams="none"/>
<s:url id="listPendingDeploymentsLink" action="listPendingDeployments" namespace="/"/>
<s:url id="record" action="recordDeploymentFragment" method="showAdminRecord" namespace="/"/>
<sx:div label="Admin Record Deployment" >
<!-- Div where content will be displayed -->
<sx:div id="pwcercontainer" href="%{pwcerAjax}" showLoadingText="false" indicator="recordImage" preload="true">
</sx:div>
<div id="loadingContainer"><img id="recordImage" src="images/ajaxLoadingAnimation.gif" style="display:none" alt="loading animation"/></div>
</sx:div>
I have hit this issue many times now and it is always down to an error on my part. Either returning a fragment that contains the calling piece of code:
<s:url id="getDeployQueue" action="deploymentQueue" />
<sx:div href="%{#getDeployQueue}" formId="queueForm" executeScripts="true" autoStart="true" updateFreq="3000" preload="false" showLoadingText="false" listenTopics="refreshqueue" id="deploymentQueue" >
THE CODE RETURNED in HERE CONTAINS THE s:url id="getDeployQueue" duplicating it and resulting in double calls
</sx:div>
Or i have been setting the target attribute of another ajax tag to be an sx:div when I really should be updating it using a dojo topic.
Hope this helps somebody
Neil

Resources