SourceForge.net Logo


Home | Download | Powered by SourceForge.net

Providers: Select Solutions

Providers generates object collections to be used in web applications, mainly in filling html select controls with options tags.

When you are creating a JSP page and you have to fill a html select with options, you have to set the collection in the request or session to be in scope for iterating it and generating options tag inside select tag. If you have the same select in different use cases and JSPs, you have to get that collection for each use case.

Using providers, you can delegate the collection generation to Providers and just place a tag that creates options tags. You can use a basic provider and create filtering providers.

Providers can use fixed Values provider, JDBC Provider, and you can plug as many providers you need. These providers are declared in a XML file and are accessed through Taglibs.

Providers comes with some aditional tags for Select manipulation, like ComboSelectTag that allows you to create dependant drop downs very simply. And SelectTag, that has a listener that matches the leters you write on the select and chooses the right option.

Taglibs

Providers comes with a set of taglibs:

OptionsTag
This tag allows you to create options inside a select tag, populated by a Provider. This tag is similar to Struts OptionsTag.

WriteTag
With this tag you can write a description given an ID. This is similar to Struts WriteTag, but if you just have an id and want a description, you can use this tag.

ComboSelectTag
This tag generates the needed JavaScript for creating dependant drop down selects. You supply it with a collection for each select in the dependency chain and it's ready to generate this functionality. This tag needs to be notified by SelectTag of what selects does it handle.

SelectTag
This tag is similar to Struts SelectTag but has the capability of work with comboSelectTag. In fact, this tag must be nested in ComboSelectTag for this last to work. Additionally, this tag can create script for detectiong matches of options while user "writes" on the select.

DefineTag
This tag allows you to define a new bean in a given scope with the collection returned from a provider. You can use it for example to iterate the collection in your JSP or to use it with other tag like DisplayTag to show a table.

Examples

Providers Configuration

Providers are declared in an xml file:


<providers>
	<provider name="countries" 
		className="ar.com.koalas.providers.FixedProvider">
		<set-property property="keyName" value="key"/>
		<set-property property="description" value="value"/>
		<value key="01" value="Argentina" tipo="SouthAmerica"/>
		<value key="02" value="Brasil" tipo="SouthAmerica"/>
		<value key="03" value="Italia" tipo="Europe"/>
		<value key="04" value="Espaņa" tipo="Europe"/>
	</provider>
	<provider name="southAmericanCountries" 
		className="ar.com.koalas.providers.RefProvider">
		<set-property property="reference" value="fixedTest"/>
		<set-property property="filter" value="//*[@tipo='SouthAmerica']"/>
	</provider>
	<provider name="cities" 
		className="ar.com.koalas.providers.JDBCProvider">
		<set-property property="jndi" value="MySqlDS"/>
		<set-property property="keyName" value="code"/>
		<set-property property="description" value="description"/>
		<param>
			<param-name>query</param-name>
			<param-value>select * from cities</param-value>
		</param>
	</provider>
</providers>

countries provider uses a fixed provider and has a declaration of countries. southAmericanCountries uses a reference provider that filters countries using XPath, to get only south american countries. Finally, cities provider uses JDBC provider to obtain a collection with an SQL statement.

Providers JSP usage

These providers are used in the JSP in the following way:


<%@ taglib uri="/WEB-INF/tld/providers.tld" prefix="prv" %>
<html>
<body>
<form name="test">
<select name="selTest">
	<prv:options provider="fixedTest"/>
</select>
<select name="selTest">
	<prv:options provider="refTest"/>
</select>
</form>
</body>
</html>

ComboSelect example (new features!)

In the previous Providers version, you needed to supply a collection in a matrix fashion and set it in the request scope in order to CombSelectTag to work, and indicating the "metadata" of the collection.
Currently, this is supported for backwards compatibility but now this functionality can be achieved as follows:

We have 3 database tables with te following information:

COUNTRIES
idCountrycountry
1Argentina
2Brasil
STATES
idCountryidStatestate
101Buenos Aires
102Cordoba
209Rio de Janeiro
222Bahia
CITIES
idCountryidStateidCitycity
10156Tandil
10177Ramos Mejia
10289Carlos Paz
209A6Ipanema
222A1Salvador De Bahia

Afterwards, you define 3 JDBCProviders to get data from that tables:


	<provider name="JDBCCountries" 
		className="ar.com.koalas.providers.JDBCProvider">
		<set-property property="jndi" value="MSSQLServer"/>
		<set-property property="initialContext" 
			value="java:comp/env"/>		
		<set-property property="keyName" value="idcountry"/>
		<set-property property="description" value="country"/>
		<param>
			<param-name>query</param-name>
			<param-value>select * from countries</param-value>
		</param>
	</provider>

	<provider name="JDBCStates" 
		className="ar.com.koalas.providers.JDBCProvider">
		<set-property property="jndi" value="MSSQLServer"/>
		<set-property property="initialContext" 
			value="java:comp/env"/>		
		<set-property property="keyName" value="idstate"/>
		<set-property property="description" value="state"/>
		<param>
			<param-name>query</param-name>
			<param-value>select * from states</param-value>
		</param>
	</provider>

	<provider name="JDBCCities" 
		className="ar.com.koalas.providers.JDBCProvider">
		<set-property property="jndi" value="MSSQLServer"/>
		<set-property property="initialContext" 
			value="java:comp/env"/>		
		<set-property property="keyName" value="idcity"/>
		<set-property property="description" value="city"/>
		<param>
			<param-name>query</param-name>
			<param-value>select * from cities</param-value>
		</param>
	</provider>	


Then, assuming that the database connection is available in MSSQLServer jndi name, you just place the following tags in the JSP page:


<%@ taglib uri="/WEB-INF/tld/providers.tld" prefix="prv" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<html>
<body>
<h1>ComboSelect Example</h1>
<p>These selects are dependant.
<html:form action="demo">
<prv:comboselect>
	<prv:select property="country2" doMatches="true">
		<prv:options provider="JDBCCountries" />
	</prv:select>
	<prv:select property="state" doMatches="true">
		<prv:options provider="JDBCStates" />		
	</prv:select>
	<prv:select property="city" doMatches="true">
		<prv:options provider="JDBCCities" />		
	</prv:select>
</prv:comboselect>
</html:form>
</body>
</html>

Also, SelectTag has an attribute doMatches, that generates a JavaScript to allow you to write on the select and this select will do matches to find the corresponding option.

HTML generated will be seen like this:



DefineTag example

If you need to define a bean containing the collection returned by a provider, you can use this tag:


<prv:define id="collectionBean" toScope="request" provider="fixedTest"/>

After this, you could use "collectionBean" to iterate it: this bean has the collection returned by fixedTest provider.

Downloads

You can download Providers from SourceForge.net.

Providers is an Open Source project under GNU Lesser General Public License.

Contact information

Providers is developed by:



Home | Download | Powered by SourceForge.net