How to print Spring MVC model values in a JSP Page - spring

I have a jsp file that receives data from a Spring MVC Controller
<%# 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"%>
<%# taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
<%# page session="false"%>
<form:form action="" commandName="someDetail">
<form:input path="name" class="form-control" />
<form:input path="address" class="form-control" />
This successfully displays the data inside a textbox. I want to display the data as an ordinary text without the textbox. I have tried printing it as
${address}
but it does not work. How do I print the values without the textbox?

As there is a commandName="someDetail", I assume there is an object called someDetail in the model.
If so, you just have to write ${someDetail.address} to print the address in the generated html.

Related

java spring model object in jsp ( very strange )

hi i have this in a jsp page
<input type="text" id="jsonBom" value='${excNotice}'/>
value='${excNotice}' is been interpreted as text in the jsp i get this text : ${excNotice} ... not the content of this variable that is been passed by spring controller ... very strange ...
I have all the tag libs needed in the jsp ,
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>

Set a value for <form: input> in Spring's form tag library

How can I possibly set a value for a form input field using the form tag library in Spring MVC shown below even if it has no value attribute and is not accepted according to form tld?
<form:input path ="name" id="name" cssStyle="display: none"/>
Not based on requirement:
<input type="hidden" id="name" value="Raven"/>
Don't use a <form:input>? It's for binding to beans.
You can use a regular <input> element ;)
If you want to set its value:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<c:set var="name" value="Raven" />
<input type="hidden" name="name" value="<c:out value='${name}' />" />

generic linking, variables and paths in jsp

Requests: Please only answer if you know implications in depth.
Related Question that I found help from: Nested expression in JSP/JSTL
I want to make my links, paths, and variables (for images, scripts, and other pages and includes) generic so that refactoring or changes file locations in future would make no big problems.
What I thought was to make:
variables.jsp:
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%#taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<c:set var="mainDir" value="${pageContext.request.contextPath}/view/jsp" />
<c:set var="resourcesDir" value="${mainDir}/resources" />
header.jsp
<%# taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%#include file="variables.jsp" %>
<html>
<head><title>${pageTitle}</title></head>
login.jsp
<c:set var="pageTitle" >
<spring:message code="pageTitle.login" />
</c:set>
<%#include file="${mainDir}/common/header.jsp" %>
<body>...
...
...
<%#include file="${mainDir}/common/footer.jsp" %>
Please observe the includes and c:sets / c:outs with spring:messages.
What is the proper way to do what I want to (if my current strategy is not sane).

Struts2 ajax theme problem in IE9

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" />

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