File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes INNERHTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "INNERHTML" Watch "INNERHTML" New topic


Rick Charles

Joined: Jul 27, 2006
Posts: 25
HI Guys,

I have a scenario where i need to insert a row containing some check boxes.I use innerHTML for that.

function createAllowanceRow(){

var table = document.getElementById('test');
var row = table.insertRow();
var col1 = row.insertCell(0);
var col2 = row.insertCell(1);
var col3 = row.insertCell(2);
var col4 = row.insertCell(3);
var col5 = row.insertCell(4);
var col6 = row.insertCell(5);
col1.innerHTML = '<bean:message key="test"/>'+(i++);
col2.innerHTML = '<html:text property="test1" value=""/>';
col3.innerHTML = '<html:text property="test2" size="5" value=""/>';
its working fine but if i tr to checkbox .. i am getting "Cannot find bean org.apache.struts.taglib.html.BEAN in any scope" . I have been stuck with this for the past 2 days. if anybody can find a solution please lemme know.

And also is there is anyway that if i refresh the page or if i submit the form the rows which i generated using insert row is displayed in the screen.


Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
When you create HTML dynamically with INNERHTML, you must use regular HTML tags, not Struts tags. So, rather than create an <html:text> tag, you must create an <input type="text"> tag.

Struts tags can only be evaluated on the server and then rendered into regular HTML before being sent to the browser. Since JavaScript executes on the browser, you must deal exclusively with regular HTML, and not with tags that are interpreted on the server.

Consultant, Sima Solutions
Rick Charles

Joined: Jul 27, 2006
Posts: 25
Yeah i got it..... but if i submit the form or if i refresh the page the controls that i generated shud remain in the to tackle this situation.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The key to doing this is to make sure your ActionForm for the page gets populated with the changes made when the form is submitted. Normally it's Struts' job to do this, but you have to help it out.

First of all, you must represent the rows on your page as some type of List or Collection in your ActionClass. Secondly, you must use indexed properties in your JSP to represent the rows of data. Essentially, this means naming each input so that the number of the row it belongs to is part of the name. For example: employee[0].phone would be an indexed property for the phone number of the first employee in the list. This link explains more about how to use indexed properties.

Secondly, you have to make sure your ActionForm can handle an expanding list, since you're adding rows with JavaScript. To do this, you can use a "lazy initialization" technique in your getter methods. This link should give you some ideas about how to do that.
I agree. Here's the link:
subject: INNERHTML
It's not a secret anymore!