}
@Override
public String generateHtml(FormEntryContext context) {
MessageSourceService messageSourceService = Context.getMessageSourceService();
AddressTemplate defaultLayoutTemplate = AddressSupport.getInstance().getDefaultLayoutTemplate();
TextFieldWidget textFieldWidget;
Map<String, String> fieldMap;
if (!isRegistered) {
registerWidgets(context);
isRegistered = true;
}
// have the date and time widgets generate their HTML
StringBuilder sb = new StringBuilder();
sb.append("<table>");
List<List<Map<String, String>>> fieldLines = defaultLayoutTemplate.getLines();
for (List<Map<String, String>> line : fieldLines) {
sb.append("<tr>");
int colIndex = 0;
for (Iterator<Map<String, String>> iterator = line.iterator(); iterator.hasNext();colIndex++ ) {
fieldMap = iterator.next();
if (fieldMap.get("isToken").equals(defaultLayoutTemplate.getLayoutToken())) {
String label = messageSourceService.getMessage(fieldMap.get("displayText"));
textFieldWidget = widgetMap.get(fieldMap.get("codeName"));
textFieldWidget.setTextFieldSize(Integer.parseInt(fieldMap.get("displaySize")));
sb.append("<td>").append(label).append("</td>");
if(!iterator.hasNext() && colIndex < defaultLayoutTemplate.getMaxTokens()){
sb.append("<td colspan='").append(defaultLayoutTemplate.getMaxTokens()-colIndex).append("'>");
}else{
sb.append("<td>");
}
sb.append(textFieldWidget.generateHtml(context)).append("</td>");
}