You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adolfo Miguelez <pe...@hotmail.com> on 2002/07/11 10:59:36 UTC

custom tags accessing database (MVC model review)

Hi All,

some of our development teams has implemented view helpers as custom tags, 
which in turn access directly to database. However, we guess that such an 
approach is not correct since it does not match Struts/MVC models.

We suggest that a better aproach would be leaving an Action to deal with 
database, and making up some kind of value object, which, in turn, could be 
used for custom tag for rendering the data.

I would be grateful for some pointer, reference or arguement against such an 
approach or, confirmations that it is correct if so.

Thanks in advance,

Adolfo.




_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: custom tags accessing database (MVC model review)

Posted by Jacob Hookom <ho...@uwec.edu>.
I developed what I call the JFuse library which uses an action/map setup
for taking result sets and mapping them to objects as per an xml config
file:

<jfuse-config>
<data-sources>
	<jndi-source
		alias="cp"
		path="java:comp/env/jdbc/colorpath"
		life="20"
	/>
<data-sources>
<actions>
	<action	alias="act_get_user"
			dataSource="cp"
			sql="select usrUsrID, usrEmail, usrPassword,
usrCreated 				from tbl_user where usrEmail =
?"
	/>
	<action alias="act_permission_insert"
		dataSource="cp"
		sql="{CALL sp_security_insert(?,?,?)}"
	/>
</actions>
<data-maps>
	<data-map className="com.dds.module.bean.User" alias="map_user">
		<property sql="usrUsrID" property="id"/>
		<property sql="usrEmail" property="login"/>
		<property sql="usrPassword" property="password"/>
		<property sql="usrCreated" property="created"/>
	</data-map>
</data-maps>
</jfuse-config>

Datasources are aliased and defined first "cp" for example, and then
actions are bound to the datasource and callable.  Finally, JFuse gives
you the option of mapping your resultset to objects using BeanUtils as
configured by a data-map entry in the xml config.  It also implements
MVC, so either from tags:

<jf:prepare name="qsel_workspaces" dataSource="cp">
	<jf:sql>
		SELECT wrkWrkID, wrkName, wrkDescription, wrkCreated
		FROM tbl_workspace
		WHERE wrkCltID = ?
		ORDER BY wrkName
	</jf:sql>
	<jf:inparam
pos="1"><%=request.getParameter("clientId")%></jf:inparam>
</jf:prepare>
<jf:map name="qsel_workspaces" id="workspaces" type="map_workspace"
scope="page"/>

Or from the Action:

// get context application
JFuse jfuse = JFuseContext.getInstance(servlet.getServletContext());

// insert new client in the database [setup params]
Action insertAction = jfuse.getAction("act_client_insert");
Object[] params = new Object[3];
params[0] = info.getName().trim();
params[1] = info.getServerAlias();
params[2] = "/" + info.getFileContext().trim();
			
// finally, update the database with new client
jfuse.doUpdate(insertAction, params);


I hope this gives you some ideas.

Jake Hookom
University of Wisconsin, Eau Claire

-----Original Message-----
From: Adolfo Miguelez [mailto:pelly69@hotmail.com] 
Sent: Thursday, July 11, 2002 4:00 AM
To: struts-user@jakarta.apache.org
Subject: custom tags accessing database (MVC model review)

Hi All,

some of our development teams has implemented view helpers as custom
tags, 
which in turn access directly to database. However, we guess that such
an 
approach is not correct since it does not match Struts/MVC models.

We suggest that a better aproach would be leaving an Action to deal with

database, and making up some kind of value object, which, in turn, could
be 
used for custom tag for rendering the data.

I would be grateful for some pointer, reference or arguement against
such an 
approach or, confirmations that it is correct if so.

Thanks in advance,

Adolfo.




_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.373 / Virus Database: 208 - Release Date: 7/1/2002
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.373 / Virus Database: 208 - Release Date: 7/1/2002
 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>