wood burning stoves 2.0*
The moose likes Servlets and the fly likes Dynamic Form Creation within a Loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Dynamic Form Creation within a Loop" Watch "Dynamic Form Creation within a Loop" New topic
Author

Dynamic Form Creation within a Loop

Kerry Shannon
Ranch Hand

Joined: May 08, 2001
Posts: 31
We are trying to create a time entry screen, so we will have two weeks of fields to include in a dynamic form web page. We are having problems creating the rows from within a java loop in the jsp. The data appears twice the width of the top and bottom of the screen - like it is ignoring the width parameters.
Any suggestions?
Here's a code fragment:

out.println("<td width=" + "6%" + " align=" + " + "center" + " height=" + " + "17" + " + "><input type=" + " + "text" + " + " name=" + " + "BrkTmIn" + " size=" + " + "5" + " + " style=" + " + "background-color: rgb(176,176,208); text-align: center; vertical-align: middle" + " + " maxlength=" + " + "5" + " + " tabindex=" + " + "1" + " + "></td>");
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
if you are using a jsp, why do you have a out.write in there ? beats the very purpose of using jsp
Kerry Shannon
Ranch Hand

Joined: May 08, 2001
Posts: 31
Where can I see an example of how it should be written?
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
you could be looping while printing the html while inserting the database values dynamically.. for ex..
<table>
<%
while (not last record) {
%>
<tr>
<td width ="5"> <input type = "text" value = " <%= dbvalue %> ">
</td></tr>
<% } // end of while loop
%>
</table>

something like this.. the html wont be perfect in this example but hope you get the idea

[This message has been edited by Mak Bhandari (edited May 08, 2001).]
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

You don't need to use out cause you can put html inside the looping control structure and it will work the same.
It won't effect how your code works, just a style concern.
Reading your code, what are all the + " + supposed to do? I think taking them out would help.
I would also suggest viewing the source code from the browser that your servlet is generating. That should give you a clue.


!_I_Know_Kung_Fu_!
Kerry Shannon
Ranch Hand

Joined: May 08, 2001
Posts: 31
OK. Thanks. That seems to make sense. We will try that.
(Is it missing a %> following the while {?)
Kerry Shannon
Ranch Hand

Joined: May 08, 2001
Posts: 31
Andrew,
We looked at the generated source, but still had problems.
We are trying Mak's suggestion to see if we can make it work. Just too many questions, and not enough examples, that seemed to show how to loop and create the thml with the java included.
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

Did the generated source have the proper values for the height and width? Did it have any funny syntactical problems?
There is no problem with <% %> in Mak's example.
But I don't see how his example helps you at all. You don't want to populate the form with values from a DB, do you?
Also Mak's code will make a new row for each text input, is this what you want?
If you tell me exactly what you want, I could probably show you code that would work, but it won't help you understand the principles behind why it works this way.
The key to what you see is the generated html that is sent to the browser. Find your mistakes there and you can fix them.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
1. Comment off the out.write portion.
2. Just write 10 lines of hard-coded <tr>'s and <td>'s
3. For all <tr>'s finish with </tr> end tag. Because Netscape needs the end tag though IE doesn't care about </tr>
4. See if it works.
5. Then go one step further and include the dynamic portion.
As Andrew suggested , right click on the page generated , view source and check if generated html is proper.
regds
maha anna

[This message has been edited by maha anna (edited May 08, 2001).]
Kerry Shannon
Ranch Hand

Joined: May 08, 2001
Posts: 31
Yes, we are trying to populate a payroll time entry form from a database.
I think we worked thru the first set of problems merging the HTML with the java. It will display the form correctly.
Now moving into how to loop thru the display for a two week period, displaying data from the db if the employee entered it.
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

You want to populate the DB from the form? or the form from the DB?
You can do it either way, but just for clarity's sake.
Are you still having any problems?
Kerry Shannon
Ranch Hand

Joined: May 08, 2001
Posts: 31
Both - it's a payroll time entry form, so we will display saved data, allow new/updates, and save on request.
We are learning, so it's slow, but no current problems. We can close this topic. I will open new topics when needed. This list appears to be active, which is helpful for us. I will return the favor and contribute when I can.
 
jQuery in Action, 2nd edition
 
subject: Dynamic Form Creation within a Loop
 
Similar Threads
resizing table width
iterate problem in struts2
Want to convert my code in method
Access Data from Database By Submitting The select Values
document.forms[0].submit(); throws Invalid Argument in IE