You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by unnii <ju...@gmail.com> on 2009/02/03 17:24:48 UTC
populate items using struts2
Hi all,
am new to struts2.. am struggling to get the result for populating items
from DB.
my requirement is to populate country, which is stored in DB, using struts2
and when u choose a particular country, another select box populate its
cities, which also stored in DB..
at first i tried, fetching the list from java class instead of DB... since
there is an example available in
struts2-showcase-2.0.14,built in project of struts2.
when i imported struts2-showcase-2.0.14 and tried that program the
<s:select> is working.. so i thought to implement that into my project.. but
unfortunately it is not working..
i will post here and please have a look and try providing the reason :)
I paste here the example block of a program from struts2-showcase-2.0.14 :
Portion of Jsp file contains the list Like : example.jsp
<s:form action="exampleSubmit" >
<s:select
tooltip="Choose Your Favourite Language"
label="Favourite Language"
list="favouriteLanguages"
name="favouriteLanguage"
listKey="key"
listValue="description"
emptyOption="true"
headerKey="None"
headerValue="None"/>
portion of java class file contains like the following: UITagExample.java
package com.mobitail.action; // i pasted this since i mentioned this in
struts.xml - u should not confuse :)
public String execute() throws Exception {
return SUCCESS;
}
//constructor
public UITagExample() {
favouriteLanguages.add(new Language("EnglishKey", "English
Language"));
favouriteLanguages.add(new Language("FrenchKey", "French
Language"));
favouriteLanguages.add(new Language("SpanishKey", "Spanish
Language"));
}
public List getFavouriteLanguages() {
return favouriteLanguages;
}
public void setFavouriteLanguage(String favouriteLanguage) {
this.favouriteLanguage = favouriteLanguage;
}
public String getFavouriteLanguage() {
return favouriteLanguage;
}
// === inner class
public static class Language {
String description;
String key;
public Language(String key, String description) {
this.key = key;
this.description = description;
}
public String getKey() {
return key;
}
public String getDescription() {
return description;
}
}
portion of struts.xml
<action name="exampleSubmit" class="com.mobitail.action.UITagExample" >
<result>example.jsp</result>
<result name="input">example.jsp</result>
</action>
when i execute http://localhost:8080/mobitail.com/example.jsp .. result is a
blank page
if example.jsp contains other tags like <s:textfield> with <s:select> ,
result is only a textfield .. select box is not shown...
and in the Eclipse Ganymede output window, the error is like the following:
SEVERE: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'favouriteLanguage': The requested list key
'favouriteLanguages' could not be resolved as a
collection/array/map/enumeration/iterator type. Example: people or
people.{name} - [unknown location]
at org.apache.struts2.components.Component.fieldError(Component.java:231)
at org.apache.struts2.components.Component.findValue(Component.java:293)
at
org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:79)
at org.apache.struts2.components.Select.evaluateExtraParams(Select.java:99)
at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:780)
at org.apache.struts2.components.UIBean.end(UIBean.java:481)
at
org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:43)
at
org.apache.jsp.example_jsp._jspx_meth_s_005fselect_005f0(example_jsp.java:383)
at
org.apache.jsp.example_jsp._jspx_meth_s_005fform_005f0(example_jsp.java:244)
at org.apache.jsp.example_jsp._jspService(example_jsp.java:111)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:416)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
I explained every single point detail in manner... i hope u guys can help me
by seeing this..
Please don't tell me to try the following: i tried and its working :)
<s:select
tooltip="Choose Your Favourite Color"
label="Favorite Color"
list="{'Red', 'Blue', 'Green'}"
name="favouriteColor"
emptyOption="true"
headerKey="None"
headerValue="None"/>
i need to populate from DB or from java class, like i explained at top
Thanks in advance...
I hope this post helps u lot...
Cheers!!!
Unnii
--
View this message in context: http://www.nabble.com/populate-items-using-struts2-%3Cs%3Aselect%3E-tp21813249p21813249.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org