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 iam getting problem in <html:OptionsCollection> 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 "iam getting problem in <html:OptionsCollection>" Watch "iam getting problem in <html:OptionsCollection>" New topic
Author

iam getting problem in <html:OptionsCollection>

parthiban thrangaraju
Greenhorn

Joined: Feb 06, 2011
Posts: 25
iam getting problem in <html:OptionsCollection>

my attachement is here


jsp file:
--------


<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<html lang="en">
<head>
<title> <bean:message key="clientscomment.title1"/> </title>
</head>

<body id="page6">
<!-- header -->
<header>

<div class="inside">
<html:form action="/ClientsCommentForm.do" styleId="contacts-form">

<fieldset>
<div class="col-1">

<bean:message key="clientscomment.title3"/><br/>

<html:text property="name" />
<html:errors property="name"/>
<br/>
<bean:message key="clientscomment.title8"/>
<br>

<html:select property="typeofbusiness" name="ClientsCommentForm" >
<%--<html:select property="typeofbusiness">--%>
<htmlption value="">Select TypeofBusiness</htmlption>
<htmlptionsCollection name="ClientsCommentForm" property="typeofbusinesslist" label="typeofbusinesslist" value="typeofbusinessId" />
<%--<htmlptions collection="typeofbusinesslist" labelProperty="typeofbusinessId" labelName="typeofbusinesslist"/>--%>
</html:select>

<html:errors property="typeofbusiness"/><br/>
<bean:message key="clientscomment.title4"/>
<br>

<html:text property="email" />
<html:errors property="email"/>
<br/>
<bean:message key="clientscomment.title7"/>
<br>
<html:text property="contactno" />
<html:errors property="contactno"/>
<br/>
<bean:message key="clientscomment.title5"/><br/>

<html:text property="state" />
<html:errors property="state"/>
</div>
<div class="col-2">
<bean:message key="clientscomment.title6"/><br />
<html:textarea property="message" />
<html:errors property="message"/>

<div class="wrapper">
<html:submit value="SUBMIT" styleId="submit" property="method" />
</div>
</div>
</fieldset>
</html:form>
</div>

</body>
</html>


action form:



package Classes.ClientsComment;

import java.util.ArrayList;

public class ClientsCommentForm extends org.apache.struts.validator.ValidatorForm {



private String name;
private String email;
private String contactno;
private String state;
private String message;
private String typeofbusiness;
private ArrayList typeofbusinesslist;



public String getTypeofbusiness() {
return typeofbusiness;
}

public String getContactno() {
return contactno;
}

public String getEmail() {
return email;
}

public String getMessage() {
return message;
}

public String getName() {
return name;
}

public String getState() {
return state;
}

public ArrayList getTypeofbusinesslist() {
return typeofbusinesslist;
}


public ClientsCommentForm() {
super();
}



public void setEmail(String email) {
this.email = email;
}

public void setMessage(String message) {
this.message = message;
}

public void setName(String name) {
this.name = name;
}

public void setState(String state) {
this.state = state;
}

public void setContactno(String contactno) {
this.contactno = contactno;
}

public void setTypeofbusiness(String typeofbusiness) {
this.typeofbusiness = typeofbusiness;
}

public void setTypeofbusinesslist(ArrayList typeofbusinesslist) {
this.typeofbusinesslist = typeofbusinesslist;
}


}

action class:


package Classes.ClientsComment;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class ClientsCommentAction extends org.apache.struts.actions.DispatchAction {


private static final String SUCCESS = "success";
private static final String SUCCESS1 = "success";


@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ClientsCommentForm ccf=(ClientsCommentForm) form;

String name=ccf.getName();
String email=ccf.getEmail();
String contactno=ccf.getContactno();
String state=ccf.getState();
String message=ccf.getMessage();

String url="jdbc:mysql://localhost:3306/nemogroups";
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(url, "root","root");
Statement st=con.createStatement();
String insert="insert into clientcomment(name,email,contactno,state,message)values('"+name+"','"+email+"','"+contactno+"','"+state+"','"+message+"')";
st.executeUpdate(insert);

return mapping.findForward(SUCCESS);
}

public ActionForward populate(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse resonse){

ArrayList typeofbusinesslist=new ArrayList();

ClientsCommentForm ccf1=(ClientsCommentForm) form;

typeofbusinesslist.add(new TypeofBusiness("1", "NemoTravels"));
typeofbusinesslist.add(new TypeofBusiness("2", "NemoHotels"));
typeofbusinesslist.add(new TypeofBusiness("3", "NemoCorporateService"));
typeofbusinesslist.add(new TypeofBusiness("4", "NemoAgriCulture"));
typeofbusinesslist.add(new TypeofBusiness("5", "NemoConstructions"));
typeofbusinesslist.add(new TypeofBusiness("6", "NemoFoundation"));
typeofbusinesslist.add(new TypeofBusiness("7", "NemoItSolutions"));

ccf1.setTypeofbusinesslist(typeofbusinesslist);

return mapping.findForward(SUCCESS1);
}
}

java class:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/



/**
*
* @author Parthibant
*/
public class TypeofBusiness {

private String typeofbusinessId;
private String typeofbusinessName;

public TypeofBusiness(String typeofbusinessId, String typeofbusinessName) {
this.typeofbusinessId = typeofbusinessId;
this.typeofbusinessName = typeofbusinessName;
}

public String getTypeofbusinessId() {
return typeofbusinessId;
}

public String getTypeofbusinessName() {
return typeofbusinessName;
}

public void setTypeofbusinessId(String typeofbusinessId) {
this.typeofbusinessId = typeofbusinessId;
}

public void setTypeofbusinessName(String typeofbusinessName) {
this.typeofbusinessName = typeofbusinessName;
}

}



while executing this program i am getting the following error

exception

javax.servlet.ServletException: javax.servlet.jsp.JspException: Failed to obtain specified collection

root cause

javax.servlet.jsp.JspException: Failed to obtain specified collection

thanks in advance
parthi



Raaja Gotluru
Ranch Hand

Joined: Mar 02, 2010
Posts: 108
Hi,

Just in the populate action method instead of adding the list to form just keep that list in request scope.
request.setAttribute("typeofbusinesslist",typeofbusinesslist);

in jsp
<logic:notEmpty name="typeofbusinesslist">
<htmlptions collection="typeofbusinesslist" labelProperty="typeofbusinessId" labelName="typeofbusinesslist"/>
</logic:notEmpty>

notEmpty is used in order to avoid exception if the list is empty.

--raaja. g
parthiban thrangaraju
Greenhorn

Joined: Feb 06, 2011
Posts: 25
Hi,

thanks raaja

now the program is executed and the form is displayed but the problem is, the is list in drop down box is not displaying, its just displaying select the business type alone.

can you help me for this problem.

thanks in advance
parthiban thrangaraju
Greenhorn

Joined: Feb 06, 2011
Posts: 25
can any one help me to solve this problem
Guy Belpa
Ranch Hand

Joined: Nov 21, 2004
Posts: 41

Make sure this action forwards to the JSP, and then call the URL for the action (/myaction.do) rather than calling the JSP directly (/mypage.jsp).
 
 
subject: iam getting problem in <html:OptionsCollection>
 
Similar Threads
java.lang.IllegalArgumentException: argument type mismatch
How to Validate duplicate entries in database using struts1
doubt regarding <html:select>
How to display error message
how to do validation in struts1