I have a scenario where i need to insert a row containing some check boxes.I use innerHTML for that.
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.
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.
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 screen.how to tackle this situation.
Joined: Feb 15, 2005
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.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.