Forum Stats

  • 3,853,440 Users
  • 2,264,222 Discussions
  • 7,905,361 Comments

Discussions

Unable to save selected lov value after form submit

713263
713263 Member Posts: 23
edited Aug 4, 2009 5:28AM in JDeveloper and ADF
Hi All,

I want to build a jsp page which has 3 lov's.

First lov is populated with some values obtained from the database when the page is loaded.
Now when i change the value in the first lov, the second lov is populated fetching values from the database using the first lov's value as parameter.
Similarly the second lov value is passed as a parameter to populat the third lov.


But the problem when i use the onchage event the selected value is not shown in either the first lov or the second lov.
i am calling onchange event form.submit to populate the second lov. But i see that the values in the first lov are again loaded.

This is the code i have framed.

please can anyone help on this or correct this code and add if required.

<form action="VE_Application.jsp"> -- Start of the code

----------- Start of Lov1-----------------------------------------------

<select size="1" name="application_label" onChange="form.submit()" >

<%ResultSet rsetlov ;
rsetlov = lovbean.getAllApplications(); %>
<% while (rsetlov.next ())
{
out.println("<option value=" + rsetlov.getString("application_label") + ">" +
rsetlov.getString("application_label") + "</option> " );
}%>
</select>


----------- End of Lov1-----------------------------------------------

----------- Start of Lov2 where the application_label is used as parameter to populate the second lov-----------------------------------------------

<select size="1" cols="30" name="view_label" onchange="form.submit()">
<%
String appls_label = request.getParameter("application_label");
ResultSet rsetlova = lovbean.getAllViews(appls_label);
while (rsetlova.next ())
{
out.println("<option value=" + rsetlova.getString("view_label") + ">" +
rsetlova.getString("view_label") + "</option> " );
}%>
</select>

----------- End of Lov2 ----------------------------------------------

</form> -- end of the code

Edited by: user1064313 on Jul 31, 2009 1:59 AM

Answers

  • Branislav Nemec
    Branislav Nemec Member Posts: 1,044
    edited Jul 31, 2009 5:40AM
    Hi,

    after calling form.submit() you must remember selected value from LOV and then when you iterate your list you must write to <option> tag also selected if you get that value

    <%
    String sel = lovbean.getSelectedValue();
    while (rsetlov.next ())
    {
    String selectedOrNot = "";
    if ( sel.equals(rsetlov.getString("application_label")) ) selectedOrNot = "selected";
    out.println("<option value=" + rsetlov.getString("application_label") + selectedOrNot + ">" +
    rsetlov.getString("application_label") + "</option> " );
    }%>

    Note that if you want to store the selected value in lovbean it must have session scope

    regards,

    Branislav

    Edited by: Branislav Nemec on Jul 31, 2009 11:39 AM
    Branislav Nemec
  • 713263
    713263 Member Posts: 23
    edited Aug 3, 2009 3:22AM
    <select size="1" name="application_label" onChange="form.submit()" >

    <%ResultSet rsetlov ;
    String query = request.getParameter("application_label");
    rsetlov = lovbean.getAllApplications(); %>
    <% while (rsetlov.next ())
    {
    out.println("<option value=" + rsetlov.getString("application_label") + ">" +
    rsetlov.getString("application_label") + "</option> " );
    }%>

    <%
    String sel = lovbean.getSelectedValue();
    while (rsetlov.next ())
    {
    String selectedOrNot = "";
    if ( sel.equals(rsetlov.getString("application_label")) ) selectedOrNot = "selected";
    out.println("<option value=" + rsetlov.getString("application_label") + selectedOrNot + ">" +
    rsetlov.getString("application_label") + "</option> " );
    }%>


    </select>

    Bran, the above code is one that i am trying to use but it still doesnt save the value in lov.

    Edited by: user1064313 on Aug 3, 2009 12:21 AM
  • 713263
    713263 Member Posts: 23
    I tried the same code by using outside the </SELECT>.

    actually lovbean.getSelectedValue(); is derived like this

    public String getSelectedValue() throws SQLException {
    Application oldAppl = findApplicationByName();
    StringBuffer columns = new StringBuffer( 255 );
    return "success";
    }

    ---findApplicationByName(); is derived fromt the object application---

    public Application findApplicationByName() throws SQLException {

    Application selectedAppl = new Application();
    stmt =
    conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    query = "select application_label from n_application_owner_templates " ;
    System.out.println("\nExecuting query: " + query);
    rset = stmt.executeQuery(query);


    while (rset.next()) {
    selectedAppl.setSelVal(rset.getString("application_label"));
    }

    return selectedAppl;
    }
  • 713263
    713263 Member Posts: 23
    And Bran the application object

    ---Applicaiton object is from application.java---------

    public class Application {
    public Application() {
    }

    private String selval;

    public String getSelVal() {
    return selval;
    }

    public void setSelVal(String selval) {
    this.selval = selval;
    }
    }
  • 713263
    713263 Member Posts: 23
    Bran please could see the above code which i have pasted above and can you please suggest if anything wrong ...............
  • Branislav Nemec
    Branislav Nemec Member Posts: 1,044
    Hi,

    I don't know exactly which technology you use, but to store anything into session and later get that value from session you can use java Bean technology.
    have a look: http://www.exampledepot.com/egs/javax.servlet.jsp/usebean.jsp.html

    regards,

    Branislav
This discussion has been closed.