Search in sources :

Example 6 with SimpleWidgetModel

use of org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel in project jaffa-framework by jaffa-projects.

the class CheckBoxTag method otherDoStartTagOperations.

/**
 * This generates the HTML for the tag.
 */
public void otherDoStartTagOperations() {
    try {
        super.otherDoStartTagOperations();
    } catch (JspException e) {
        log.error("CheckBoxTag.otherDoStartTagOperations() error=" + e);
    }
    // Preprocess if within a Property widget
    IPropertyRuleIntrospector propertyRuleIntrospector = lookupPropertyTag();
    // raise an error, if the 'field' is null
    if (getField() == null) {
        String str = "The " + TAG_NAME + " requires 'field' parameter to be supplied or it should be within a PropertyTag";
        log.error(str);
        throw new MissingParametersRuntimeException(str);
    }
    // Get the formtag from the page & register the widget
    FormTag formTag = TagHelper.getFormTag(pageContext);
    if (formTag == null) {
        String str = "The " + TAG_NAME + " should be inside a FormTag";
        log.error(str);
        throw new OuterFormTagMissingRuntimeException(str);
    }
    // Will hold the required html
    String html = null;
    // Get the model
    SimpleWidgetModel model = null;
    try {
        model = (SimpleWidgetModel) TagHelper.getModel(pageContext, getField(), TAG_NAME);
    } catch (ClassCastException e) {
        String str = "Wrong WidgetModel for " + TAG_NAME + " on field " + getField();
        log.error(str, e);
        throw new JspWriteRuntimeException(str, e);
    }
    // Check for an IPropertyRuleIntrospector, if this tag is not within a Property widget
    try {
        if (propertyRuleIntrospector == null)
            propertyRuleIntrospector = TagHelper.getPropertyRuleIntrospector(pageContext, getField());
        // Wrap the propertyRuleIntrospector
        propertyRuleIntrospector = TagHelper.wrapPropertyRuleIntrospector(propertyRuleIntrospector, model);
    } catch (JspException e) {
        log.error("CheckBoxTag.otherDoStartTagOperations(): error property inspector: " + e);
    }
    if (propertyRuleIntrospector.isHidden()) {
        // Display the (Restricted) text for a hidden field
        html = TagHelper.getTextForHiddenField(pageContext);
    } else {
        if (model != null) {
            if (propertyRuleIntrospector.isReadOnly()) {
                // Render a readOnly field as a displayOnly checkbox
                m_displayOnly = true;
                if (m_type != null && m_type.equalsIgnoreCase("HTML"))
                    m_type = "IMAGE";
            }
            html = getHtml(getHtmlIdPrefix(), model);
        }
    }
    if (html != null) {
        // Write the HTML
        JspWriter out = pageContext.getOut();
        try {
            out.print(html);
        } catch (IOException e) {
            String str = "Exception in writing the " + TAG_NAME;
            log.error(str, e);
            throw new JspWriteRuntimeException(str, e);
        }
    }
}
Also used : IPropertyRuleIntrospector(org.jaffa.rules.IPropertyRuleIntrospector) JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) JspException(javax.servlet.jsp.JspException) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) MissingParametersRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException) SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)

Example 7 with SimpleWidgetModel

use of org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel in project jaffa-framework by jaffa-projects.

the class TaskMaintenanceForm method doValidate0.

/**
 * This method should be invoked to ensure a valid state of the FormBean. It will validate the data in the models and set the corresponding properties.
 * Errors will be raised in the FormBean, if any validation fails.
 * @param request The request stream
 * @return A true indicates validations went through successfully.
 */
