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:
Advertisements
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 - Strutscontains 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
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) - Strutsusing 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
Struts Struts How to retrive data from database by using
Struts STRUTSSTRUTS MAIN DIFFERENCES BETWEEN
STRUTS 1 AND
STRUTS 2
STRUTSSTRUTS MAIN DIFFERENCES BETWEEN
STRUTS 1 AND
STRUTS 2
StrutsStruts what is SwitchAction in
struts StrutsStruts how to learn
struts STRUTS STRUTS Request context in
struts?
SendRedirect () and forward how to configure in
struts-config.xml
strutsstruts 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
StrutsStruts Tell me good
struts manual
strutsstruts what are the 4 methods of
struts framework
strutsstruts 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 strutsstruts 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
strutsstruts why doc type is not manditory in
struts configuration file
strutsstruts why doc type is not manditory in
struts configuration file
strutsstruts why doc type is not manditory in
struts configuration file
strutsstruts why doc type is not manditory in
struts configuration file
StrutsStruts 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
StrutsSetter 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
strutsstruts 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