Search in sources :

Example 1 with FormComponentTraverser

use of org.olat.core.util.component.FormComponentTraverser in project OpenOLAT by OpenOLAT.

the class Form method submit.

private final void submit(UserRequest ureq, Event validationOkEvent) {
    ValidatingFormComponentVisitor vfcv = new ValidatingFormComponentVisitor();
    FormComponentTraverser ct = new FormComponentTraverser(vfcv, formLayout, false);
    ct.visitAll(ureq);
    // validate all form elements and gather validation status
    ValidationStatus[] status = vfcv.getStatus();
    // 
    boolean isValid = status == null || status.length == 0;
    for (Iterator<FormBasicController> iterator = formListeners.iterator(); iterator.hasNext(); ) {
        FormBasicController fbc = iterator.next();
        // let all listeners validate and calc the total isValid
        // let further validate even if one fails.
        isValid = fbc.validateFormLogic(ureq) && isValid;
    }
    formWrapperComponent.fireValidation(ureq, isValid, validationOkEvent);
    isValidAndSubmitted = isValid;
    hasAlreadyFired = true;
}
Also used : ValidationStatus(org.olat.core.util.ValidationStatus) FormComponentTraverser(org.olat.core.util.component.FormComponentTraverser)

Example 2 with FormComponentTraverser

use of org.olat.core.util.component.FormComponentTraverser in project OpenOLAT by OpenOLAT.

the class Form method reset.

/**
 * @param ureq
 */
public void reset(UserRequest ureq) {
    ResettingFormComponentVisitor rfcv = new ResettingFormComponentVisitor();
    FormComponentTraverser ct = new FormComponentTraverser(rfcv, formLayout, false);
    // calls reset on all elements!
    ct.visitAll(ureq);
    // 
    evalAllFormDependencyRules(ureq);
    // 
    formWrapperComponent.fireFormEvent(ureq, FormEvent.RESET);
    hasAlreadyFired = true;
}
Also used : FormComponentTraverser(org.olat.core.util.component.FormComponentTraverser)

Example 3 with FormComponentTraverser

use of org.olat.core.util.component.FormComponentTraverser in project OpenOLAT by OpenOLAT.

the class Form method evalAllFormDependencyRules.

/**
 * @param ureq
 */
void evalAllFormDependencyRules(UserRequest ureq) {
    FormDependencyRulesInitComponentVisitor fdrocv = new FormDependencyRulesInitComponentVisitor();
    FormComponentTraverser ct = new FormComponentTraverser(fdrocv, formLayout, false);
    // visit all container and eval container with its elements!
    ct.visitAll(ureq);
}
Also used : FormComponentTraverser(org.olat.core.util.component.FormComponentTraverser)

Example 4 with FormComponentTraverser

use of org.olat.core.util.component.FormComponentTraverser in project OpenOLAT by OpenOLAT.

the class Form method evalFormRequest.

/**
 * @param ureq
 */
