Announcement Announcement Module
Collapse
No announcement yet.
Displaying a second drop down after selecting a value in the first drop down Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Displaying a second drop down after selecting a value in the first drop down

    Hi Friends,

    I am relatively new to spring frame work especially on the Front end.

    I have a requirement in my project where user selects an application area from drop down box in JSP I need display another drop down box and form to enter more data. I don't know how to do that. If I am right I think this can be done with java script. I am poor in java scripting. Please help me. I need to do it by the end of today.

    Please give me some example code. And also in application there is drop down box called "Application" when the selects an application from the drop down list, I want to read this field in the formcontroller to Application.id object directly. I am not able to correctly. So I wrote my code in round about manner. I created another field called "applicationind" and reading into this field. How can read the selected value directly to "Application" object and how can I map this correctly to Hibernate mapping config file. In Hibernate I only know how to map to standard data types. I don't know how to map it to custom object types.

    Here I am pasting my code.

    You fast response will be really appreciated (and you will save my day). Thanks in advance.


    ----processingrecords.jsp----code


    <%@ include file="/WEB-INF/jsp/include.jsp"%>
    <!-- -->
    <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <%@ taglib uri="/spring" prefix="spring"%>


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title><fmt:message key="title" /></title>
    </head>
    <body>
    <%@ include file="/WEB-INF/jsp/header.jsp"%>
    <h1><fmt:message key="processrecords.heading" /></h1>
    <form:form method="post" commandName="processingRecords">
    <table width="80%" bgcolor="f8f8ff" border="0" cellspacing="0" cellpadding="2">
    <tr>
    <td align="right" width="20%"><font face="arial" size="2">Application:</font></td>
    <td width="35%">
    <spring:bind path="processingRecords.applicationind">
    <select id="applicationind" name="<c:out value="${status.expression}"/>" size="1">
    <c:forEach items="${applications}" var="application">
    <option value="<c:out value="${application.id}"/>" <c:if test="${application.id == status.value}">selected</c:if>>
    <c:out value="${application.value}" />
    </option>
    </c:forEach>
    </select>
    </spring:bind>
    </td>
    <td width="45%"><font color="red"> <c:out value="${status.errorMessage}"/></font></td>

    </tr>

    </table>
    <br>
    <spring:hasBindErrors name="processingRecords">
    <font face="arial" color="red"><b>Please fix all errors!</b></font>
    </spring:hasBindErrors>
    <br>
    <br>
    <input type="submit" value="Submit">
    </form:form>
    <center><a href="<c:url value="processingrecords.htm"/>">Refresh</a>&nbsp;
    <a href="<c:url value="controllerlist.htm"/>">Back</a>&nbsp;
    <a href="<c:url value="home.htm"/>">Home</a>&nbsp;</center>
    <br>
    <hr>
    <%@ include file="/WEB-INF/jsp/footer.jsp"%>
    </body>
    </html>



    ---ProcessingRecords.java ----Code


    public class ProcessingRecords implements Serializable {

    private int id;
    private Application application;
    private String applicationind;
    private Claim claim

    public void setId(int id) {
    this.id = id;
    }

    public int getId() {
    return id;
    }

    // public void setApplication(String application) {
    // this.application = application;
    // }
    //
    // public String getApplication() {
    // return application;
    // }

    public void setApplication(Application application) {
    this.application = application;
    }

    public Application getApplication() {
    return application;
    }

    public void setApplicationind(String applicationind) {
    this.applicationind = applicationind;
    }

    public String getApplicationind() {
    return applicationind;
    }

    }


    ---Claim.java---- code

    public class Claim implements Serializable{

    private String id;
    private String conflict;
    private String status;

    public void setId(String id) {
    this.id = id;
    }
    public String getId() {
    return id;
    }
    public void setConflict(String conflict) {
    this.conflict = conflict;
    }
    public String getConflict() {
    return conflict;
    }
    public void setStatus(String status) {
    this.status = status;
    }
    public String getStatusrecords() {
    return status;
    }

    }

    ----Application.java--- code

    public class Application implements Serializable {

    private String id;
    private String value;

    public void setId(String id) {
    this.id = id;
    }

    public String getId() {
    return id;
    }

    public void setValue(String value) {
    this.value = value;
    }

    public String getValue() {
    return value;
    }
    }

    -------processingrecords.hbm.xml-------------

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping auto-import="true" default-lazy="false">
    <class name="ss.dao.hibernate.ProcessingRecords" table="processing_records">
    <id name="id" column="id">
    <generator class="increment" />
    </id>
    <property name="applicationind" type="java.lang.String"
    column="application" not-null="true" length="4" />
    <property name="claim.id" type="java.lang.String"
    column="claimid" not-null="false" length="1" />
    </class>
    </hibernate-mapping>

    ------ProcessingRecordsFormController.java----code

    public class ProcessingRecordsFormController extends SimpleFormController {

    /** Logger for this class and subclasses */
    protected final Log log = LogFactory.getLog(getClass());

    private ProcessingRecords prs = null;

    private SerrorManager serrMan;
    // private List<Serror> li;

    public ModelAndView onSubmit(Object command) throws ServletException {

    prs = new ProcessingRecords();
    prs.setApplicationind(((ProcessingRecords)command) .getApplicationind());

    try {

    ProcessingRecordsDaoImpl prsDao = (ProcessingRecordsDaoImpl) new BeanFinder().getBean("ProcessingRecordsDaoTarget") ;
    log.info("prsDao: " + prsDao);
    prsDao.addProcessingRecordInfo(prs);

    } catch (DataAccessException e) {

    log.info("DataAccessException: " + e.getMessage());
    Serror err = new Serror();
    err.setMessage(e.getMessage());
    log.info("Error: " + err.getMessage());
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("serror", err);
    return new ModelAndView("errors", "model", model);

    } catch (SQLException e) {

    log.info("SQLException: " + e.getMessage());
    Serror err = new Serror();
    err.setMessage(e.getMessage());
    log.info("Error: " + err.getMessage());
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("serror", err);
    return new ModelAndView("errors", "model", model);

    } catch (BeansException e) {

    log.info("SQLException: " + e.getMessage());
    Serror err = new Serror();
    err.setMessage(e.getMessage());
    log.info("Error: " + err.getMessage());
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("serror", err);
    return new ModelAndView("errors", "model", model);

    }

    log.info("returning from enterInputForm view to " + getSuccessView());
    return new ModelAndView(new RedirectView(getSuccessView()));

    }

    // protected Map<String, List<Application>> referenceData(HttpServletRequest request) throws Exception {
    // Map<String, List<Application>> referenceData = new HashMap<String, List<Application>>();
    // referenceData.put("applications", new ApplicationManager().getApplications());
    // return referenceData;
    // }

    protected Map<String, List> referenceData(HttpServletRequest request) throws Exception {
    Map<String, List> referenceData = new HashMap<String, List>();
    referenceData.put("applications", new ApplicationManager().getApplications());
    referenceData.put("adjudicationplatforms", new ApplicationManager().getAdjudicationplatforms());
    referenceData.put("alternateplatforms", new ApplicationManager().getAlternateplatforms());
    referenceData.put("deliverysystems", new ApplicationManager().getDeliverysystems());
    return referenceData;
    }

    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    super.initBinder(request, binder);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:MM:SS");
    binder.registerCustomEditor(Date.class, new DatePropertyCustomEditor(dateFormat, true));
    binder.registerCustomEditor(Time.class, new TimePropertyCustomEditor(timeFormat, true));
    }

    public void setProcessingRecords(ProcessingRecords processingRecords) {
    this.prs = processingRecords;
    }

    public ProcessingRecords getProcessingRecords() {
    return prs;
    }


    }
    Last edited by rsrch; Apr 16th, 2008, 05:27 PM.

  • #2
    use code tags!!!

    is the label or icon with #

    If I am write I think this can be done with java script. I am poor java scripting.
    js would be, maybe with ajax

    Please give me some example code.
    i think that is hard to see here

    Comment


    • #3
      Try using DWR,
      Hope that help you out,

      Cheers,
      DeepEdward

      Comment

      Working...
      X