aspose file tools*
The moose likes JSP and the fly likes Use Bean more than one time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Use Bean more than one time " Watch "Use Bean more than one time " New topic
Author

Use Bean more than one time

naro pad
Ranch Hand

Joined: May 07, 2008
Posts: 58

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?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
naro pad
Ranch Hand

Joined: May 07, 2008
Posts: 58

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: May 07, 2008
Posts: 58

...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

Joined: May 07, 2008
Posts: 58

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use Bean more than one time