Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8249465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:33:13+00:00 2026-06-07T23:33:13+00:00

I want to fetch a selected value from a drop down ‘select’ list of

  • 0

I want to fetch a selected value from a drop down ‘select’ list of ‘form’ in a jsp page into a variable defined in the action class of the form, where ‘select’ drop down list is itself fetched dynamically from a column ‘name’ of database table ‘Category’ with the list ‘categoryList’ which is defined in some another action class.

After fetching the selected value (that is a name of Category) i want to fetch the primary key ‘cid’ of the table ‘Category’. columns of Category are : id, name

After Retrieving the ‘cid’ of the category i want to fill this cid in the column ‘cid’ of another table ‘Question’.

I am using struts2 and hibernate.

My column is ‘name’ and table is ‘Category’
I have made the mapping configuration and bean classes.

My code of action class where the list is generated :

public class FindCategory extends ActionSupport {

    private List<Category> categoryList = new ArrayList<Category>();

    @Override
    public String execute() throws Exception {
        Session session = null;
        try {
            session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            this.categoryList = (List<Category>) session.createQuery("from Category").list();
            if (this.categoryList.isEmpty()) {
                this.addActionError("Sorry.. No category Available. Try again Later.!");
                return ERROR;
            }
            session.getTransaction().commit();
        } catch (Exception e) {
            this.addActionError("Oops. An Error Encountered...!");
            return ERROR;
        }
        return SUCCESS;
    }

    public List<Category> getCategoryList() {
        return categoryList;
    }

    public void setCategoryList(List<Category> categoryList) {
        this.categoryList = categoryList;
    }
}

code in a ‘form’ of a jsp page :

<s:form action="okadddqs" method="post" cssClass="text">
                                <input type="hidden" name="email" value="goods.ramesh@gmail.com"/>
                                <s:select label="Select Category :" name="name" list="categoryList" listkey="name" listValue="name"/> //Here the list is generated
                                <s:textarea label="Your Question " cols="40" rows="5" name="body"/>
                                <s:textfield name="op1" label="Option 1 :"/>
                                <s:textfield name="op2" label="Option 2 :"/>
                                <s:textfield name="op3" label="Option 3 :"/>
                                <s:textfield name="op4" label="Option 4 :"/>
                                <s:textfield name="op5" label="Option 5 :"/>
                                <s:select label="Correct Option :" 
                                         name="opc"       
                                         list="#@java.util.LinkedHashMap@{'1':'One',
                                         '2':'Two','3':'Three','4':'Four','5':'Five'}"/>
                                <s:submit value="Update Daily Question"/>
                            </s:form>

My action to submit a new question class :

package com.rambo.action;

import beans.Category;
import beans.Question;
import beans.Users;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.hibernate.Session;

/**
 *
 * @author ROMO
 */
@ManagedBean
@SessionScoped
public class NewQuestion extends ActionSupport {

    private String cname;

    private List<Category> cl = new ArrayList<Category>();


    public List<Category> getCl() {
        return cl;
    }

    public void setCl(List<Category> cl) {
        this.cl = cl;
    }

    @Override
    public String execute() throws Exception {

        Session session = null;
        int c;
        //c store the cid of the selected Category name from drop down list.
        try {
            session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            cl = (List<Category>) session.createQuery("from Category c where c.name = '" + getName() + "'");
            if (!cl.isEmpty()) {
                c = cl.get(0).getCid();
            } else {
                this.addActionError("Oops. Sorry No Category Available.");
                session.close();
                return ERROR;
            }

            u = new Question();
            u.setCid(c);
            u.setCname(getName());
            session.save(u);
            session.getTransaction().commit();
        } catch (Exception e) {
            this.addActionError("Oops. An Error Encountered...! Email address already registered. Try with your new email address.");
            session.close();
            return ERROR;
        }
        return SUCCESS;
    }


    @Override
    public void validate() {
        if ("".equals(getEmail()) || getEmail() == null ) {
            this.addActionError("All Fields are Compulsory to input..!");
        } else if (getEmail().indexOf("@") < 0 || getEmail().indexOf(",") > 0 || getEmail().indexOf(".") < 0) {
            this.addActionError("Please Input a valid email address.");
        }
    }
}

Mapping in Category.hbm.xml :

<property name="name" type="string">
            <column name="NAME" length="20" not-null="true" />
        </property>

Getter and setter of the bean “Category.java”:

public String getName() {
    return this.name;
}

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

My glassfish server shows error as :

org.apache.jasper.JasperException: tag 'select', field 'list', name 'cname': The requested list key 'categoryList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

root cause tag 'select', field 'list', name 'cname': The requested list key 'categoryList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

Can some one please point out what may b the error..?
thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:33:15+00:00Added an answer on June 7, 2026 at 11:33 pm

    As we discussed in comments, categoryList should be of type Category with getter/setter

    List<Category> categoryList
    

    then in your jsp

    <s:select label="Select Category :"
           name="cid"
           id="cid"
           list="categoryList"
           listKey="id"
           listValue="name"
    />
    

    Now declare a hidden field in your form to submit cname also, with cid

    <s:hidden name="cname" id="cname"/>
    

    jQuery code(as requested by you) to set cname

    $("#cid").change(function(){
      $("#cname").val($(this).find("option:selected").text());
    });
    

    You need to declare cid & cname variables(with getter/setter) in your NewQuestion action

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I fetch a post value from a drop-down list to check if
How do I access the selected value of a drop down menu from html
want to fetch the value from dynamically created textfield with tag from NSMutableArray.... Txt_New_Estimated
I want to insert a value from the database into my dropdown menu in
I want to get the number of rows selected and sender value from the
I want to write a code that should let me select from a drop
I want to create a drop down list that allows the user to choose
I have a PHP based form. It has a drop down list which fetches
I want to fetch the user groups and want to list them but I
I want to fetch the title from book table and the subject name from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.