You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andy Cheng <an...@pos.st> on 2003/06/19 04:43:05 UTC

Struts and database

Hi! Would anyone give me some examples of database programming, which
lead from retrieving data to rendering view. (I mean real database, not
from XML files), e.g. any web site with source, or even better, some
simple example?  I am very confused on how to use beans from the model.
If there any book that focus on database programming?  I have been
searching on the web, but unable to find.
 
Andy Cheng
andy@pos.st

Re: Struts and database

Posted by Erik Price <ep...@ptc.com>.

Sloan Bowman wrote:
>     I will do my best to explain this but I will also point you in the 
> right direction. First off you need to read the Java Blueprints on using 
> DAO with J2ee. This will teach you the best methods of using Databases 
> by using the DAO to encapsulate the DataSource . Here is the link to the 
> Java Blueprints 
> http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html 
> read this complete document and it will help you out alot with how you 
> should use your databases in your applications.

And for excellent sample code of a J2EE application that uses DAO 
pattern without using EJBs see this one:

<http://java.sun.com/blueprints/code/adventure/1.0/docs/architecture.html>



Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Struts and database

Posted by Laurent PETIT <lp...@sqli.com>.
Hello,

Take a look at Commons-Scaffold on the apache-jakarta site, it uses
externalized SQL statements in properties files.


My 0.02 Euros ;-)

--
Laurent

----- Original Message -----
From: "Yansheng Lin" <ya...@isogis.com>
To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
Sent: Thursday, June 19, 2003 5:26 PM
Subject: RE: Struts and database



A follow up to the J2EE DAO Pattern:  I found that it helps a lot using
externalized SQL statements, i.e., build SQL statements in an XML file with
your
own DTD.  It's point #3 in that blueprint.  However, to this date I haven't
found any good examples online.  Also I sent an email to the blueprint team
asking how to pass multiple arguments(for example, a collection.)  If anyone
looked at the 'petsstore' example that comes with the blueprints, you would
notice that the number of parameters are hardcoded all the time in the Dao
related .xml files.  So still I don't know how to pass a collection as the
'input-mapping.'

I am just wondering if anyone is using externalized SQL statements in their
application as well. What's your view on it?

Thanks!

-----Original Message-----
From: Sloan Bowman [mailto:smileyq@nashlinux.com]
Sent: June 18, 2003 9:49 PM
To: Struts Users Mailing List
Subject: Re: Struts and database


I will do my best to explain this but I will also point you
in the right direction. First off you need to read the Java
Blueprints on using DAO with J2ee. This will teach you the best
methods of using Databases by using the DAO to encapsulate the
DataSource . Here is the link to the Java Blueprints
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.ht
ml
read this complete document and it will help you out alot with how
you should use your databases in your applications.
Lets use an example say for a User requesting a item from the
online store for our example. First you build the ActionForm which
stores the data sent by the form. The ActionForm is passed through
the FrontController which in turn dispatches you to the correct
Action. In our case the Action will be using methods from a class
which contains all of your Buisness logic.  Form example, we have a
ItemDAO which has a method getItem(int itemNum). This method returns
a ItemBean which stores all of the information about that item. This
Bean you are using to store all of the information is called a State
Bean (if I remember right, corrections are welcome). When you get the
ItemBean returned from the method getItem(int itemNum) you can then
add it to your session/request etc.. for example you could do
request.setAttribute("itemBean", itemBean). Now once you return the
ActionForward in the Action (Example: mapping.findForward("success"))
the itemBean will be part of the request and you acn access these
properties in the View using jsp, velocity etc.. I hope this helps
you out.

--Sloan

p.s. Sorry for the type o's I didn't proof read


>Hi! Would anyone give me some examples of database programming, which
>lead from retrieving data to rendering view. (I mean real database, not
>from XML files), e.g. any web site with source, or even better, some
>simple example?  I am very confused on how to use beans from the model.
>If there any book that focus on database programming?  I have been
>searching on the web, but unable to find.
>
>Andy Cheng
>andy@pos.st



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Struts and database

Posted by Yansheng Lin <ya...@isogis.com>.
A follow up to the J2EE DAO Pattern:  I found that it helps a lot using
externalized SQL statements, i.e., build SQL statements in an XML file with your
own DTD.  It's point #3 in that blueprint.  However, to this date I haven't
found any good examples online.  Also I sent an email to the blueprint team
asking how to pass multiple arguments(for example, a collection.)  If anyone
looked at the 'petsstore' example that comes with the blueprints, you would
notice that the number of parameters are hardcoded all the time in the Dao
related .xml files.  So still I don't know how to pass a collection as the
'input-mapping.'  

