ultiple selections list in Struts

Ads

 
 

Share on Google+Share on Google+

Clark
ultiple selections list in Struts
1 Answer(s)      7 years ago
Posted in : Struts

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

Ads
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.


Ads









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

Ads

 
Advertisement null

Ads