ultiple selections list in Struts

ultiple selections list in Struts

How to create a multiple selections list in Struts? and retrive seleted values ?

View Answers

November 20, 2010 at 11:44 AM

Hi friends,

With the help of this example, you can display multiple selections list and how to access selected values in struts. bookList list contains list of Book objects.

Java bean class.

public class Book{
int  bookId;
String bookName;


public int getBookId() {
    return medId;
}

public void setBookId(int bookId) {
    this.bookId = bookId;
}

public String getBookName() {
    return bookName;
}

public void setBookName(String bookName) {
    this. bookName =  bookName;
}

}

In the Form Class :

public class BookForm {
private List bookList;
private String[] book;
public void setBookList(List medList){
    this.bookList = bookList;
}

public List getBookList(){
    return this.bookList;
}

public String[] getBook() {
    return book;
}

public void setBook(String[] book) {
    this.book = book;
}

}

In the Action class :

List medList = DAO.getBooks(); form.setBookList(bookList);

DAO Class :

DAO Class to retrieve Books in data base.

  public static List getBooks(){
    PreparedStatement pStmt = null;
 Connection con = null;
 boolean success = false;
 ResultSet rs = null;
 List bookList = new ArrayList();

 try{
     conn = getConnection();

     String sql = " select * from BOOK ";
     pStmt = conn.prepareStatement(sql);

     rs = pStmt.executeQuery();
     while(rs.next()){
         Book book= new Book();
         book.setBookId(rs.getInt("Book_ID"));
         book.setBookName(rs.getString("Book_NAME"));
         bookList.add(book);
         }               
 }catch(Exception e){
     e.printStackTrace();

 }finally{
     closeConnectionProp(conn,pStmt,rs);
 }        
 return bookList;    
}

JSP Struts page:

<html:select name="BookForm" property="book" multiple="true">

<bean:define name="BookForm" property="BookList" id="bklist" />
<html:options collection="bklist" property="bookId" labelProperty="bookName" />
</html:select>

In the Action class again :

how to retrieve the selected values.

String[] book= form.getBook();

Thanks.









Related Tutorials/Questions & Answers:
ultiple selections list in Struts
ultiple selections list in Struts  How to create a multiple selections list in Struts? and retrive seleted values
multiple selections list in Struts
multiple selections list in Struts  How to create a multiple selections list in Struts? and retrive seleted values
Advertisements
drop down list in Struts
drop down list in Struts  How to create a drop down list in Struts
struts dropdown list
struts dropdown list   In strtus how to set the dropdown list values... page using struts ? please send me jsp code... sample code: **Action... = MasterDataDAO.getValues(list); request.setAttribute("masterlist", masterList
contains for list in struts2 - Struts
contains for list in struts2  Is there any way to check in the list or for existence of an enum ? Something like list.contains(string). iterating over list I want to do something like Display x display y
creating list in dropdown using struts - Struts
creating list in dropdown using struts   creating list in dropdown using struts : In action class list.add(new LabelValueBean("ID","Name")); In Jsp * Select Item Select In Form : getter
Version of struts>struts dependency
List of Version of struts>struts dependency
Version of struts>struts-el dependency
List of Version of struts>struts-el dependency
Version of struts>struts-bean dependency
List of Version of struts>struts-bean dependency
Version of struts>struts-html dependency
List of Version of struts>struts-html dependency
Version of struts>struts-legacy dependency
List of Version of struts>struts-legacy dependency
Version of struts>struts-logic dependency
List of Version of struts>struts-logic dependency
Version of struts>struts-nested dependency
List of Version of struts>struts-nested dependency
Version of struts>struts-template dependency
List of Version of struts>struts-template dependency
Version of struts>struts-tiles dependency
List of Version of struts>struts-tiles dependency
Select functionality of drop down list - Struts
(in struts application) in which if user select HIDE from the drop down list... have Drop down list having element Test1,Test2,Test3,HIDE and one Text msg box for entering Age,Now if user select "HIDE" from drop-down list the below text
using getText(String aTextName, List args) - Struts
using getText(String aTextName, List args)   What should my pacakge.properties (Message.properties) should have ? basically i am trying to use ActionSupport.getText(String aTextName, List args) I want something like "you
Artifacts of struts
List of Artifacts of struts maven depenency
Version of struts>struts-bean-el dependency
List of Version of struts>struts-bean-el dependency
Version of struts>struts-html-el dependency
List of Version of struts>struts-html-el dependency
Version of struts>struts-logic-el dependency
List of Version of struts>struts-logic-el dependency
Version of struts-scripting>struts-scripting dependency
List of Version of struts-scripting>struts-scripting dependency
Version of struts>struts-tiles-el dependency
List of Version of struts>struts-tiles-el dependency
Version of struts-menu>struts-menu dependency
List of Version of struts-menu>struts-menu dependency
How to handle the list dynamically in struts inside logic:iterate tag
How to handle the list dynamically in struts inside logic:iterate tag ...; </table> my struts config with dyna form is: <form-bean name...; In my action I wish to take the values from list named inutParamsvalues
Struts
Struts   How to retrive data from database by using Struts
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
Struts
Struts  what is SwitchAction in struts
Struts
Struts  how to learn struts
STRUTS
STRUTS   Request context in struts? SendRedirect () and forward how to configure in struts-config.xml
struts
struts  in industry, struts 1 and struts 2. which is the best? which is useful as a professuional   Have a look at the following link: Struts Tutorials
Struts
Struts  Tell me good struts manual
struts
struts  what are the 4 methods of struts framework
struts
struts shopping cart project in struts with oracle database connection  shopping cart project in struts with oracle database connection   Have a look at the following link: Struts Shopping Cart using MySQL
Struts
Struts   When Submit a Form and while submit is working ,press the Refresh , what will happen in Struts
struts
struts  Hi what is struts flow of 1.2 version struts? i have struts applicatin then from jsp page how struts application flows Thanks Kalins Naik   Please visit the following link: Struts Tutorial
struts
struts   how to write Dao to select data from the database
struts
struts  why doc type is not manditory in struts configuration file
struts
struts  why doc type is not manditory in struts configuration file
struts
struts  why doc type is not manditory in struts configuration file
struts
struts  why doc type is not manditory in struts configuration file
Artifacts of struts-scripting
List of Artifacts of struts-scripting maven depenency
Artifacts of struts-menu
List of Artifacts of struts-menu maven depenency
Struts
Struts  Hi i am new to struts. I don't know how to create struts please in eclipse help me
struts
struts   Hi how struts flows from jsp page to databae and also using validation ? Thanks Kalins Naik
Struts
Setter methods of form bean class in Struts applications  who calls the setter methods of form bean class in struts applications
Struts
Struts   What is called properties file in struts? How you call the properties message to the View (Front End) JSP Pages
Struts
Struts   in struts I want two struts.xml files. Where u can specify that xml files location and which tag u specified
struts
struts  which is the best book to study struts on own? please tell me   You can learn struts through the following books: 1)Programming Jakarta Struts By Chuck Cavaness 2)Professional Jakarta Struts By James Goodwill

Ads