Search in sources :

Example 1 with UIComponent

use of jakarta.faces.component.UIComponent in project guide-jpa-intro by OpenLiberty.

the class EventBean method getUnitOfTimeOptions.

/**
 * Gets 'selectOptions' for a specific unit of time from user interface
 */
private UIInput getUnitOfTimeOptions(ComponentSystemEvent event, String unit) {
    UIComponent components = event.getComponent();
    UIInput unitOptions = (UIInput) components.findComponent("eventform:" + unit);
    return unitOptions;
}
Also used : UIComponent(jakarta.faces.component.UIComponent) UIInput(jakarta.faces.component.UIInput)

Example 2 with UIComponent

use of jakarta.faces.component.UIComponent in project rubia-forums by flashboss.

the class BackButton method getCancelButton.

private UIComponent getCancelButton(UIViewRoot uiViewRoot) {
    List<UIComponent> result = new ArrayList<UIComponent>();
    findComponents("cancel", uiViewRoot.getChildren(), result);
    UIComponent cancelButton = result.isEmpty() ? null : result.get(0);
    return cancelButton;
}
Also used : UIComponent(jakarta.faces.component.UIComponent) ArrayList(java.util.ArrayList)

Example 3 with UIComponent

use of jakarta.faces.component.UIComponent in project rubia-forums by flashboss.

the class JSFUtil method getComponentValue.

/**
 * @author sshah
 *
 * @param componentId the id component to check
 *
 * @return the value of the choosen component
 */
public static String getComponentValue(String componentId) {
    String value = null;
    UIViewRoot root = getCurrentInstance().getViewRoot();
    UIComponent component = root.findComponent(componentId);
    if (component != null) {
        Object o = component.getValueExpression("value").getValue(getCurrentInstance().getELContext());
        value = (String) o;
    }
    return value;
}
Also used : UIComponent(jakarta.faces.component.UIComponent) UIViewRoot(jakarta.faces.component.UIViewRoot)

Example 4 with UIComponent

use of jakarta.faces.component.UIComponent in project rubia-forums by flashboss.

the class JSFUtil method removeComponent.

/**
 * @author sshah
 *
 * @param componentId the id component to check
 */
public static void removeComponent(String componentId) {
    UIViewRoot root = getCurrentInstance().getViewRoot();
    UIComponent component = root.findComponent(componentId);
    if (component != null) {
        UIComponent parent = component.getParent();
        parent.getChildren().remove(component);
    }
}
Also used : UIComponent(jakarta.faces.component.UIComponent) UIViewRoot(jakarta.faces.component.UIViewRoot)

Example 5 with UIComponent

use of jakarta.faces.component.UIComponent in project rubia-forums by flashboss.

the class PollValidator method validate.

public void validate(FacesContext context, UIComponent component, String value) throws ValidatorException {
    // A check whether it is post submition action. If not validators are
    // not executed.
    FacesContext fc = FacesContext.getCurrentInstance();
    Map<String, String> reqParams = fc.getExternalContext().getRequestParameterMap();
    if (!reqParams.keySet().contains("post:Submit")) {
        return;
    }
    // Collecting all poll data from the form.
    UIComponent formComp = component.getParent();
    UIComponent questionComp = formComp.findComponent("question");
    UIComponent pollDurationComp = formComp.findComponent("pollDuration");
    List<UIComponent> options = new ArrayList<UIComponent>();
    for (int i = 1; ; i++) {
        UIComponent temp = formComp.findComponent("option_" + i);
        if (temp != null) {
            options.add(temp);
        } else {
            break;
        }
    }
    // validate.
    if (!((questionComp.getAttributes().get("value") != null && questionComp.getAttributes().get("value").toString().trim().length() != 0) || (options.size() > 0))) {
        return;
    }
    // Checks
    if (options.size() > 10) {
        throwValidationException(TOO_MANY_OPTIONS_MSG);
    }
    if (options.size() < 2) {
        throwValidationException(TOO_FEW_OPTIONS_MSG);
    }
    if (questionComp.getAttributes().get("value") == null || questionComp.getAttributes().get("value").toString().trim().length() == 0) {
        throwValidationException(EMPTY_POLL_QUESTION_MSG);
    }
    for (UIComponent option : options) {
        if (option.getAttributes().get("value") == null || option.getAttributes().get("value").toString().trim().length() == 0) {
            throwValidationException(EMPTY_POLL_OPTION_MSG);
        }
    }
    int duration = 0;
    if (pollDurationComp.getAttributes().get("value") != null && pollDurationComp.getAttributes().get("value").toString().trim().length() != 0) {
        try {
            duration = parseInt(pollDurationComp.getAttributes().get("value").toString());
        } catch (NumberFormatException e) {
            throwValidationException(POLL_DURATION_MSG);
        }
        if (duration < 0) {
            throwValidationException(POLL_DURATION_MSG);
        }
    }
}
Also used : FacesContext(jakarta.faces.context.FacesContext) UIComponent(jakarta.faces.component.UIComponent) ArrayList(java.util.ArrayList)

Aggregations

UIComponent (jakarta.faces.component.UIComponent)802 UIViewRoot (jakarta.faces.component.UIViewRoot)219 Test (org.junit.Test)213 PrintWriter (java.io.PrintWriter)149 FacesContext (jakarta.faces.context.FacesContext)137 IOException (java.io.IOException)79 UINamingContainer (jakarta.faces.component.UINamingContainer)76 UIOutput (jakarta.faces.component.UIOutput)75 UICommand (jakarta.faces.component.UICommand)74 FacesException (jakarta.faces.FacesException)63 ServletException (jakarta.servlet.ServletException)58 UIInput (jakarta.faces.component.UIInput)49 ArrayList (java.util.ArrayList)49 StringWriter (java.io.StringWriter)47 MockResponseWriter (org.apache.myfaces.test.mock.MockResponseWriter)39 ValueExpression (jakarta.el.ValueExpression)35 HashMap (java.util.HashMap)34 ResponseWriter (jakarta.faces.context.ResponseWriter)31 Map (java.util.Map)31 HelloWorld (org.apache.myfaces.view.facelets.bean.HelloWorld)31