I am just wondering if anyone is using externalized SQL statements in their
application as well. What's your view on it?  

Thanks!

-----Original Message-----
From: Sloan Bowman [mailto:smileyq@nashlinux.com] 
Sent: June 18, 2003 9:49 PM
To: Struts Users Mailing List
Subject: Re: Struts and database


	I will do my best to explain this but I will also point you 
in the right direction. First off you need to read the Java 
Blueprints on using DAO with J2ee. This will teach you the best 
methods of using Databases by using the DAO to encapsulate the 
DataSource . Here is the link to the Java Blueprints 
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html 
read this complete document and it will help you out alot with how 
you should use your databases in your applications.
	Lets use an example say for a User requesting a item from the 
online store for our example. First you build the ActionForm which 
stores the data sent by the form. The ActionForm is passed through 
the FrontController which in turn dispatches you to the correct 
Action. In our case the Action will be using methods from a class 
which contains all of your Buisness logic.  Form example, we have a 
ItemDAO which has a method getItem(int itemNum). This method returns 
a ItemBean which stores all of the information about that item. This 
Bean you are using to store all of the information is called a State 
Bean (if I remember right, corrections are welcome). When you get the 
ItemBean returned from the method getItem(int itemNum) you can then 
add it to your session/request etc.. for example you could do 
request.setAttribute("itemBean", itemBean). Now once you return the 
ActionForward in the Action (Example: mapping.findForward("success")) 
the itemBean will be part of the request and you acn access these 
properties in the View using jsp, velocity etc.. I hope this helps 
you out.

--Sloan

p.s. Sorry for the type o's I didn't proof read


>Hi! Would anyone give me some examples of database programming, which
>lead from retrieving data to rendering view. (I mean real database, not
>from XML files), e.g. any web site with source, or even better, some
>simple example?  I am very confused on how to use beans from the model.
>If there any book that focus on database programming?  I have been
>searching on the web, but unable to find.
>
>Andy Cheng
>andy@pos.st



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Struts and database

Posted by Sloan Bowman <sm...@nashlinux.com>.
	I will do my best to explain this but I will also point you 
in the right direction. First off you need to read the Java 
Blueprints on using DAO with J2ee. This will teach you the best 
methods of using Databases by using the DAO to encapsulate the 
DataSource . Here is the link to the Java Blueprints 
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html 
read this complete document and it will help you out alot with how 
you should use your databases in your applications.
	Lets use an example say for a User requesting a item from the 
online store for our example. First you build the ActionForm which 
stores the data sent by the form. The ActionForm is passed through 
the FrontController which in turn dispatches you to the correct 
Action. In our case the Action will be using methods from a class 
which contains all of your Buisness logic.  Form example, we have a 
ItemDAO which has a method getItem(int itemNum). This method returns 
a ItemBean which stores all of the information about that item. This 
Bean you are using to store all of the information is called a State 
Bean (if I remember right, corrections are welcome). When you get the 
ItemBean returned from the method getItem(int itemNum) you can then 
add it to your session/request etc.. for example you could do 
request.setAttribute("itemBean", itemBean). Now once you return the 
ActionForward in the Action (Example: mapping.findForward("success")) 
the itemBean will be part of the request and you acn access these 
properties in the View using jsp, velocity etc.. I hope this helps 
you out.

--Sloan

p.s. Sorry for the type o's I didn't proof read


>Hi! Would anyone give me some examples of database programming, which
>lead from retrieving data to rendering view. (I mean real database, not
>from XML files), e.g. any web site with source, or even better, some
>simple example?  I am very confused on how to use beans from the model.
>If there any book that focus on database programming?  I have been
>searching on the web, but unable to find.
>
>Andy Cheng
>andy@pos.st



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


how to get the formbean in script

Posted by Duan Qiang <qd...@ilog.com.sg>.
Hi,

I have a formbean defined as "test", how can I get the formbean in JSP so
that I can better control it rather than using <bean:write name="test"
property = "xxx "/>.

I tried to use

<bean:define id="test" name="test" /> but I got the exception that "no test
found in any scope".

I have one question, when the formbean is initialized ? when the page
containing the formbean is shown for the first time, the bean should exists
in proper scope? write?

Thx.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org