aspose file tools*
The moose likes JSP and the fly likes how to populate the ui which is retrieved from Database depending on another ui field in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to populate the ui which is retrieved from Database depending on another ui field in jsp" Watch "how to populate the ui which is retrieved from Database depending on another ui field in jsp" New topic
Author

how to populate the ui which is retrieved from Database depending on another ui field in jsp

rambabu desina
Ranch Hand

Joined: May 26, 2012
Posts: 35

Dear ranchers ,

i have UI field named area code and which is retrieved from database and populate those values in the area code depending on the area input field which is also taken from DB
so please give any solution to populate the area code depending on the value of area input field. :rolling: :confused:
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

rambabu desina wrote:Dear ranchers ,

i have UI field named area code and which is retrieved from database and populate those values in the area code depending on the area input field which is also taken from DB
so please give any solution to populate the area code depending on the value of area input field. :rolling: :confused:


You will ask the user to enter Area Input field and based on the Area Input field you need to fetch the Area code from the db. What is the issue with this? Where exactly is the problem? Are you not able to write a SQL query or you are not sure about your JSP?

ShowSomeEffort


Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
rambabu desina
Ranch Hand

Joined: May 26, 2012
Posts: 35

Palak Mathur wrote:
rambabu desina wrote:Dear ranchers ,

i have UI field named area code and which is retrieved from database and populate those values in the area code depending on the area input field which is also taken from DB
so please give any solution to populate the area code depending on the value of area input field. :rolling: :confused:


You will ask the user to enter Area Input field and based on the Area Input field you need to fetch the Area code from the db. What is the issue with this? Where exactly is the problem? Are you not able to write a SQL query or you are not sure about your JSP?

ShowSomeEffort


thanks dear Ranchhand,

But how to write SQL Query using the Area code in the JSP
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

First thing first, you will need to show some effort. Go through a JSP book or online references.

Secondly, you will not like to query your DB from your JSP. Separation of Presentation and Persistence logic is must. So, from your JSP you may want to call a Servlet which may call your DB through some helper classes.
rambabu desina
Ranch Hand

Joined: May 26, 2012
Posts: 35

Palak Mathur wrote:First thing first, you will need to show some effort. Go through a JSP book or online references.

Secondly, you will not like to query your DB from your JSP. Separation of Presentation and Persistence logic is must. So, from your JSP you may want to call a Servlet which may call your DB through some helper classes.


ok
but we did not know about area input field value to write the query in DAO classes. i.e., to write the helper classes
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

rambabu desina wrote:
Palak Mathur wrote:First thing first, you will need to show some effort. Go through a JSP book or online references.

Secondly, you will not like to query your DB from your JSP. Separation of Presentation and Persistence logic is must. So, from your JSP you may want to call a Servlet which may call your DB through some helper classes.


ok
but we did not know about area input field value to write the query in DAO classes. i.e., to write the helper classes


Your problem statement is not at all clear. Try to tell a little more. How are you representing them on screen - textfield, dropdown. What you expect the user to do? And what happens when the user do that? Any relevant info will be helpful.
rambabu desina
Ranch Hand

Joined: May 26, 2012
Posts: 35

Palak Mathur wrote:
rambabu desina wrote:
Palak Mathur wrote:First thing first, you will need to show some effort. Go through a JSP book or online references.

Secondly, you will not like to query your DB from your JSP. Separation of Presentation and Persistence logic is must. So, from your JSP you may want to call a Servlet which may call your DB through some helper classes.


ok
but we did not know about area input field value to write the query in DAO classes. i.e., to write the helper classes


Your problem statement is not at all clear. Try to tell a little more. How are you representing them on screen - textfield, dropdown. What you expect the user to do? And what happens when the user do that? Any relevant info will be helpful.


thanks for your help
i have select field as follows
<select name=area>
<option>---</option>
<option>---</option>
<option>---</option>
</select>

those above option values will be retrived from the DB and populated
after population of the area field ,depending on the area field the following field will be populated with corresponding areacodes of that area from DB

<select name=areacodes>
<option>---</option>
<option>---</option>
<option>---</option>
</select>

my problem is how to write SQL Query to retrive the area codes of corresponding selected area.
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

What code have you written? Can you please show us that? You have a clear problem statement in front of you and you know the solution. Try to work on it first.
rambabu desina
Ranch Hand

Joined: May 26, 2012
Posts: 35

Palak Mathur wrote:What code have you written? Can you please show us that? You have a clear problem statement in front of you and you know the solution. Try to work on it first.


<select name="court_name" Onchange="getcase();getsubcourt();">
<OPTION VALUE="" SELECTED>Select</OPTION>
<c:forEach ....>
<option value=${courtCase.caseName}>${courtCase.caseName}</option>
</c:forEach>

