Re: DHTML and Struts
Any form elements created dynamically on the client-side will have no intrinsic link to the ActionForm. However, this is not necessarily a problem... imagine if your ActionForm has this in it: private String firstName; public void setFirstName(String inFirstName) { firstName = inFirstName; } public String getFirstName() { return firstName; } What happens if your JSP *DOES NOT* include this form field? Obviously that will be just fine, Struts won't complain. Now, what happens if you dynamically add that field to your HTML form via JavaScript, and then submit the form? Again, this will be just fine, Struts will happily populate the firstName field in the ActionForm. It doesn't matter that it wasn't there when the HTML for the page was originally rendered by the JSP. In the case of indexed properties, the same is true... if you dynamically add a field to the HTML form, so long as the name follows the index naming paradigm, it will be populated in the ActionForm when submitted. The code you have here looks basically correct, with one possible exception... setting innerHTML doesn't necessarily add anything to the DOM. So, when the form is submitted, the fields you dynamically added may not be sent (I believe it will work in some browsers, but not in others... I'd have to go test to verify this, but that's what's in my memory). Instead, you should use DOM methods to create your new field and append it to the form, that should alleviate that problem. This is generally the preferred method to work with dynamic content anyway. So, your add method should be something like function add() { var newField = document.createElement(input); newField.type = text; newField.name = foo[ + count + ]; var newCell = document.createElement(td); newCell.appendChild (newField); var newRow = document.createElement(tr); newRow.appendChild(newCell); var theTable = document.getElementById(t1); theTable.appendChild(newRow); count++; } Frank ok this is actually fanatsticThanks a tonne. But small problem, this thing doesnt work on IE(and yes, like everyone, my target audience also has it as there primary browser). I mean the rows dont get added to the page. It stays static, doesnt throw any javascript errors either.. could you test it out on your side?? I have yahoo toolbar on my IE. could that be causing the problem?? I have IE 6 and Firefox 1.5.0.6 It works easily on firefox. -- Puneet
Re: DHTML and Struts
On 8/3/06, Puneet Lakhina [EMAIL PROTECTED] wrote: Any form elements created dynamically on the client-side will have no intrinsic link to the ActionForm. However, this is not necessarily a problem... imagine if your ActionForm has this in it: private String firstName; public void setFirstName(String inFirstName) { firstName = inFirstName; } public String getFirstName() { return firstName; } What happens if your JSP *DOES NOT* include this form field? Obviously that will be just fine, Struts won't complain. Now, what happens if you dynamically add that field to your HTML form via JavaScript, and then submit the form? Again, this will be just fine, Struts will happily populate the firstName field in the ActionForm. It doesn't matter that it wasn't there when the HTML for the page was originally rendered by the JSP. In the case of indexed properties, the same is true... if you dynamically add a field to the HTML form, so long as the name follows the index naming paradigm, it will be populated in the ActionForm when submitted. The code you have here looks basically correct, with one possible exception... setting innerHTML doesn't necessarily add anything to the DOM. So, when the form is submitted, the fields you dynamically added may not be sent (I believe it will work in some browsers, but not in others... I'd have to go test to verify this, but that's what's in my memory). Instead, you should use DOM methods to create your new field and append it to the form, that should alleviate that problem. This is generally the preferred method to work with dynamic content anyway. So, your add method should be something like function add() { var newField = document.createElement(input); newField.type = text; newField.name = foo[ + count + ]; var newCell = document.createElement(td); newCell.appendChild (newField); var newRow = document.createElement(tr); newRow.appendChild(newCell); var theTable = document.getElementById(t1); theTable.appendChild(newRow); count++; } Frank ok this is actually fanatsticThanks a tonne. But small problem, this thing doesnt work on IE(and yes, like everyone, my target audience also has it as there primary browser). I mean the rows dont get added to the page. It stays static, doesnt throw any javascript errors either.. could you test it out on your side?? I have yahoo toolbar on my IE. could that be causing the problem?? I have IE 6 and Firefox 1.5.0.6 It works easily on firefox. -- Puneet ok.. got it to work on IE too. Some javascript trial and error. This thing works, why and how the earlier thing doesnt work on IE will take time to figure out tha javascript function count=1;//one cell is already there using function add() { var theTable = document.getElementById(t1); var row = theTable.insertRow(count); var newField = document.createElement(input); newField.type = text; newField.name = list[ + count + ]; var newCell = row.insertCell(0);/*you could have some kind of count here if u want multiple cells*/ newCell.appendChild(newField); count++; } -- Puneet
Re: DHTML and Struts
Yeah, leave it to IE to not work with DOM-compliant code :) I guess I only tried it in FF, which is odd since I don't generally use FF (it was probably just open at the time!). Glad you got it working! Frank Puneet Lakhina wrote: On 8/3/06, Puneet Lakhina [EMAIL PROTECTED] wrote: Any form elements created dynamically on the client-side will have no intrinsic link to the ActionForm. However, this is not necessarily a problem... imagine if your ActionForm has this in it: private String firstName; public void setFirstName(String inFirstName) { firstName = inFirstName; } public String getFirstName() { return firstName; } What happens if your JSP *DOES NOT* include this form field? Obviously that will be just fine, Struts won't complain. Now, what happens if you dynamically add that field to your HTML form via JavaScript, and then submit the form? Again, this will be just fine, Struts will happily populate the firstName field in the ActionForm. It doesn't matter that it wasn't there when the HTML for the page was originally rendered by the JSP. In the case of indexed properties, the same is true... if you dynamically add a field to the HTML form, so long as the name follows the index naming paradigm, it will be populated in the ActionForm when submitted. The code you have here looks basically correct, with one possible exception... setting innerHTML doesn't necessarily add anything to the DOM. So, when the form is submitted, the fields you dynamically added may not be sent (I believe it will work in some browsers, but not in others... I'd have to go test to verify this, but that's what's in my memory). Instead, you should use DOM methods to create your new field and append it to the form, that should alleviate that problem. This is generally the preferred method to work with dynamic content anyway. So, your add method should be something like function add() { var newField = document.createElement(input); newField.type = text; newField.name = foo[ + count + ]; var newCell = document.createElement(td); newCell.appendChild (newField); var newRow = document.createElement(tr); newRow.appendChild(newCell); var theTable = document.getElementById(t1); theTable.appendChild(newRow); count++; } Frank ok this is actually fanatsticThanks a tonne. But small problem, this thing doesnt work on IE(and yes, like everyone, my target audience also has it as there primary browser). I mean the rows dont get added to the page. It stays static, doesnt throw any javascript errors either.. could you test it out on your side?? I have yahoo toolbar on my IE. could that be causing the problem?? I have IE 6 and Firefox 1.5.0.6 It works easily on firefox. -- Puneet ok.. got it to work on IE too. Some javascript trial and error. This thing works, why and how the earlier thing doesnt work on IE will take time to figure out tha javascript function count=1;//one cell is already there using function add() { var theTable = document.getElementById(t1); var row = theTable.insertRow(count); var newField = document.createElement(input); newField.type = text; newField.name = list[ + count + ]; var newCell = row.insertCell(0);/*you could have some kind of count here if u want multiple cells*/ newCell.appendChild(newField); count++; } -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com AIM/Yahoo: fzammetti MSN: [EMAIL PROTECTED] Author of Practical Ajax Projects With Java Technology (2006, Apress, ISBN 1-59059-695-1) Java Web Parts - http://javawebparts.sourceforge.net Supplying the wheel, so you don't have to reinvent it! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DHTML and Struts
Any form elements created dynamically on the client-side will have no intrinsic link to the ActionForm. However, this is not necessarily a problem... imagine if your ActionForm has this in it: private String firstName; public void setFirstName(String inFirstName) { firstName = inFirstName; } public String getFirstName() { return firstName; } What happens if your JSP *DOES NOT* include this form field? Obviously that will be just fine, Struts won't complain. Now, what happens if you dynamically add that field to your HTML form via JavaScript, and then submit the form? Again, this will be just fine, Struts will happily populate the firstName field in the ActionForm. It doesn't matter that it wasn't there when the HTML for the page was originally rendered by the JSP. In the case of indexed properties, the same is true... if you dynamically add a field to the HTML form, so long as the name follows the index naming paradigm, it will be populated in the ActionForm when submitted. The code you have here looks basically correct, with one possible exception... setting innerHTML doesn't necessarily add anything to the DOM. So, when the form is submitted, the fields you dynamically added may not be sent (I believe it will work in some browsers, but not in others... I'd have to go test to verify this, but that's what's in my memory). Instead, you should use DOM methods to create your new field and append it to the form, that should alleviate that problem. This is generally the preferred method to work with dynamic content anyway. So, your add method should be something like function add() { var newField = document.createElement(input); newField.type = text; newField.name = foo[ + count + ]; var newCell = document.createElement(td); newCell.appendChild(newField); var newRow = document.createElement(tr); newRow.appendChild(newCell); var theTable = document.getElementById(t1); theTable.appendChild(newRow); count++; } Frank -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com AIM/Yahoo: fzammetti MSN: [EMAIL PROTECTED] Author of Practical Ajax Projects With Java Technology (2006, Apress, ISBN 1-59059-695-1) Java Web Parts - http://javawebparts.sourceforge.net Supplying the wheel, so you don't have to reinvent it! On Wed, August 2, 2006 12:48 am, Puneet Lakhina wrote: you were hung up (maybe I read into your question incorrectly). So are you actually hung up on the JavaScript to dynamically add fields? Yes, i am able to add text fields to my page, but I dont know what all attributes to specify in the input tag so that my user bean recieves the values from the dynamically added text fields. i.e. script language=javascript count=1; function add() { var row = document.getElementById('t1').insertRow(count); var cell=row.insertCell(0); cell.innerHTML=input type=text name=foo[ + count + ] + / count++; } /script input type=button onclick=add() / table id=t1 tr td html:text property=foo[0] /td /tr /table /table -- Puneet - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DHTML and Struts
http://struts.apache.org/1.x/userGuide/building_controller.html Specifically, section 4.3.3 Map-backed ActionForms. have already read that. But in that the page is generated dynamically, it doesnt change once rendered on the client, which is what I want to do. -- Puneet
Re: DHTML and Struts
On Tue, August 1, 2006 5:05 am, Puneet Lakhina wrote: http://struts.apache.org/1.x/userGuide/building_controller.html Specifically, section 4.3.3 Map-backed ActionForms. have already read that. But in that the page is generated dynamically, it doesnt change once rendered on the client, which is what I want to do. Correct, but the tricky part is when the submission hits the ActionForm, which is where that information comes into play. That's where I thought you were hung up (maybe I read into your question incorrectly). So are you actually hung up on the JavaScript to dynamically add fields? Puneet Frank - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DHTML and Struts
you were hung up (maybe I read into your question incorrectly). So are you actually hung up on the JavaScript to dynamically add fields? Yes, i am able to add text fields to my page, but I dont know what all attributes to specify in the input tag so that my user bean recieves the values from the dynamically added text fields. i.e. script language=javascript count=1; function add() { var row = document.getElementById('t1').insertRow(count); var cell=row.insertCell(0); cell.innerHTML=input type=text name=foo[ + count + ] + / count++; } /script input type=button onclick=add() / table id=t1 tr td html:text property=foo[0] /td /tr /table /table -- Puneet
DHTML and Struts
I have a set of text fields on a form. but the number of the text fields il need is soemthing that depends on the user using the application. So i have used DHTML to dynamically add a text field to the form. ofcourse i have used normal html tags for the dynamically added text field. But the problem is that this data never reaches my form bean. Is it not possible to use dhtml in combination with struts?? thanks -- Puneet
Re: DHTML and Struts
Hi, Have a look here: http://struts.apache.org/1.x/userGuide/building_controller.html Specifically, section 4.3.3 Map-backed ActionForms. Frank Puneet Lakhina wrote: I have a set of text fields on a form. but the number of the text fields il need is soemthing that depends on the user using the application. So i have used DHTML to dynamically add a text field to the form. ofcourse i have used normal html tags for the dynamically added text field. But the problem is that this data never reaches my form bean. Is it not possible to use dhtml in combination with struts?? thanks -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com AIM/Yahoo: fzammetti MSN: [EMAIL PROTECTED] Author of Practical Ajax Projects With Java Technology (2006, Apress, ISBN 1-59059-695-1) Java Web Parts - http://javawebparts.sourceforge.net Supplying the wheel, so you don't have to reinvent it! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]