public boolean doValidate0(HttpServletRequest request) {
    TaskMaintenanceDto taskMaintenanceDto = ((TaskMaintenanceComponent) getComponent()).getTaskMaintenanceDto();
    String value;
    value = getScheduledTaskIdWM().getStringValue();
    if (value != null && value.length() == 0)
        value = null;
    taskMaintenanceDto.setScheduledTaskId(value);
    value = getTaskTypeWM().getStringValue();
    if (value != null && value.length() == 0)
        value = null;
    taskMaintenanceDto.setTaskType(value);
    value = getDescriptionWM().getStringValue();
    if (value != null && value.length() == 0)
        value = null;
    taskMaintenanceDto.setDescription(value);
    value = getRunAsWM().getStringValue();
    if (value != null && value.length() == 0)
        value = null;
    taskMaintenanceDto.setRunAs(value);
    taskMaintenanceDto.setStartOn(getStartOnWM().getDateTimeValue());
    taskMaintenanceDto.setEndOn(getEndOnWM().getDateTimeValue());
    value = getMisfireRecoveryWM().getStringValue();
    if (value != null && value.length() == 0)
        value = null;
    taskMaintenanceDto.setMisfireRecovery(value != null ? ScheduledTask.MisfireRecovery.valueOf(value) : null);
    taskMaintenanceDto.setCreatedOn(getCreatedOnWM().getDateTimeValue());
    value = getCreatedByWM().getStringValue();
    if (value != null && value.length() == 0)
        value = null;
    taskMaintenanceDto.setCreatedBy(value);
    taskMaintenanceDto.setLastChangedOn(getLastChangedOnWM().getDateTimeValue());
    value = getLastChangedByWM().getStringValue();
    if (value != null && value.length() == 0)
        value = null;
    taskMaintenanceDto.setLastChangedBy(value);
    value = getRecurrenceWM().getStringValue();
    if (value != null && value.length() == 0)
        value = null;
    if (value == null) {
        taskMaintenanceDto.setRecurrence(null);
    } else if (RecurrenceEnum.OFTEN.toString().equals(value)) {
        value = getOftenHoursWM().getStringValue();
        if (value != null && value.length() == 0)
            value = null;
        Integer hours = value != null ? new Integer(value) : null;
        value = getOftenMinutesWM().getStringValue();
        if (value != null && value.length() == 0)
            value = null;
        Integer minutes = value != null ? new Integer(value) : null;
        value = getOftenSecondsWM().getStringValue();
        if (value != null && value.length() == 0)
            value = null;
        Integer seconds = value != null ? new Integer(value) : null;
        taskMaintenanceDto.setRecurrence(new Recurrence.Often(hours, minutes, seconds));
    } else if (RecurrenceEnum.DAILY.toString().equals(value)) {
        taskMaintenanceDto.setRecurrence(new Recurrence.Daily(getDailyWeekDaysOnlyWM().getBooleanValue()));
    } else if (RecurrenceEnum.WEEKLY.toString().equals(value)) {
        value = getWeeklyFrequencyWM().getStringValue();
        if (value != null && value.length() == 0)
            value = null;
        Recurrence.WeekFrequency frequency = value != null ? Recurrence.WeekFrequency.valueOf(value) : null;
        value = getWeeklyDayWM().getStringValue();
        if (value != null && value.length() == 0)
            value = null;
        Recurrence.WeekDay day = value != null ? Recurrence.WeekDay.valueOf(value) : null;
        taskMaintenanceDto.setRecurrence(new Recurrence.Weekly(frequency, day));
    } else if (RecurrenceEnum.MONTHLY.toString().equals(value)) {
        Integer day = null;
        Recurrence.WeekFrequency weekFrequency = null;
        Recurrence.WeekDay weekDay = null;
        value = getMonthlyTypeWM().getStringValue();
        if (value != null && value.length() == 0)
            value = null;
        if (value == null || value.equals(MonthlyType.DAY.toString())) {
            value = getMonthlyDayWM().getStringValue();
            if (value != null && value.length() == 0)
                value = null;
            day = value != null ? new Integer(value) : null;
        } else {
            value = getMonthlyWeekFrequencyWM().getStringValue();
            if (value != null && value.length() == 0)
                value = null;
            weekFrequency = value != null ? Recurrence.WeekFrequency.valueOf(value) : null;
            value = getMonthlyWeekDayWM().getStringValue();
            if (value != null && value.length() == 0)
                value = null;
            weekDay = value != null ? Recurrence.WeekDay.valueOf(value) : null;
        }
        // Build the list of selected months
        Collection<Recurrence.Month> months = new TreeSet<Recurrence.Month>();
        for (Iterator itr = getMonthlyMonthsWM().getRows().iterator(); itr.hasNext(); ) {
            GridModelRow row = (GridModelRow) itr.next();
            for (int i = 0; i < MONTHS_GRID_COLUMNS; i++) {
                Boolean selected = ((SimpleWidgetModel) row.get("selected" + i)).getBooleanValue();
                if (selected != null && selected) {
                    Recurrence.Month month = (Recurrence.Month) row.get("value" + i);
                    months.add(month);
                }
            }
        }
        taskMaintenanceDto.setRecurrence(new Recurrence.Monthly(day, weekFrequency, weekDay, months.toArray(new Recurrence.Month[months.size()])));
    } else if (RecurrenceEnum.YEARLY.toString().equals(value)) {
        value = getYearlyFrequencyWM().getStringValue();
        if (value != null && value.length() == 0)
            value = null;
        Integer frequency = value != null ? new Integer(value) : null;
        value = getYearlyOnWM().getStringValue();
        if (value != null && value.length() == 0)
            value = null;
        Recurrence.Month on = value != null ? Recurrence.Month.valueOf(value) : null;
        taskMaintenanceDto.setRecurrence(new Recurrence.Yearly(frequency, on));
    } else if (RecurrenceEnum.CUSTOM.toString().equals(value)) {
        value = getCustomPatternWM().getStringValue();
        if (value != null && value.length() == 0)
            value = null;
        taskMaintenanceDto.setRecurrence(new Recurrence.Custom(value));
    } else
        taskMaintenanceDto.setRecurrence(null);
    return true;
}
Also used : TaskMaintenanceDto(org.jaffa.modules.scheduler.components.taskmaintenance.dto.TaskMaintenanceDto) Recurrence(org.jaffa.modules.scheduler.services.Recurrence) SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) GridModelRow(org.jaffa.presentation.portlet.widgets.model.GridModelRow)

