• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Use Bean more than one time

 
Ranch Hand
Posts: 58
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok... I will try to explain.
I hope you will understand what I'm trying to do

I have a form which has dynamic adding of textfields. I fill let say a book(title,author,year,edition) and if I want to add another book I click on a button creates me new text fields for entering the new book.(I have a table below the button which displays me the books with the textfiels inside).

Each time I create a new book to enter values I have put name and id of the textfield to be created dynamically.

Now when I'm submitting my form if it was one book I could use the following to save the values:

<jsp:useBean id="book" class="beans.book" scope="request"/>
<jsp:setProperty name="book" property="*"/>

Now I can add as many books I want how can I use the same bean to save them all seperate or I can't. What can I do?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The setProperty mechanism has it's limits.

In a case like this, I would (in the controller) loop through the fields and create a list or array of book beans.
 
naro pad
Ranch Hand
Posts: 58
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok because I'm new to jsp world...can you provide me with a reference to look at.
This is the only way to do that?

Thanks in advance
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The useBean and setProperty tags are somewhat outdated.

These days, the accepted best practice is to write your application using the Model, View, Controller pattern (MVC) and then use EL and JSTL in your JSPs to do what ever scripting is necessary to build the HTML output.
 
naro pad
Ranch Hand
Posts: 58
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...Model, View, Controller pattern (MVC) and then use EL and JSTL in your JSPs to do what ever scripting is necessary to build the HTML output...


Sorry if I'm a little insistent but because I don't have time to learn new things and to change my whole application is it possible to explain me or provide me a reference how to make a list or an array of beans
 
naro pad
Ranch Hand
Posts: 58
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to make loop which it will creates beans but I don't know how the syntax is. I want to pass the 'i' to the id of the bean but I have syntax error

<% for(int i=0;i<=8;i++){%>
<jsp:useBean id=<%="book" +i%> class="beans.book" scope="request"/>

<%}%>

Can anyone provide me the right syntax?
Thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic