This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes mapping between JSP n form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "mapping between JSP n form" Watch "mapping between JSP n form" New topic
Author

mapping between JSP n form

lubna kausar
Ranch Hand

Joined: May 06, 2006
Posts: 51
hi all,
m using ArrayList to display a list of users on my page...
now m having
ArrayList userList to hold users'list.
and a class named Users with attribute userNameli.

now my problem is that i do get values set in userList perfectly...
but when it comes to JSP it gives me the error that "no bean found under "userList"" and i suppose it is because i dont know how to perform mapping between JSP n farm...
here is te code of JSP please check where i m mistaken???


"<"html:select property="userList" size="20">
"<"html:"&o;"ptions collection="userList" property="userNameli" labelProperty="userNaemli" />
"<"/html:select>
Raminder Singh
Ranch Hand

Joined: Mar 01, 2002
Posts: 72
"<"html:select property="userList" size="20">
"<"html:"&o;"ptions collection="userList" property="userNameli" labelProperty="userNaemli" />
"<"/html:select>

property="userList" AND collection="userList" both are form properties with same name.

use: property="userCode" AND collection="allUserList" and check.

hope it will solve problem.
lubna kausar
Ranch Hand

Joined: May 06, 2006
Posts: 51
hi there i have changed the property of select tag to "userSelected" and kept setter getter for this in Form also but the property of the options should be the arraylist i m using so that is "userList" so thats correct i suppose...
bute yet not working...
do i need to use useBean tag???
when i try to put useBaen
id=arraylistname
type=full path of the class "Users" whose objects arraylist contains...
but this is giving me some clascastexception
i replaced all the classfile n deleted all the cookies also but yet the error is not removed...
any suggestions???
Soumya Saha
Ranch Hand

Joined: Apr 14, 2006
Posts: 64
Hi Lubna,
"<"html:select property="userList" size="20">
"<"html:"&o;"ptions collection="userList" property="userNameli" labelProperty="userNaemli" />
"<"/html:select>


U should have a different select property other than the collection one.In the Form It should be like this:

private String userId;
private ArrayList userList;

public String getUserId() { return userId; }

public void setUserId(String userId) { this.userId = userId; }

public ArrayList getUserList() { return userList; }

public void setUserList(ArrayList userList) { this.userList = userList; }

Action Class:
Set the ArrayList of UserList to the Form Property 'userList'

JSP:

"<"html:select property="userId" size="20">
"<"html:"&o;"ptions collection="userList" property="userNameli" labelProperty="userNaemli" />
"<"/html:select>

Check for Compilation Errors.When u submit the Form the userID field will give u the current selected user.

Thanks
lubna kausar
Ranch Hand

Joined: May 06, 2006
Posts: 51
yes saumya ,
as i have written in the previous message i have changed the property of select tag to "userSelected"
and now my code is same as urs...
but it is giving me following error...
n yes i m having both setter and getter methods for userNameli in Users class whose object userList holds...


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: No getter method available for property userNameli for bean under name userList
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:536)


root cause

javax.servlet.ServletException: No getter method available for property userNameli for bean under name userList
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:533)
at org.apache.jsp.UserInfo_jsp._jspService(UserInfo_jsp.java:101)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:536)



--------------------------------------------------------------------------------

Apache Tomcat/4.1.29
Soumya Saha
Ranch Hand

Joined: Apr 14, 2006
Posts: 64
Hi Lubna,
Can u give the code where u are creating ur userlist and setting it in the form.

Thanks
lubna kausar
Ranch Hand

Joined: May 06, 2006
Posts: 51
hi saumya... m doing this in UserLinkAction
and here is the code...
// Created by Xslt generator for Eclipse.
// XSL : not found (java.io.FileNotFoundException: (Bad file descriptor))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.patni.peass.action.user;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.patni.peass.bean.common.PEASSBean;
import com.patni.peass.bean.user.UserMasterBean;
import com.patni.peass.business.UserBusiness;
import com.patni.peass.classes.user.Users;
import com.patni.peass.form.user.UserForm;

/**
* UserLinkAction.java created by EasyStruts - XsltGen.
* http://easystruts.sf.net
* created on 05-12-2006
*
* XDoclet definition:
* @struts:action validate="true"
*/
public class UserLinkAction extends Action {
// --------------------------------------------------------- Instance Variables
// --------------------------------------------------------- Methods
/**
* Method execute
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ArrayList createBean(ArrayList userList)
{
ArrayList userListArray=new ArrayList();
int count=0;
while(count<userListArray.size())
{
userListArray.add((UserMasterBean)(userList.get(count)));
count++;
}
return userListArray;
}
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
UserForm uf=new UserForm();
ArrayList userList=new ArrayList();
userList=uf.getUserList();
ArrayList newUserList=new ArrayList();
userList=UserBusiness.findAll();
//UserMasterBean userBean[]=new UserMasterBean[userList.size()];
//userBean=(UserMasterBean[]) userList.toArray();
//userList=createBean(userList);
//request.setAttribute("users",userList);
int i=0;
String listUser[] = new String[userList.size()];
//ArrayList userList=null;
while(i<userList.size())
{
//System.out.println("First Name="+( (UserMasterBean)userList.get(i) ).getFirstName());
UserMasterBean ub=new UserMasterBean();
ub=(UserMasterBean) userList.get(i);
listUser[i]=ub.getUserName();
//Users user=new Users();
uf.getUser().setUserNameli(listUser[i]);
System.out.println("uf.getUser().getUserNameli() = "+uf.getUser().getUserNameli());
//user.setUserNameli(listUser[i]);
//uf.setUser(user);
newUserList.add((Users)uf.getUser());
i++;
}

uf.setUserList(newUserList);
HttpSession session = request.getSession();
session.setAttribute( "userList", userList);
if(uf.getUserList()!=null)
return mapping.findForward("success");
else
return mapping.findForward("faliure");
}
/* (non-Javadoc)
* @see com.patni.peass.action.common.PEASSAction#createBean(javax.servlet.http.HttpServletRequest)
*/
public PEASSBean createBean(HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
}


thanx...
Soumya Saha
Ranch Hand

Joined: Apr 14, 2006
Posts: 64
Hi Lub,

This method :

userList=UserBusiness.findAll();

Does it return only a collection of UserMasterBean?.If so then add this bean in the USerList prop of ur Form and display it in ur JSP.Change the label property and value fields to "username"

Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: mapping between JSP n form
 
Similar Threads
html:select problem
html:select and html:options
No getter method for property name of bean userList
List "key Column" and "List Index" values null.
Display struts output to jsp