Example 8 with SimpleWidgetModel

use of org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel in project jaffa-framework by jaffa-projects.

the class TaskMaintenanceForm method getRecurrenceWM.

/**
 * Getter for property recurrence. This is invoked by the custom tag, when the jsp is rendered, to get the current value.
 * @return Value of property recurrence.
 */
public SimpleWidgetModel getRecurrenceWM() {
    SimpleWidgetModel w_recurrence = (SimpleWidgetModel) getWidgetCache().getModel("recurrence");
    if (w_recurrence == null) {
        w_recurrence = new SimpleWidgetModel(getRecurrence());
        getWidgetCache().addModel("recurrence", w_recurrence);
    }
    return w_recurrence;
}
Also used : SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)

Example 9 with SimpleWidgetModel

use of org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel in project jaffa-framework by jaffa-projects.

the class TaskMaintenanceForm method getRunAsWM.

/**
 * Getter for property runAs. This is invoked by the custom tag, when the jsp is rendered, to get the current value.
 * @return Value of property runAs.
 */
public SimpleWidgetModel getRunAsWM() {
    SimpleWidgetModel w_runAs = (SimpleWidgetModel) getWidgetCache().getModel("runAs");
    if (w_runAs == null) {
        w_runAs = new SimpleWidgetModel(getRunAs());
        getWidgetCache().addModel("runAs", w_runAs);
    }
    return w_runAs;
}
Also used : SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)

Example 10 with SimpleWidgetModel

use of org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel in project jaffa-framework by jaffa-projects.

the class TaskMaintenanceForm method getTaskTypeWM.

/**
 * Getter for property taskType. This is invoked by the custom tag, when the jsp is rendered, to get the current value.
 * @return Value of property taskType.
 */
public SimpleWidgetModel getTaskTypeWM() {
    SimpleWidgetModel w_taskType = (SimpleWidgetModel) getWidgetCache().getModel("taskType");
    if (w_taskType == null) {
        w_taskType = new SimpleWidgetModel(getTaskType());
        Collection<String> taskTypeCodes = ((TaskMaintenanceComponent) getComponent()).getTaskTypeCodes();
        if (taskTypeCodes != null) {
            for (String taskTypeCode : taskTypeCodes) w_taskType.addOption(taskTypeCode, taskTypeCode);
        }
        getWidgetCache().addModel("taskType", w_taskType);
    }
    return w_taskType;
}
Also used : SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)

Aggregations

SimpleWidgetModel (org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)40 GridModelRow (org.jaffa.presentation.portlet.widgets.model.GridModelRow)5 JspWriteRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException)5 IOException (java.io.IOException)4 JspException (javax.servlet.jsp.JspException)4 JspWriter (javax.servlet.jsp.JspWriter)4 MissingParametersRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException)4 OuterFormTagMissingRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException)4 IPropertyRuleIntrospector (org.jaffa.rules.IPropertyRuleIntrospector)4 Iterator (java.util.Iterator)2 IntegerFieldMetaData (org.jaffa.metadata.IntegerFieldMetaData)2 Recurrence (org.jaffa.modules.scheduler.services.Recurrence)2 FormBase (org.jaffa.presentation.portlet.FormBase)2 File (java.io.File)1 TreeSet (java.util.TreeSet)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 TaskMaintenanceDto (org.jaffa.modules.scheduler.components.taskmaintenance.dto.TaskMaintenanceDto)1 GridModel (org.jaffa.presentation.portlet.widgets.model.GridModel)1 WidgetModelAccessMethodNotFoundRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.WidgetModelAccessMethodNotFoundRuntimeException)1