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?

<%@ page contentType="text/html" %>
<%@ page session="true" %>
<%@ page language="java" %>
<%@ page autoFlush="true" import=".*, java.util.*"%>
<%@ page import="java.util.*,java.io.*"%>
<jsp:useBean id="bean id" class="jdbc driver name" scope="application" />
<jsp:useBean id="bean id" class="java pgm name" scope="page" />

check this and leave a comment..

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.*"%>
<jsp:useBean id="bean id" class="jdbc driver name" scope="application" />
<jsp:useBean id="bean id" class="java pgm name" scope="page" />

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.*"%>
<jsp:useBean id="bean id" class="jdbc driver name" scope="application" />
<jsp:useBean id="bean id" class="java pgm name" scope="page" />

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?

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

This article has been dead for over six months. Start a new discussion instead.