</select>


i have populated the above court_name values by hitting the DB before coming to JSP

and after selecting the above value we have to populate the courtcase_number for the corresponding cour_tname
from DB


<select size="1" name="courtcase_number">
<option></option>
</select>


for that purpose how to retriving the data from DB using the above selected court_name
rambabu desina
Ranch Hand

Joined: May 26, 2012
Posts: 35

rambabu desina wrote:
Palak Mathur wrote:What code have you written? Can you please show us that? You have a clear problem statement in front of you and you know the solution. Try to work on it first.


<select name="court_name" Onchange="getcase();getsubcourt();">
<OPTION VALUE="" SELECTED>Select</OPTION>
<c:forEach ....>
<option value=${courtCase.caseName}>${courtCase.caseName}</option>
</c:forEach>

</select>


i have populated the above court_name values by hitting the DB before coming to JSP

and after selecting the above value we have to populate the courtcase_number for the corresponding cour_tname
from DB

please provide the solution for the above issue

<select size="1" name="courtcase_number">
<option></option>
</select>


for that purpose how to retriving the data from DB using the above selected court_name
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

rambabu desina wrote:
Palak Mathur wrote:What code have you written? Can you please show us that? You have a clear problem statement in front of you and you know the solution. Try to work on it first.


<select name="court_name" Onchange="getcase();getsubcourt();">
<OPTION VALUE="" SELECTED>Select</OPTION>
<c:forEach ....>
<option value=${courtCase.caseName}>${courtCase.caseName}</option>
</c:forEach>

</select>


i have populated the above court_name values by hitting the DB before coming to JSP

and after selecting the above value we have to populate the courtcase_number for the corresponding cour_tname
from DB



<select size="1" name="courtcase_number">
<option></option>
</select>


for that purpose how to retriving the data from DB using the above selected court_name


What are you doing to solve the part that I have marked in bold? You have to fetch the data from DB and show it. Also, you can fetch these details in the first DB call and depending on the selection, you can display the options. But it will all depend on your needs and requirements.
rambabu desina
Ranch Hand

Joined: May 26, 2012
Posts: 35

Palak Mathur wrote:
rambabu desina wrote:
Palak Mathur wrote:What code have you written? Can you please show us that? You have a clear problem statement in front of you and you know the solution. Try to work on it first.


<select name="court_name" Onchange="getcase();getsubcourt();">
<OPTION VALUE="" SELECTED>Select</OPTION>
<c:forEach ....>
<option value=${courtCase.caseName}>${courtCase.caseName}</option>
</c:forEach>

</select>


i have populated the above court_name values by hitting the DB before coming to JSP

and after selecting the above value we have to populate the courtcase_number for the corresponding cour_tname
from DB






<select size="1" name="courtcase_number">
<option></option>
</select>


for that purpose how to retriving the data from DB using the above selected court_name


What are you doing to solve the part that I have marked in bold? You have to fetch the data from DB and show it. Also, you can fetch these details in the first DB call and depending on the selection, you can display the options. But it will all depend on your needs and requirements.





thank you ranch hand

but i don't know the which court _name is to be selected to write the DB call to retrieve the court_case details depending upon the court_name
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Why don't you check out this approach: Servlets + AJAX


Junilu - [How to Ask Questions] [How to Answer Questions]
rambabu desina
Ranch Hand

Joined: May 26, 2012
Posts: 35

Junilu Lacar wrote:Why don't you check out this approach: Servlets + AJAX


thank you Dear Bartender
before the AJAX is there any concept to populate the data of child depending on the parent UI
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

You would have to use JavaScript to respond to the onChange event, then submit the form, again using JavaScript. That would cause a round-trip to the server and your page would be redrawn by the browser with the other field updated based on the previous selection. That causes the user to see the page "flash" as it is being refreshed after the round-trip and this can be disconcerting, especially if you have a long form that the user has to scroll through. AJAX is probably the best way to go at this time, at least that I know of.
rambabu desina
Ranch Hand

Joined: May 26, 2012
Posts: 35

Junilu Lacar wrote:You would have to use JavaScript to respond to the onChange event, then submit the form, again using JavaScript. That would cause a round-trip to the server and your page would be redrawn by the browser with the other field updated based on the previous selection. That causes the user to see the page "flash" as it is being refreshed after the round-trip and this can be disconcerting, especially if you have a long form that the user has to scroll through. AJAX is probably the best way to go at this time, at least that I know of.


thank you for your valuable information
 
 
subject: how to populate the ui which is retrieved from Database depending on another ui field in jsp