Search in sources :

Example 1 with CallBackDropdownHelper

use of org.jaffa.util.CallBackDropdownHelper in project jaffa-framework by jaffa-projects.

the class DropDownTag method getHtml.

private String getHtml() {
    String idPrefix = getHtmlIdPrefix();
    StringBuffer b = new StringBuffer();
    b.append("<select id = \"" + idPrefix + "\"" + (TagHelper.isEnclosed(pageContext) ? "" : " name=\"" + getField() + "WV\"") + " class=\"WidgetDropDown\">\n");
    Object widgetValueObject = m_model.getWidgetValue();
    String widgetValue = widgetValueObject != null ? m_propertyRuleIntrospector.format(widgetValueObject) : m_model.getStringValue();
    // Build an option for display purposes.
    if (this.getDomain() != null && widgetValue != null && widgetValue.length() > 0) {
        CriteriaElementDto[] criteriaElementDtos;
        criteriaElementDtos = new CriteriaElementDto[1];
        CallBackDropdownHelper cbddHelper = new CallBackDropdownHelper();
        CriteriaElementDto criteriaElementDto = new CriteriaElementDto();
        criteriaElementDto.setFieldName(this.getDropdownValueField());
        criteriaElementDto.setCriteria(StringCriteriaField.getStringCriteriaField(CriteriaField.RELATIONAL_EQUALS, widgetValue, null));
        criteriaElementDtos[0] = criteriaElementDto;
        try {
            CodeHelperOutElementDto m_dropDownCodes = cbddHelper.getOptions((HttpServletRequest) pageContext.getRequest(), this.getDropdownValueField(), this.getDropdownDescField(), this.getDomain(), criteriaElementDtos);
            for (int i = 0; i < m_dropDownCodes.getCodeHelperOutCodeDtoCount(); i++) {
                m_model.addOption("" + m_dropDownCodes.getCodeHelperOutCodeDto(i).getDescription(), "" + m_dropDownCodes.getCodeHelperOutCodeDto(i).getCode());
            }
        } catch (ApplicationExceptions e) {
        } catch (FrameworkException e) {
        }
    }
    if (widgetValue == null)
        widgetValue = "";
    // Loop through display columns
    List options = m_model.getOptions();
    if (options != null) {
        for (Iterator i = options.iterator(); i.hasNext(); ) {
            SimpleWidgetModel.Option option = (SimpleWidgetModel.Option) i.next();
            String label = option.getLabel();
            if (label != null)
                label = MessageHelper.replaceTokens(pageContext, label);
            widgetValueObject = option.getWidgetValue();
            String value = widgetValueObject != null ? m_propertyRuleIntrospector.format(widgetValueObject) : option.getStringValue();
            if (value == null)
                value = "";
            b.append("<option value=\"" + StringHelper.convertToHTML(value) + "\"" + (value.equals(widgetValue) ? " SELECTED" : "") + ">" + label + "</option>\n");
        }
    }
    b.append("</select>\n");
    b.append(getWidgetRegistrationScript(idPrefix, false));
    return b.toString();
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) CallBackDropdownHelper(org.jaffa.util.CallBackDropdownHelper) FrameworkException(org.jaffa.exceptions.FrameworkException) CodeHelperOutElementDto(org.jaffa.components.codehelper.dto.CodeHelperOutElementDto) SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel) CriteriaElementDto(org.jaffa.components.codehelper.dto.CriteriaElementDto)

Aggregations

CodeHelperOutElementDto (org.jaffa.components.codehelper.dto.CodeHelperOutElementDto)1 CriteriaElementDto (org.jaffa.components.codehelper.dto.CriteriaElementDto)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 SimpleWidgetModel (org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)1 CallBackDropdownHelper (org.jaffa.util.CallBackDropdownHelper)1