954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

collection of beans

Hi

I am trying to create something like online shop with products and a shopping basket. User can see an html form and edit it. The form is represented by bean. After editing it, he should be able to create new, or submit all products he edited (add actual bean to a some sort of collection or do something with collection of previously created beans).

The form page looks like this:

<html>....
<form action="addBean.jsp">
... some input elements, names matches with getters and setters of form bean
</form>


addBean.jsp

<jsp:useBean id="form" class="formBean" scope="session"/>
<jsp:setProperty name="form" property="*"/>
      //... now i want be able to do something like this:
      //"take this bean with values from form and add it to some sort of array or collection"


Does anybody have an idea?

paski
Newbie Poster
4 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

<%@ page contentType="text/html" %>
<%@ page session="true" %>
<%@ page language="java" %>
<%@ page autoFlush="true" import=".*, java.util.*"%>
<%@ page import="java.util.*,java.io.*"%>

check this and leave a comment..

hidash_in
Junior Poster in Training
86 posts since Oct 2007
Reputation Points: 1
Solved Threads: 0
 

check this also
<%@ page contentType="text/html" %>
<%@ page session="true" %>
<%@ page language="java" %>
<%@ page autoFlush="true" import=".*, java.util.*"%>
<%@ page import="java.util.*,java.io.*"%>

hidash_in
Junior Poster in Training
86 posts since Oct 2007
Reputation Points: 1
Solved Threads: 0
 
check this also <%@ page contentType="text/html" %> <%@ page session="true" %> <%@ page language="java" %> <%@ page autoFlush="true" import=".*, java.util.*"%> <%@ page import="java.util.*,java.io.*"%>

Oh, I forgot to mention, that that page directives and all that "header" stuff is in addBean.jsp file. Also I am able to get variables from bean :

You inserted number : <jsp:getProperty name="form" property="formNumber"/>


I thought about it and this crossed my mind:

..."header" stuff
<%
ArrayList<FormClass> formList = new ArrayList<FormClass>();
FormClass fc = new FormClass();
fc.setValue1(%><jsp:getProperty name="form" property="value1"/> <%);
fc.setValue2(%><jsp:getProperty name="form" property="value2"/> <%);
fc.setValue3(%><jsp:getProperty name="form" property="value3"/> <%);

.... and so on, so basicaly I can create a new instance of bean...

formList.add(fc);

... and add it to collection, but it seems too complicated (especially when form has about 30 fields :-)
%>


Is there any simple way to do it?

paski
Newbie Poster
4 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

I tried the code above, but all I got was errors. The problem is, that is transformed into out.write(...); a method returning void, so I cant get even a string representation of that value :-(

paski
Newbie Poster
4 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You