Skip to content
Mrdigs edited this page Apr 9, 2014 · 10 revisions

The Molding System is a powerful feature of Bootstrap.jsp that allows you to knock out Components with the same characteristics time and time again just by setting the mold attribute in your JSP page.

The value of the mold attribute can either be the name of a class that extends the org.bootstrapjsp.mold.Mold class, or be resolved into one via the Bootstrap.jsp properties file, or an artibrary mold name whose attributes are defined in the properties file.

Let's define a simple properties based mold for the panel Component as an example. Place the following properties in your WEB-INF/classes/bootstrapjsp_local.properties file:

panel.mold.danger.context=danger
panel.mold.danger.label=Danger!

Now create a panel with 'danger' as the value of the mold attribute:

<b:panel mold="danger">You probably don't want to do that</b:panel>

The context and label attributes are found in the properties file and set on your panel:

<div class="panel panel-danger">
	<div class="panel-heading">
		<h3 class="panel-title">Danger!</h3>
	</div>
	<div class="panel-body">
		You probably don't want to do that
	</div>
</div>

Implementing a Mold

Properties based molds are quick and easy to use, but you may want to do something more complex with a mold other than defining simple attribute values. In these cases you can implement your own mold by extending the org.bootstrapjsp.mold.Mold class.

As a simple introduction, here is the equivalent mold to above implemented as a class:

import org.bootstrapjsp.mold.Mold;
import org.bootstrapjsp.tags.core.panel.Panel;

public class DangerPanelMold extends Mold<Panel> {

	@Override
	public void apply(Panel panel, String mold) {
		panel.setAttribute("context", "danger");
		panel.setAttribute("label", "Danger!");
	}
	
}

You can either use the class name as the value of your mold attribute, or define a mapping in the Bootstrap.jsp properties file:

panel.mold.danger=DangerPanelMold
<b:panel mold="DangerPanelMold">You probably don't want to do that</b:panel>
<b:panel mold="danger">You probably don't want to do that</b:panel>

See Composite Components for a more complex example of a mold implementation.

Clone this wiki locally