In this example we will build a web application for managing data about our business partners in following steps:
The Makumba Data Definitions (MDDs) can be placed anywhere in the CLASSPATH, in the dataDefinitions folder.
dataDefinitions/organisation/Partner.mddname=not null char[40] ;Name city=char[40] ;City country= ptr general.Country ;Country phone=char[20] ;Phone fax=char[40] ;Fax email=char[40] ;E-Mail homepage=char[50] ;Home Page on the Internet comment=text ;Other comments personalContacts= set general.Person ; precise personal contacts at the partner
dataDefinitions/organisation/Country.mddname=char[60] ;Country iso2letterCode=fixed char[2];2-letter ISO code
dataDefinitions/organisation/Person.mddname=char[60] ;name birthdate=date ;birthdate
To be able to change the table in the database you need to add the following line to the database proprieties <server_name>_<database_engine>_<database_name>.properties, e.g. example/WEB-INF/classes/localhost_mysql_testdatabase.properties
alter#MDD_name=true(you should comment it after the changes: #alter#MDD_name=true)
In order to create the table or make the MDD changes available, just reload Tomcat (or any engine that implement Java Servlet API).
partnerList.jsp will be showing the list of all partners, each entry with:
If we are starting with an empty database it will be at first rendered to:example/parnerList.jsp<%@ taglib uri="http://www.makumba.org/presentation" prefix="mak" %> <h2>Partners:</h2> <mak:list from="organisation.Partner p"> <dt><a href="partner.jsp?partner=<mak:value expr="p"/>"> <mak:value expr="p.name"/> </a>, <i><mak:value expr="p.city"/></i> </dt> <dd><mak:list from="p.personalContacts c" separator="<br>"> <mak:value expr="c.name"/> </mak:list></dd> </mak:list> <hr> [<a href="partnerNew.jsp">New partner entry</a>]
partner.jsp will be showing all fields of organisation.Partner objects.
Is rendered to:example/partners.jsp<%@ taglib uri="http://www.makumba.org/presentation" prefix="mak" %> <mak:object from="organisation.Partner p" where="p=$partner"> <h2><mak:value expr="p.name"/></h2> <mak:value expr="p.city"/>, <mak:value expr="p.country.name"/> Home Page: <b><mak:value expr="p.homepage"/></b> <p> You can send them an email to: <mak:value expr="p.email"/><br> Call me: <b><mak:value expr="p.phone"/></b><br> Comment: <mak:value expr="p.comment"/> <p> <a href="partnerEdit.jsp?partner=<mak:value expr="p"/>">edit</a> </mak:object> <hr> [<a href="partnerList.jsp">List them all</a>]
You can send them an email to: info@example.com
Call me: +1 23 456789
Comment: They are very rich!!!
p.country.name was evaluated to "Bangladesh" automagically. Makumba joined the Partner and Country tables when performing the query, and can make even more sophisticated table joins when needed.
For additional options see the specification of mak:object and mak:value.
partnerNew.jsp will require only the basic info when
creating a new object:
example/partnerNew.jsp<%@ taglib uri="http://www.makumba.org/presentation" prefix="mak" %> <h2>New partner</h2> <mak:newForm type="organisation.Partner" action="partnerList.jsp"> Name: <mak:input name="name"/> <br> City: <mak:input name="city"/> <br> Country: <mak:input name="country"/> <a href="countryNew.jsp">Add countries</a><br> <input type="submit" value="Create"> </mak:newForm> <hr> [<a href="partnerList.jsp">Back to list</a>]
not null attribute of field name in the MDD, Makumba will not create a new object unless some name is specified.
Page countryNew.jsp looks almost the same as partnerNew.jsp:
example/countryNew.jsp<%@ taglib uri="http://www.makumba.org/presentation" prefix="mak" %> <h2>New country</h2> <mak:newForm type="general.Country" action="partnerList.jsp"> Name: <mak:input field="name"/> <br> ISO code: <mak:input field="iso2letterCode" size="5"/><br> <input type="submit" value="Add"> </mak:newForm> <hr> [<a href="partnerList.jsp">Back to list</a>]
For additional options see the specification of mak:newForm and mak:input.
partnerEdit.jsp we could edit all (non-fixed) fields, but here we decided to not support editing of some fields (Field name in this case)
example/partnerEdit.jsp<%@ taglib uri="http://www.makumba.org/presentation" prefix="mak" %> <mak:object from="organisation.Partner p" where="p=$partner"> <h2>Edit <mak:value expr="p.name"/></h2> <mak:editForm object="p" action="partnerList.jsp"> City: <mak:input field="city"/> <br> Country: <mak:input field="country"/> <a href="countryNew.jsp">Add countries</a><br> Home Page: <mak:input field="homepage"/> <p> Email: <mak:input field="email"/><br> Phone: <mak:input field="phone"/><br> Comment: <mak:input field="comment"/><br> <input type="submit" value="Save"> </mak:editForm> <mak:deleteLink object="p" action="partnerList.jsp">Delete this</mak:deleteLink> </mak:object> <hr> [<a href="partnerList.jsp">Back to list</a>]
For additional options see the specification of mak:editForm, mak:input and mak:deleteLink.
In order to keep your code as clean as possible, we advise you to break it down into small, human-managable files and include them in your pages with <jsp:include /> directive, eg:
<jsp:include page="header.jsp"/>You can also take some size of the .jsp files and improve their readability by seperating the layout specification into seperate Cascading Style Sheets.
For this example you will need to define the following methods in, for example, Logic.java. See how makumba looks for the handlers.
public void on_newPartner(Dictionary d, Attributes a, Database db) {}
public void on_editPartner(Pointer p, Dictionary d, Attributes a, Database db) {}
public void on_newCountry(Dictionary d, Attributes a, Database db) {}
public void on_deletePartner(Pointer p, Attributes a, Database db) {}
Do not forget that you have to compile after changing a java file.