In this example we will build a web application for managing data about our business partners in following steps:
File dataDefinitions/organisation/Partner.mdd (somewhere in classpath):
name=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 commentsFile dataDefinitions/general/Country.mdd (somewhere in classpath):
name=char[60] ;Country iso2letterCode=fixed char[2];2-letter ISO code
partnerList.jsp will be showing the list of all partners, each entry with:
<%@ taglib uri="http://www.makumba.org/presentation" prefix="mak" %> <h2>Partners:</h2> <mak:list from="organisation.Partner p"> <a href="partner.jsp?partner=<mak:value expr="p"/>"> <mak:value expr="p.name"> </a>, <i><mak:value expr="p.city"/></i> <br> </mak:list> <hr> [<a href="partnerNew.jsp">New partner entry</a>]If we are starting with an empty database it will be at first rendered to: But once we enter some data it will look more like:
partner.jsp will be showing all fields of organisation.Partner objects.
<%@ 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"/><br> 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"/> </mak:object> <hr> [<a href="partnerList.jsp">List them all</a>]Is rendered to:
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:
<%@ taglib uri="http://www.makumba.org/presentation" prefix="mak" %> <h2>New partner</h2> <mak:newForm type="organisation.Partner" action="partnerList.jsp"> Name: <mak:input field="name"/> <br> City: <mak:input field="city"/> <br> Country: <mak:input field="country"/><br> <input type="submit" value="Create"> </mak:newForm> <hr> [<a href="partnerList.jsp">Back to list</a>]User can decide to omit city and country information as well, but due to
not null attribute of field name in MDD, Makumba will not create a new object unless some name is specified.
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)
<%@ 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"/><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:delete object="p" action="partnerList.jsp">Delete this</mak:delete> </mak:object> <hr> [<a href="partnerList.jsp">Back to list</a>]
For additional options see the specification of mak:editForm and mak:input.
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.