• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet or jsp page with prefilled forms

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a jsp page where an admin can manage users.
this page is used to both create new users or edit details of existing users.

at the top of the page there is a drop down box.

what i want is, if the admin selects an username from the dropdown menu, the html form should be prefilled by fetching the correspondig data from the database.

if he/she does not select anything from the drop down box, he/she can fill in the form and create a new user.

how can i prefill the forms when a user is selected from the drop down menu?

thanks in advance.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set the value attributes of the controls.
 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry i am new to jsp and servlet programming. how does it work, setting the attributes for controls?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTML input form elements all have a value attribute.



So when the select box changes and you get the data from the database use the value attribute to populate form elements. This can be done with a standard/typical POST/GET refreshing the page with the new values. So you might have something like:



or this could be done using AJAX. As you are new to all this I'd get the basics down first though. Once you understand it then you can look at helpful technologies such as AJAX to make things better on your applications.
 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply.

just a question for the syntax:



is that assuming the bean-id is user and there is an attribute in the servlet called "firstName"?

are there any good tutorials out there to read on??

thanks
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by V. Singh:
thanks for the reply.

just a question for the syntax:



is that assuming the bean-id is user and there is an attribute in the servlet called "firstName"?




That's correct.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the change event of the dropdown, fire of a call to the servlet/backend that will get the associated values and store it in the appropriate scope so that the view/jsp can get it from there.
 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

On the change event of the dropdown, fire of a call to the servlet/backend that will get the associated values and store it in the appropriate scope so that the view/jsp can get it from there.



This will have to be done using Ajax, isnt it?
 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I used this syntax: value="${user.firstName}" it simply puts that in the text box and not the value of the attribute firstName. What am I doing wrong?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the JSP FAQ to make sure that your web app is set up correctly for JSP 2.0.
 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bosun Bello:
....., fire of a call to the servlet/backend that will get the associated values and store it in the appropriate scope so that the view/jsp can get it from there.



I had to change the idea to the following there is a single page.
At the top of the page there is a textbox and a search button.
followed by a few fields (text boxes) to enter or update data.

now if the user enters a username in the first text box, which is the "search text box" and clicks the search button i get the data from the database in a servlet. after that it should redirect the admin to the same page but now with the fields below the search textbox prefilled with the data fetched from the database.

I have the following code:



my "suser" servlet fetches the data from the database and i have written another class/bean "User" that stores the data fetched, which is instanciated in the servlet. Now i would like get the data from that bean to prefill the forms.

what am i doing wrong here?

thanks for the help
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic