java - Retrieve value from database in drop-down(<s:select>) using Struts 2 and Hibernate -


i want use dropdown , getting value in drop down database, dropdown should contain company code saving purpose & company description display purpose.

below code:

bean class:

package com.ims.master.company.bean;  public class companybean {          private string id;         private string cmpcode;         private string cmpdes;         private string cmpstatus;         private string cmpcreated;          public companybean(string cmpcode, string cmpdes) {             super();             this.cmpcode = cmpcode;             this.cmpdes = cmpdes;         }          public string getid() {             return id;         }         public void setid(string id) {             this.id = id;         }         public string getcmpcreated() {             return cmpcreated;         }         public void setcmpcreated(string cmpcreated) {             this.cmpcreated = cmpcreated;         }         public string getcmpcode() {             return cmpcode;         }         public void setcmpcode(string cmpcode) {             this.cmpcode = cmpcode;         }         public string getcmpdes() {             return cmpdes;         }         public void setcmpdes(string cmpdes) {             this.cmpdes = cmpdes;         }         public string getcmpstatus() {             return cmpstatus;         }         public void setcmpstatus(string cmpstatus) {             this.cmpstatus = cmpstatus;         } } 

dao class:

package com.ims.master.company.dao;  import java.util.arraylist; import org.hibernate.query; import org.hibernate.session; import org.hibernate.sessionfactory; import com.ims.hibernate.hibernateutil; import com.ims.master.company.bean.companybean;   public class companydao {      sessionfactory factory = hibernateutil.getfactory();     session session = factory.opensession();     arraylist<companybean> reclist = new arraylist<companybean>();      @suppresswarnings("unchecked")     public arraylist<companybean> retrievecmpcode()     {         system.out.println("=====inside dao======");         query query = session.createquery("select b.cmpcode,b.cmpdes companybean b b.cmpstatus=:val");         query.setparameter("val", "y");         reclist = (arraylist<companybean>) query.list();         system.out.println("=====value====="+reclist);         return reclist;     } } 

action class:

package com.ims.master.masterdata;  import java.util.arraylist; import com.ims.master.company.dao.companydao; import com.opensymphony.xwork2.actionsupport; import com.opensymphony.xwork2.modeldriven; import com.opensymphony.xwork2.preparable;  public class masterlookup extends actionsupport {      arraylist companycode;     public string getcompany()     {         companydao companycodevalue = new companydao();         companycode = companycodevalue.retrievecmpcode();         return success;     }     public arraylist getcompanycode() {         return companycode;     }     public void setcompanycode(arraylist companycode) {         this.companycode = companycode;     }   } 

jsp:

<s:select name="companyname" list="companycode" key="label.companyname" listkey="cmpcode" listvalue="cmpdes"/> 

please suggest me how value come in drop down. suggest how value in drop down displayed selected in edit part.

you can use below code in jsp

<html:select property ="cmpdes">     <html:optionscollection name ="cmpdes" />      </html:select> 

when above code added in ur jsp , dropdown have cmp description fetched db.

and below site has perfect example learn struts-1 , related question getting ideas go on. http://www.javabeat.net/struts-html-optionscollection-tag-htmloptionscollection/


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -