aspose file tools*
The moose likes Struts and the fly likes adding textbox dynamically in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "adding textbox dynamically in struts" Watch "adding textbox dynamically in struts" New topic
Author

adding textbox dynamically in struts

Vikas Ramnani
Greenhorn

Joined: Sep 20, 2010
Posts: 4
Hello,
I saw similar queries have been asked in other topics, But even after reading that I could not lend up with a proper solution. So I am posting it in new thread.
Here is what I want to do, I want to have a Add button in my JSP which on click generate a textbox. This completely depends on user how many times he clicks on the Add button.
I have successfully implemented the java script part, But I am not sure How can I retrieve the information in those textboxes in my Struts action.

I have tried giving dynamically generated textboxes same name. I defined an ArrayList with the same name and getter, setter methods with that name in my Form Bean. But it didn't work.
Could anybody please tell me :
1. What kind of name should I give to the dynamically added textboxes ?
2. What kind of field should I define in my Form Bean to retrieve the information ?
3. What should be my getter setter methods for that particular field ?

Thank you very much in advance.

Best,
Vikas
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

have a look indexed properties.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Vikas Ramnani
Greenhorn

Joined: Sep 20, 2010
Posts: 4
Hi,
Thanks for replying.
I already read that link following that I made a skeleton which I am posting here

MY Java Script

My relevant Form part


In my Action I am using

form.getVersionArray(1);

Where form is instance of my Form Bean. But I am getting exception when I submit this form, I am new to struts I might have missed some details in that article, But I am kind of stuck. Please guide me where I am doing the mistake.

Best,
Vikas

JCE: Please UseCodeTags
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Vikas Ramnani wrote:Hi,
But I am getting exception when I submit this form, I am new to struts I might have missed some details in that article, But I am kind of stuck. Please guide me where I am doing the mistake.


What is the exception you are getting? Remember, the better question you ask, the better help we can be.
Vikas Ramnani
Greenhorn

Joined: Sep 20, 2010
Posts: 4
I am getting NullPointerException on method setVersionArray.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

That makes sense. I don't see you creating an array anywhere.
Vikas Ramnani
Greenhorn

Joined: Sep 20, 2010
Posts: 4
Oh yes my bad !
I got it working.
Thank you very much for your help.

Vikas
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Supraja Araveeti
Greenhorn

Joined: Feb 28, 2011
Posts: 1




can you please tell me where you have declared version Array.I am also getting the same null pointer exception.

This is my javascript code

var counter=0;

var cellThird = row.insertCell(2);
var e1 = document.createElement('input');
e1.type = 'text';
e1.name = "cnsIDArray["+counter+"]";

public String getCnsIDArray(int index)
{
return cnsIDArray[index];
}

public void setCnsIDArray(int index,String cnsID)
{
cnsIDArray[index] = cnsID; //Here I am getting exception
}

I am accessing the value in this way

needForm.getCnsIDArray(0)


please help me
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: adding textbox dynamically in struts