• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

adding textbox dynamically in struts

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 9567
12
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a look indexed properties.
 
Vikas Ramnani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9567
12
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting NullPointerException on method setVersionArray.
 
Joe Ess
Bartender
Posts: 9567
12
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes sense. I don't see you creating an array anywhere.
 
Vikas Ramnani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes my bad !
I got it working.
Thank you very much for your help.

Vikas
 
Joe Ess
Bartender
Posts: 9567
12
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




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
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!