Displaying repetitive type information with displaytag and struts
Often when displaying a list of dtos, you have to display a lookup value from a code file or another table.
There are a three ways to do this:
1. Stuff the lookup value into another value on the dto your using - 2 queries
2. Custom dto or custom sql which joins the lookup table - 1 query but takes a long time to develop
3. One query for your dtos, one for your types/lookup values and then put in a form map and display the lookup value from the form map - 2 querys, but the jsp is not super intuitive
I think 3 is pretty cool you dont have to do any special custom dto work as long as you know the jsp its pretty.
I'm using a bean called fuelmaster which has a field on it called trtype, and there is a table called fueltype which has fuel type descriptions in it for the trtype.
Action.java
if (fuelForm.getFueltypeMap() == null
|| fuelForm.getFueltypeMap().size() == 0) {
//store lookup values in a map with trtype/idx as the key
FueltypeDao fueltypeDao = DaoFactory.getFueltypeDao();
Fueltype[] fueltypeArray = fueltypeDao.findWhereCompEquals(fuelForm
.getCompanyId());
HashMap map = new HashMap();
for (Fueltype fueltype : fueltypeArray) {
map.put(fueltype.getIdx(), fueltype);
}
fuelForm.setFueltypeMap(map);
}
...
//store your list of dtos in the form or in the request
fuelmasterList = getFuelManager().getFuelmasters(params);
log.info("fuelmasterList=" + fuelmasterList.size());
fuelForm.setResults(fuelmasterList);
JSP
<display:table
name="${fuelForm.results}"
requestURI="${requestUri}"
pagesize="${pagesize}"
id="fuelmaster"
class="displaytag"
cellpadding="0px" cellspacing="0px"
export="true"
defaultorder="ascending"
partialList="false"
style="vertical-align:top;"
>
.....
<display:column title="Description" style="text-align:left" sortable="true" headerClass="leftalign">
<c:set var="fueltypeDto" value="${fuelForm.fueltypeMap[fuelmaster.trtype]}" />
<c:out value="${fueltypeDto.descr}" />
</display:column>
There are a three ways to do this:
1. Stuff the lookup value into another value on the dto your using - 2 queries
2. Custom dto or custom sql which joins the lookup table - 1 query but takes a long time to develop
3. One query for your dtos, one for your types/lookup values and then put in a form map and display the lookup value from the form map - 2 querys, but the jsp is not super intuitive
I think 3 is pretty cool you dont have to do any special custom dto work as long as you know the jsp its pretty.
I'm using a bean called fuelmaster which has a field on it called trtype, and there is a table called fueltype which has fuel type descriptions in it for the trtype.
Action.java
if (fuelForm.getFueltypeMap() == null
|| fuelForm.getFueltypeMap().size() == 0) {
//store lookup values in a map with trtype/idx as the key
FueltypeDao fueltypeDao = DaoFactory.getFueltypeDao();
Fueltype[] fueltypeArray = fueltypeDao.findWhereCompEquals(fuelForm
.getCompanyId());
HashMap map = new HashMap();
for (Fueltype fueltype : fueltypeArray) {
map.put(fueltype.getIdx(), fueltype);
}
fuelForm.setFueltypeMap(map);
}
...
//store your list of dtos in the form or in the request
fuelmasterList = getFuelManager().getFuelmasters(params);
log.info("fuelmasterList=" + fuelmasterList.size());
fuelForm.setResults(fuelmasterList);
JSP
<display:table
name="${fuelForm.results}"
requestURI="${requestUri}"
pagesize="${pagesize}"
id="fuelmaster"
class="displaytag"
cellpadding="0px" cellspacing="0px"
export="true"
defaultorder="ascending"
partialList="false"
style="vertical-align:top;"
>
.....
<display:column title="Description" style="text-align:left" sortable="true" headerClass="leftalign">
<c:set var="fueltypeDto" value="${fuelForm.fueltypeMap[fuelmaster.trtype]}" />
<c:out value="${fueltypeDto.descr}" />
</display:column>
