File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes LabelValueBean html:select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "LabelValueBean html:select" Watch "LabelValueBean html:select" New topic

LabelValueBean html:select

M. Sigler

Joined: Oct 21, 2004
Posts: 2
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="" prefix="bean" %>
<%@ taglib uri="" prefix="html" %>
<%@ taglib uri="" prefix="logic" %>
<%@ taglib uri="" prefix="tiles" %>
<%@ taglib uri="" prefix="template" %>
<%@ taglib uri="" 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">
<html:base />


<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">

<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:submit />

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" />

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.


With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: LabelValueBean html:select
It's not a secret anymore!