File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet or jsp page with prefilled forms

 
Viv Singh
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set the value attributes of the controls.
 
Viv Singh
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i am new to jsp and servlet programming. how does it work, setting the attributes for controls?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic