| 1600 PMP mock questions | 1400 CAPM mock questions | 800 SCJP 6 mock questions | 600 OCAJP 7 mock questions | 590 OCPJP 7 mock questions | 556 SCWCD 5 mock questions | 500 OCEJWCD 6 mock questions | pdfDownload (java,struts, hibernet etc) | JobsJobs and Walkins |
Struts interview questions
|
!!! Struts interview questions !!!Go to Struts Tutorials >>> new Q.How to create a multiple selections list in Struts? and retrive seleted values ?This is the code to display multiple selections list and retrive seleted values in struts. medList list contains list of Medium objects. Java : bean class. public class Medium { int medId; String medName; /** * @return Returns the medId. */ public int getMedId() { return medId; } /** * @param medId The medId to set. */ public void setMedId(int medId) { this.medId = medId; } /** * @return Returns the medName. */ public String getMedName() { return medName; } /** * @param medName The medName to set. */ public void setMedName(String medName) { this.medName = medName; } } In the Form Class : public class MediumForm { private List medList; private String[] med; public void setMedList(List medList){ this.medList = medList; } public List getMedList(){ return this.medList; } public String[] getMed() { return med; } public void setMed(String[] med) { this.med = med; } } In the Action class : List medList = DAO.getMediums(); form.setMedList(medList); DAO Class : DAO Class to retrive mediums in data base. public static List getMediums(){ PreparedStatement pStmt = null; Connection conn = null; boolean success = false; ResultSet rs = null; List medList = new ArrayList(); try{ conn = getConnection(); String sql = " select * from MEDIUM "; pStmt = conn.prepareStatement(sql); rs = pStmt.executeQuery(); while(rs.next()){ Medium med = new Medium(); med.setMedId(rs.getInt("MED_ID")); med.setMedName(rs.getString("MEDIUM_NAME")); medList.add(med); } }catch(Exception e){ e.printStackTrace(); }finally{ closeConnectionProp(conn,pStmt,rs); } return medList; } JSP Struts: <html:select name="MediumForm" property="med" multiple="true"> <bean:define name="MediumForm" property="medList" id="mlist" /> <html:options collection="mlist" property="medId" labelProperty="medName" /> </html:select> In the Action class again : how to retrive the selected values. String[] med = form.getMed(); |
Suggested JobsMore Jobs >> |