JSP taglib to select file path - Undefined attribute name type - spring

I am trying to create a form. Where the user need to select a file path.
This can be done in html as
<input type="file" name="inputFileName"/>
If we use html then I don't know how to map that value to "fileObject" class.
So how should I do this with the following code throwing a warning "Undefined attribute name type "
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="f" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<f:form method="PUT" commandName="fileObject" >
<f:input type="file" path="inputFileName"/>
</f:form>
</body>
</html>
Exception:
org.apache.jasper.JasperException: /WEB-INF/jsp/Main.jsp(9,0) Attribute type invalid for tag input according to TLD

f:input does not have attribute type as you can find it in docs

Related

Value not displayed into Spring MVC view

I'm having a problem with displaying a string in jsp view. A a web framework I'm using Spring MVC.
The view (return.jsp) is like that:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>FredomWings</title>
</head>
<body>
<b>Result -></b>
<p>${currentValue}</p>
</body>
</html>
The controller looks like that:
#RequestMapping(value="balance")
public String getBalance(Model model) {
model.addAttribute("currentValue","alalal");
return "return";
}
What is the reason for which in the jsp page only Result -> without any value is displayed?

Type [java.lang.String] is not valid for option items

I am trying to bind a list to drop down in JSP. Below is my controller and JSP.
Controller:
#Controller
public class WeatherServiceController {
#Value("#{'${countryList}'.split(',')}")
private List<String> countries;
#ModelAttribute("CountriesList")
private List<String> getCountries(){
System.out.println(countries.size());
return countries;
}
#RequestMapping(value = "/getweather", method=RequestMethod.GET)
public ModelAndView getWeather(){
Place p = new Place();
ModelAndView mav = new ModelAndView();
mav.addObject("place",p);
mav.setViewName("home");
return mav;
}
}
JSP:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!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>Weather Service Client - Home</title>
</head>
<body>
<h2>Welcome to Weather Service</h2>
<form:form modelAttribute="place" action="getWeather">
<table>
<tr>
<td><form:label path="country">Country:</form:label></td>
<td>
<form:select path="country" items="${CountriesList}">
</form:select>
</td>
</tr>
</table>
</form:form>
</body>
</html>
But I am getting error like "Type [java.lang.String] is not valid for option items". Country list is not coming in jsp page. Please help me what I did wrong here.
It is working now.
I have added below line in jsp page.
<%# page isELIgnored="false" %>
I thought by default "isELIgnored" is set to false, so I haven't included earlier. After including this page is binding list result.

Display a list by display:table tag in Spring + Hibernate MVC project

I am doing on a MVC project using netbean IDE and I have a problem with displaying my objects on table
This is my jsp page
<%#page import="java.util.List"%>
<%#page import="java.util.ArrayList"%>
<%#page import="model.Clothes"%>
<%#page import="org.hibernate.Session"%>
<%#page import="cfg.HibernateUtil"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#taglib prefix="display" uri="http://displaytag.sf.net" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Clothes</title>
</head>
<body>
<div style="margin-left: 10%; ">
<%
Session session1 = HibernateUtil.getSessionFactory().getCurrentSession();
List<Clothes> clothes = new ArrayList<Clothes>();
session1.beginTransaction();
clothes = session1.createQuery("from Clothes").list();
session1.getTransaction();
System.out.println(clothes.size() + "aaaaaaaaa");
session1.close();
request.setAttribute("results", clothes);
%>
<display:table name="results" pagesize="10"/>
</div>
<jsp:include page="/index.htm" flush="true"/>
</body>
And the browser display an exception at line contains 'display' tag like this:"org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/clothes.jsp" Where did I do wrong, please help me, I am newbie in java web.
p/s: I add libs in my project, they are: displaytag-1.2, displaytag-export-poi-1.2, displaytag-portlet-1.2 and commons-lang-2.6.
I followed #JB Nizet instruction and it worked, just use the libs exactly the same that listed in this link: http://www.displaytag.org/1.2/displaytag/dependencies.html
However, in some PC, when using org.slf4j, your project can not work properly, just remove them from the project, it is OK!

SpringFramework set selected FilePath to a "path attribute" of form

When a file is selected it must set the fileName with path to a textField with path="inputFileName". I tried to below code which is not working as setFileName is not called either onClick nor onSelect.
Any pointers how this can be done will be great help to me.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="f" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%!
public void setFileName(){
System.out.println("In SetFile Name for InputFile");
}
%>
<html>
<body>
File Convertor
<PRE>
<f:form method="PUT" commandName="file2" >
Input File <f:input path="inputFileName"/><input type="file" name="ChooseMyFile" value="A" onclick="setFileName()" onselect="setFileName()"/>
Output File <f:input path="outputFileName"/>
</f:form>
</PRE>
</body>
</html>

Making appliication internationnalize using jstl tag

I am trying to Internationalize my application using JSTL tag in JSP. My problem is, the content of properties file are not visible in UI.
JSP CODE
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
This Example demonstrates the basic JSTL formating tags:
<br/><br/>
Locale from client:
<b><c:out value="${pageContext.request.locale}"/></b><br/>
<fmt:setBundle basename="ApplicationResources" var="mybundle"/>
<fmt:message key="welcome.message" bundle="${mybundle}">
<fmt:param value="${param.uname}"></fmt:param>
</fmt:message>
<b>Now testing <fmt:setLocale>tag:</b><br>
Creating a ResourceBundle with client locale and setting it to <i>mybundle1</i>
variable.<br>
<fmt:setBundle basename="ApplicationResources" var="mybundle1"/>
Setting the locale to<i>it</i>(italian).<br/>
<fmt:setLocale value="it"/>
Creating a ResourceBundle with <i>it</i>(italian) locale and setting it to <i>mybundle2</i> variable.<br><br>
<fmt:setBundle basename="ApplicationResources" var="mybundle2"/>
<b>Message using <i>mybundle1</i>:</b><br>
<pre>
<fmt:message bundle="${mybundle1}" key="welcome.message">
</fmt:message>
</pre>
<br>
<b>Message using <i>mybundle2</i>:</b><br>
<pre>
<fmt:message bundle="${mybundle2}" key="welcome.message">
</fmt:message>
</pre>
</body>
</html>
The rendered output is:
This Example demonstrates the basic JSTL formating tags:
Locale from client: en_US
???welcome.message??? Now testing <fmt:setLocale>tag:
Creating a ResourceBundle with client locale and setting it to mybundle1 variable.
Setting the locale toit(italian).
Creating a ResourceBundle with it(italian) locale and setting it to mybundle2 variable.
Message using mybundle1:
???welcome.message???
Message using mybundle2:
???welcome.message???
I believe this is what we need to start with. Create two files named:
ApplicationResources.properties
ApplicationResources_it.properties
Both should contain (at least) similar entry:
welcome.message=Hello,{0}
Remove these unnecessary declarations:
<fmt:setBundle basename="ApplicationResources" var="mybundle1"/>
<fmt:setBundle basename="ApplicationResources" var="mybundle2"/>
Move <fmt:setLocale value="it"/> to the top of your page. It will set the locale for the entire page either way, I don't think there is a way to mix languages (thank God).

Resources