Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populating Country Values in combobox using spring form tags

 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am unable to display country list from database on my jsp page. Instead of the country values, i am getting the below output onm my jsp page

-----------Output Start---------------------
Project.Domain.Admin.CountryService@d6a0e0 Project.Domain.Admin.CountryService@dbf04d
-----------Output End-----------------------

The code on my jsp page is as under.

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ include file="/WEB-INF/jsp/Admin/include.jsp" %>

<core:forEach var="county" items="${CountryList}">
<coreut value="${county}"/>
</core:forEach>

I am using spring Controller & i am sending the List object in HttpRequest parameters of ModelAndView return type.


Regards,

Ujjwal Soni
 
Jason Ferguson
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, first some nitpicking:

You are mixing "county" and "country" as names. This can lead to massive confusion since the words are similar but have different meanings.

Now, I'm assuming that you have a Domain Object named Country, with fields such as "id","name" (or "countryname"), etc. However, in your Expression Language (EL) in <coreut name="">, you are specifying the entire object. This is calling the default "toString()" of that object.

Instead, use an EL something like this: ${country.name}, specifying which attribute of the country object to output.

Also, in order to keep myself consistent, I usually create an interface for my Domain Objects:



I tend to use alot of dynamically created <option> tags, and one of the things this interface allows me to do is always know what the option tags will be populated with. (Also, sometimes I just get going too fast and will name my id and name fields badly).

Jason

Originally posted by ujjwal soni:
Hi,

I am unable to display country list from database on my jsp page. Instead of the country values, i am getting the below output onm my jsp page

-----------Output Start---------------------
Project.Domain.Admin.CountryService@d6a0e0 Project.Domain.Admin.CountryService@dbf04d
-----------Output End-----------------------

The code on my jsp page is as under.

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ include file="/WEB-INF/jsp/Admin/include.jsp" %>

<core:forEach var="county" items="${CountryList}">
<coreut value="${county}"/>
</core:forEach>

I am using spring Controller & i am sending the List object in HttpRequest parameters of ModelAndView return type.


Regards,

Ujjwal Soni
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic