I am having problems retrieving the value of the selected item from a jsp page in my action page. I am not sure what I should be doing and I haven't found a good example.
I have a header on the page that shows districts in a drop down list. I have the list populated, but when it goes to the action page, I am not sure how to get the value selected. I need to use the value selected so that I can do a query based on it.
My JSP looks like this:
<%@ page language="java"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %>
<jsp:useBean id="dstrctForm" class="com.NG.struts_class.form.dstrctForm" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<head>
<html:base />
<title>dstrctHeader.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<html:form name="dstrctForm" action="/displayAllUsers" type="com.NG.struts_class.form.dstrctForm">
<html:select property="districtId" >
<html
ptions collection="district" property="value" labelProperty="label" />
</html:select>
<html:submit />
</html:form>
</body>
</html:html>
Here is my form bean in my struts-config:
<form-bean name="dstrctForm" type="com.NG.struts_class.form.dstrctForm">
<form-property name="distrctId" type="java.lang.String" />
<form-property name="value" type="java.util.ArrayList" />
</form-bean>
My form looks like this:
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_2.7.101/xslt/JavaClass.xsl
package com.NG.struts_class.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import java.util.ArrayList;
/**
* MyEclipse Struts
* Creation date: 10-20-2004
*
* XDoclet definition:
* @struts:form name="dstrctForm"
*/
public class dstrctForm extends ActionForm {
// --------------------------------------------------------- Instance Variables
/** distrct property */
private String districtId;
private ArrayList value;
// --------------------------------------------------------- Methods
/**
* Method validate
* @param ActionMapping mapping
* @param HttpServletRequest request
* @return ActionErrors
*/
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
return errors;
}
/**
* @return
*/
public String getDistrictId() {
return districtId;
}
/**
* @param string
*/
public void setDistrictId(String string) {
districtId = string;
}
/**
* @return
*/
public ArrayList getValue() {
return value;
}
/**
* @param list
*/
public void setValue(ArrayList list) {
value = list;
}
}
So when I am in DisplayAllUsersAction, I am not sure what I should be referencing to know what I select. I have tried casting the form and then doing a get on the districtId, but it gives me a null pointer exception.
Thanks,
Melissa