Re: [studs-devel] access to datasource from taglib
Status: Beta
Brought to you by:
mojavelinux
|
From: Dan A. <dan...@gm...> - 2005-07-01 01:23:34
|
Beautiful suggestion. Although data access in tag libraries is one of
debate (possibly breaking MVC), I feel that a framework should not
restrict the user from choosing to do things a certain way.=20
Therefore, I will offer this method as an option, similar to Struts.
Additionally, I would really like to see the sql tag library ported to
Studs so that it is easy to throw together some SQL statements using
standard tag libraries. Anyone want to give it a go?
/dan
On 6/30/05, Timur Vafin <ti...@e-...> wrote:
> Hello.
>=20
> Let's assume, that it is required to create tag carrying out specific thi=
ngs in the project.
> Tag should take data from from DB by interaction with a class Manager
> which it is returned DataSource object reference.
>=20
>=20
> Let's name ours tag HtmlAreaTag, which detching data by the key.
>=20
> class HtmlAreaTag extends TagSupport
> {
> ....
>=20
> function getBlock()
> {
> $manager =3D& new HtmlAreaManager(TagUtils::getDat=
aSource($this->pageContext));
> $block =3D& $manager->getRowByAlias($this->getAl=
ias());
>=20
> return is_null($block) ? '' : $block->getHtml();
> }
>=20
> }
>=20
> For this purpose in TagUtils I suggest to add function
>=20
>=20
> /**
> * Return the default data source for the current module.
> *
> * @param request The HttpServletRequest we are processing
> * @return DataSource
> * @throws ServletException If the datasource with the specified =
key could not be found
> */
> function &getDataSource(&$pageContext, $key =3D null)
> {
> if (is_null($key))
> {
> $key =3D c('StudsConstants::DATA_SOURCE_KEY');
> }
>=20
> // identify the current module
> $request =3D& $pageContext->getRequest();
> $servletContext =3D& $pageContext->getServletContext();
> $moduleConfig =3D& ModuleUtils::getModuleConfig($reques=
t, $servletContext);
>=20
> // return the requested data source instance
> $ds =3D& $servletContext->getAttribute($key . $moduleConf=
ig->getPrefix());
> if ($ds =3D=3D null)
> {
> throw_exception(new ServletException('The datasou=
rce with the requested key \'' . $key . '\' has not been configured'));
> return;
> }
>=20
> return $ds;
> }
>=20
>=20
>=20
>=20
>=20
> --
> Send plain text only to timurv at e-kazan dot ru
> PGP key: http://wwwkeys.us.pgp.net:11371/pks/lookup?op=3Dget&search=3D0x=
425B9F0F
> --
> Timur Vafin
>=20
>=20
>=20
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id=16492&opclick
> _______________________________________________
> studs-devel mailing list
> stu...@li...
> https://lists.sourceforge.net/lists/listinfo/studs-devel
>=20
--=20
Open Source Advocacy
http://www.mojavelinux.com
|