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



Home Answers Viewqa Struts ultiple selections list in Struts
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Clark
ultiple selections list in Struts
1 Answer(s)      4 years 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
List interface
List interface  What is the List interface
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
Struts
Struts   How to retrive data from database by using Struts
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
Struts
Struts  how to learn struts
Struts
Struts  what is SwitchAction in 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 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 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  what are the 4 methods of struts framework
Struts
Struts  Tell me good struts manual
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
linked list
linked list  program for single linked list
list boxs
list boxs  i have two list boxes first list box values from database and i want to assign selected options to the second list box using jsp is it possible to do this in jsp
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
List interface
List interface  Give me some of the real time examples that can be developed based on List and its implemented classes
Advertisements
 

 

 

DMCA.com