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;
}
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;
}
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;
}
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);
}
}
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);
}
}
}
Aggregations