Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts ultiple selections list in Struts

Have Programming Question? Ask it here!
 
 
 


Clark
ultiple selections list in Struts
1 Answer(s)      3 years and 5 months ago
Posted in : Struts


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


Advertisement
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
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
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
List
List  i do have one list object, i want to compare this list from database table and if match found i want to update the list
List
List  getting values from a form and make a list of them and store them into database
Enabling Row, Column and Cell Selections in a JTable
Enabling Row, Column and Cell Selections in a JTable... to describe how to enable the row, column and cell selections in a JTable... will see the enabling row, column and cell selections in a JTable. When you
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
need help with two dimensional array that takes input from user and bubble sorts and selections sorts  I can get both of the sorts figured out but i... many words he/she types without using an array list.   Thank you. I
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  i have no any idea about struts.please tell me briefly about struts?**   Hi Friend, You can learn struts from the given link: Struts Tutorials Thanks
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
Struts
Struts   What is called properties file in struts? How you call the properties message to the View (Front End) JSP Pages
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   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
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
Struts
Struts  How Struts is useful in application development? Where to learn Struts? Thanks   Hi, Struts is very useful in writing web... performance Java web applications that runs on Java enabled application servers. Struts
Struts 2 IDE
Struts 2 IDE This page contains the list of IDEs available to ease the development of Struts 2 Framework based applications. The IDE for Struts 2 will actually make the development cycle much easier. Here are the list of Struts 2
struts
struts  how to start struts?   Hello Friend, Please visit the following links: http://www.roseindia.net/struts/ http://www.roseindia.net... can easily learn the struts. Thanks
Struts
Struts  Am newly developed struts applipcation,I want to know how to logout the page using the strus   Please visit the following link: Struts Login Logout Application
struts
struts  hi i would like to have a ready example of struts using "action class,DAO,and services" for understanding.so please guide for the same. thanks  Please visit the following link: Struts Tutorials
Struts
Struts   1)in struts server side validations u are using programmatically validations and declarative validations? tell me which one is better ? 2) How to enable the validator plug-in file
List interface
List interface  What is the List interface
Struts - Struts
Struts for beginners  struts for beginners example
struts
struts  please send me a program that clearly shows the use of struts with jsp
struts
struts  Hi, 1) can we write two controller classes in struts
struts
struts  Hi,... please help me out how to store image in database(mysql) using struts
struts
struts  how to generate bar code for continuous numbers in a loop using struts ... or atleast for a given number
Advertisements
 

 

 

DMCA.com