public void evalFormRequest(UserRequest ureq) {
    // Initialize temporary request parameters
    if (isMultipartEnabled() && isMultipartContent(ureq.getHttpReq())) {
        doInitRequestMultipartDataParameter(ureq);
    } else {
        doInitRequestParameter(ureq);
    }
    String dispatchUri = getRequestParameter("dispatchuri");
    String dispatchAction = getRequestParameter("dispatchevent");
    boolean invalidDispatchUri = dispatchUri == null || dispatchUri.equals(FORM_UNDEFINED);
    boolean invalidDispatchAct = dispatchAction == null || dispatchAction.equals(FORM_UNDEFINED);
    // see also OLAT-3141
    boolean implicitFormSubmit = false;
    if (invalidDispatchAct && invalidDispatchUri) {
        // case if:
        // enter was pressed in Safari / IE
        // crawler tries form links
        SubmitFormComponentVisitor efcv = new SubmitFormComponentVisitor();
        new FormComponentTraverser(efcv, formLayout, false).visitAll(ureq);
        Submit submitFormItem = efcv.getSubmit();
        if (submitFormItem != null) {
            // if we have submit form item
            // assume a click on this item
            dispatchUri = FormBaseComponentIdProvider.DISPPREFIX + submitFormItem.getComponent().getDispatchID();
            action = FormEvent.ONCLICK;
        } else {
            // instead of
            // throw new AssertException("You have an input field but no submit item defined! this is no good if enter is pressed.");
            // assume a desired implicit form submit
            // see also OLAT-3141
            implicitFormSubmit = true;
        }
    } else {
        try {
            action = Integer.valueOf(dispatchAction);
        } catch (Exception e) {
            throw new InvalidRequestParameterException();
        }
    }
    hasAlreadyFired = false;
    isValidAndSubmitted = false;
    // 
    // step 1: call evalFormRequest(ureq) on each FormComponent this gives
    // ....... for each element the possibility to intermediate save a value.
    // ....... As a sideeffect the formcomponent to be dispatched is found.
    EvaluatingFormComponentVisitor efcv = new EvaluatingFormComponentVisitor(dispatchUri);
    FormComponentTraverser ct = new FormComponentTraverser(efcv, formLayout, false);
    ct.visitAll(ureq);
    // step 2: dispatch to the form component
    // ......... only one component to be dispatched can be found, e.g. clicked
    // ......... element....................................................
    // ......... dispatch changes server model -> rerendered
    // ......... dispatch may also request a form validation by
    // ......... calling the submit
    FormItem dispatchFormItem = efcv.getDispatchToComponent();
    // .......... the code goes further with step 3.........................
    if (implicitFormSubmit) {
        // implicit Submit (Press Enter without on a Field without submit item.)
        // see also OLAT-3141
        submit(ureq);
    } else {
        if (dispatchFormItem == null) {
            // source not found. This "never happens". Try to produce some hints.
            String fbc = new String();
            for (FormBasicController i : formListeners) {
                if (fbc.length() > 0) {
                    fbc += ",";
                }
                fbc += (i.getClass().getName());
            }
            log.warn("OLAT-5061: Could not determine request source in FlexiForm >" + formName + "<. Check >" + fbc + "<", null);
            // TODO: what now?
            // Assuming the same as "implicitFormSubmit" for now.
            submit(ureq);
        } else {
            // ****************************************
            // explicit Submit or valid form dispatch *
            // ****************************************
            dispatchFormItem.doDispatchFormRequest(ureq);
            // step 3: find parent container of dispatched component
            // .......... check dependency rules
            // .......... apply dependency rules
            FindParentFormComponentVisitor fpfcv = new FindParentFormComponentVisitor(dispatchFormItem);
            ct = new FormComponentTraverser(fpfcv, formLayout, false);
            ct.visitAll(ureq);
            fpfcv.getParent().evalDependencyRuleSetFor(ureq, dispatchFormItem);
        }
    }
    // 
    action = -1;
    // End of request dispatch: cleanup temp files: ureq requestParams and multipart files
    doClearRequestParameterAndMultipartData();
}
Also used : FormComponentTraverser(org.olat.core.util.component.FormComponentTraverser) FormItem(org.olat.core.gui.components.form.flexible.FormItem) Submit(org.olat.core.gui.components.form.flexible.elements.Submit) AssertException(org.olat.core.logging.AssertException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 5 with FormComponentTraverser

use of org.olat.core.util.component.FormComponentTraverser in project openolat by klemens.

the class Form method evalFormRequest.

/**
 * @param ureq
 */
public void evalFormRequest(UserRequest ureq) {
    // Initialize temporary request parameters
    if (isMultipartEnabled() && isMultipartContent(ureq.getHttpReq())) {
        doInitRequestMultipartDataParameter(ureq);
    } else {
        doInitRequestParameter(ureq);
    }
    String dispatchUri = getRequestParameter("dispatchuri");
    String dispatchAction = getRequestParameter("dispatchevent");
    boolean invalidDispatchUri = dispatchUri == null || dispatchUri.equals(FORM_UNDEFINED);
    boolean invalidDispatchAct = dispatchAction == null || dispatchAction.equals(FORM_UNDEFINED);
    // see also OLAT-3141
    boolean implicitFormSubmit = false;
    if (invalidDispatchAct && invalidDispatchUri) {
        // case if:
        // enter was pressed in Safari / IE
        // crawler tries form links
        SubmitFormComponentVisitor efcv = new SubmitFormComponentVisitor();
        new FormComponentTraverser(efcv, formLayout, false).visitAll(ureq);
        Submit submitFormItem = efcv.getSubmit();
        if (submitFormItem != null) {
            // if we have submit form item
            // assume a click on this item
            dispatchUri = FormBaseComponentIdProvider.DISPPREFIX + submitFormItem.getComponent().getDispatchID();
            action = FormEvent.ONCLICK;
        } else {
            // instead of
            // throw new AssertException("You have an input field but no submit item defined! this is no good if enter is pressed.");
            // assume a desired implicit form submit
            // see also OLAT-3141
            implicitFormSubmit = true;
        }
    } else {
        try {
            action = Integer.valueOf(dispatchAction);
        } catch (Exception e) {
            throw new InvalidRequestParameterException();
        }
    }
    hasAlreadyFired = false;
    isValidAndSubmitted = false;
    // 
    // step 1: call evalFormRequest(ureq) on each FormComponent this gives
    // ....... for each element the possibility to intermediate save a value.
    // ....... As a sideeffect the formcomponent to be dispatched is found.
    EvaluatingFormComponentVisitor efcv = new EvaluatingFormComponentVisitor(dispatchUri);
    FormComponentTraverser ct = new FormComponentTraverser(efcv, formLayout, false);
    ct.visitAll(ureq);
    // step 2: dispatch to the form component
    // ......... only one component to be dispatched can be found, e.g. clicked
    // ......... element....................................................
    // ......... dispatch changes server model -> rerendered
    // ......... dispatch may also request a form validation by
    // ......... calling the submit
    FormItem dispatchFormItem = efcv.getDispatchToComponent();
    // .......... the code goes further with step 3.........................
    if (implicitFormSubmit) {
        // implicit Submit (Press Enter without on a Field without submit item.)
        // see also OLAT-3141
        submit(ureq);
    } else {
        if (dispatchFormItem == null) {
            // source not found. This "never happens". Try to produce some hints.
            String fbc = new String();
            for (FormBasicController i : formListeners) {
                if (fbc.length() > 0) {
                    fbc += ",";
                }
                fbc += (i.getClass().getName());
            }
            log.warn("OLAT-5061: Could not determine request source in FlexiForm >" + formName + "<. Check >" + fbc + "<", null);
            // TODO: what now?
            // Assuming the same as "implicitFormSubmit" for now.
            submit(ureq);
        } else {
            // ****************************************
            // explicit Submit or valid form dispatch *
            // ****************************************
            dispatchFormItem.doDispatchFormRequest(ureq);
            // step 3: find parent container of dispatched component
            // .......... check dependency rules
            // .......... apply dependency rules
            FindParentFormComponentVisitor fpfcv = new FindParentFormComponentVisitor(dispatchFormItem);
            ct = new FormComponentTraverser(fpfcv, formLayout, false);
            ct.visitAll(ureq);
            fpfcv.getParent().evalDependencyRuleSetFor(ureq, dispatchFormItem);
        }
    }
    // 
    action = -1;
    // End of request dispatch: cleanup temp files: ureq requestParams and multipart files
    doClearRequestParameterAndMultipartData();
}
Also used : FormComponentTraverser(org.olat.core.util.component.FormComponentTraverser) FormItem(org.olat.core.gui.components.form.flexible.FormItem) Submit(org.olat.core.gui.components.form.flexible.elements.Submit) AssertException(org.olat.core.logging.AssertException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

FormComponentTraverser (org.olat.core.util.component.FormComponentTraverser)8 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 Submit (org.olat.core.gui.components.form.flexible.elements.Submit)2 AssertException (org.olat.core.logging.AssertException)2 ValidationStatus (org.olat.core.util.ValidationStatus)2