You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Santosh Kumar Panda <Sa...@infosys.com> on 2004/11/22 11:07:04 UTC
Populating drop-downs
Hi,
I have been facing problems populating drop-downs using dummy stub
classes .I have used a function to populate the page containing the
drop-down and thrown the Action Form type object into the session.
Now how do I retrieve the values on to my jsp screen. Here is the code
snippet..
Action Class:
..................
form = populate(request, iFlag);
session.setAttribute("com.itest.web.form.SelectionForm", form);
......................
.......................
public ActionForm populate(HttpServletRequest request)
{
SelectionForm form = new SelectionForm();
ArrayList arlproject = ProjectData.getProjects();
ListIterator iter = arlproject.listIterator();
while (iter.hasNext())
{
Project proj = (Project) iter.next();
System.out.println("++++++++++++++++" +
(String)proj.getProjectcode());
form.setProjects((String)proj.getProjectcode());
}
return form;
}
SelectionForm.java
public void setProjects(String strProject) {
System.out.println("rrrrrrrrrrrrrrrrrr");
String strKey="proj"+index;
System.out.println("rrrrrrrrrrrrrrrrrr"+strKey);
if (this.htbSelect.containsKey(strKey))
{
index++;
strKey="proj"+index;
}
//this.htbSelect.remove("proj");
this.htbSelect.put(strKey,strProject);
System.out.println("rrrrrrrrrrrrrrrrrr"+index);
System.out.println("iiiiiiiiiiiiii"+htbSelect.get(strKey));
}
public ArrayList getProjects() {
ArrayList arlProject=new ArrayList();
System.out.println("111111111111111111111111111"+index);
for(int i=0;i<index;i++)
{
String strKey="proj"+i;
String proj=(String)this.htbSelect.get(strKey);
arlProject.add(proj);
}
return(arlProject);
}
_____
Regrads
Santosh Kumar Panda
Software Engineer
HTDM(extn.2680)
Re: Populating drop-downs
Posted by Rick Reumann <st...@reumann.net>.
Santosh Kumar Panda wrote the following on 11/22/2004 5:07 AM:
> I have been facing problems populating drop-downs using dummy stub
> classes .I have used a function to populate the page containing the
> drop-down and thrown the Action Form type object into the session.
Well you didn't create a function(method) for populating the dropdowns.
You created some kind of method that is returning an ActionForm. Create
a method called populate(..) that returns a Collection in your Action
go do what you want and call that from your action methods. (If you
arne't using a DispatchAction then just put the populate method in a
base class or else maybe in some Helper class). I describe more here
http://www.reumann.net/struts/articles/request_lists.jsp
<no other comments from me below>
>
>
>
> Now how do I retrieve the values on to my jsp screen. Here is the code
> snippet..
>
>
>
> *_Action Class_*:
>
> ………………
>
>
>
> form = populate(request, iFlag);
>
> session.setAttribute("com.itest.web.form.SelectionForm", form);
>
>
>
> ………………….
>
>
>
> …………………..
>
> *public* ActionForm populate(HttpServletRequest request)
>
> {
>
>
>
> SelectionForm form = *new* SelectionForm();
>
> ArrayList arlproject = ProjectData.getProjects();
>
> ListIterator iter = arlproject.listIterator();
>
> *while* (iter.hasNext())
>
> {
>
> Project proj = (Project) iter.next();
>
>
>
> System.out.println("++++++++++++++++" +
> (String)proj.getProjectcode());
>
> form.setProjects((String)proj.getProjectcode());
>
> }
>
> *return* form;
>
> }
>
>
>
> *_SelectionForm.java_*
>
> *_ _*
>
> *public* *void* setProjects(String strProject) {
>
>
>
> System.out.println("rrrrrrrrrrrrrrrrrr");
>
> String strKey="proj"+index;
>
> System.out.println("rrrrrrrrrrrrrrrrrr"+strKey);
>
> *if* (*this*.htbSelect.containsKey(strKey))
>
> {
>
> index++;
>
> strKey="proj"+index;
>
> }
>
> //this.htbSelect.remove("proj");
>
> *this*.htbSelect.put(strKey,strProject);
>
> System.out.println("rrrrrrrrrrrrrrrrrr"+index);
>
> System.out.println("iiiiiiiiiiiiii"+htbSelect.get(strKey));
>
>
>
> }
>
>
>
> *public* ArrayList getProjects() {
>
> ArrayList arlProject=*new* ArrayList();
>
> System.out.println("111111111111111111111111111"+index);
>
> *for*(*int* i=0;i<index;i++)
>
> {
>
> String strKey="proj"+i;
>
> String proj=(String)*this*.htbSelect.get(strKey);
>
> arlProject.add(proj);
>
> }
>
> *return*(arlProject);
>
> }
>
> *_ _*
>
>
>
> ------------------------------------------------------------------------
>
> /*/Regrads/*/
>
>
>
> /*/Santosh Kumar Panda/*/
>
> /*/Software Engineer/*/
>
> /*/HTDM(extn.2680)/*/
>
>
>
>
>
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Populating drop-downs
Posted by Tak Yoshida <ta...@optonline.net>.
I'm not sure what you exactly want to do,
with adding value to HashTable as set method,
and creating List from the HashTable as get method.
Anyway, if you want to acces that Form you created via poppulate method,
I guess you just write Struts tag with name attribute as the name you set in sesison,
even though codes gets strange.
I'm not sure why you don't use form object passed in Action class.
And speaking of pre-population of dropdown list,
Struts leaves the question "where we should implement?" to the application.
we need to think how to separate "process request" and "prepare for rendering".
and pre-population should be done in "prepare" cycle, and we want clear codes.
You'll see one of the solutions from
http://sourceforge.net/project/showfiles.php?group_id=111296&package_id=120334
Tak
Santosh Kumar Panda wrote in <48...@bhumsg01.ad.infosys.com>
>Hi,
>
>
>
>I have been facing problems populating drop-downs using dummy stub
>classes .I have used a function to populate the page containing the
>drop-down and thrown the Action Form type object into the session.
>
>
>
>Now how do I retrieve the values on to my jsp screen. Here is the code
>snippet..
>
>
>
>Action Class:
>
>..................
>
>
>
>form = populate(request, iFlag);
>
>session.setAttribute("com.itest.web.form.SelectionForm", form);
>
>
>
>......................
>
>
>
>.......................
>
>public ActionForm populate(HttpServletRequest request)
>
> {
>
>
>
> SelectionForm form = new SelectionForm();
>
> ArrayList arlproject = ProjectData.getProjects();
>
> ListIterator iter = arlproject.listIterator();
>
> while (iter.hasNext())
>
> {
>
> Project proj = (Project) iter.next();
>
>
>
> System.out.println("++++++++++++++++" +
>(String)proj.getProjectcode());
>
> form.setProjects((String)proj.getProjectcode());
>
> }
>
> return form;
>
> }
>
>
>
>SelectionForm.java
>
>
>
>public void setProjects(String strProject) {
>
>
>
> System.out.println("rrrrrrrrrrrrrrrrrr");
>
> String strKey="proj"+index;
>
> System.out.println("rrrrrrrrrrrrrrrrrr"+strKey);
>
> if (this.htbSelect.containsKey(strKey))
>
> {
>
> index++;
>
> strKey="proj"+index;
>
> }
>
> //this.htbSelect.remove("proj");
>
> this.htbSelect.put(strKey,strProject);
>
> System.out.println("rrrrrrrrrrrrrrrrrr"+index);
>
> System.out.println("iiiiiiiiiiiiii"+htbSelect.get(strKey));
>
>
>
> }
>
>
>
> public ArrayList getProjects() {
>
> ArrayList arlProject=new ArrayList();
>
>
>System.out.println("111111111111111111111111111"+index);
>
> for(int i=0;i<index;i++)
>
> {
>
> String strKey="proj"+i;
>
> String proj=(String)this.htbSelect.get(strKey);
>
> arlProject.add(proj);
>
> }
>
> return(arlProject);
>
> }
>
>
>
>
>
> _____
>
>Regrads
>
>
>
>Santosh Kumar Panda
>
>Software Engineer
>
>HTDM(extn.2680)
>
>
>
>
>
>
--
Tak Yoshida mailto:takyoshida@optonline.net
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org