Search in sources :

Example 1 with HtmlInputText

use of javax.faces.component.html.HtmlInputText in project gdmatrix by gdmatrix.

the class QueryInstanceBean method addParameterComponent.

private void addParameterComponent(Query.Parameter parameter, String expression, HtmlPanelGroup exprPanelGroup) {
    FacesContext context = FacesContext.getCurrentInstance();
    String sql = parameter.getSql();
    if (StringUtils.isBlank(sql)) {
        String format = parameter.getFormat();
        ValueBinding valueBinding;
        if (Query.Parameter.DATE.equals(format)) {
            HtmlCalendar calendar = new HtmlCalendar();
            calendar.setId("input_" + id);
            String expr = "#{queryInstanceBean." + expression + "['" + parameter.getName() + "']}";
            valueBinding = context.getApplication().createValueBinding(expr);
            calendar.setValueBinding("value", valueBinding);
            calendar.setStyleClass("input_value date");
            exprPanelGroup.getChildren().add(calendar);
        } else {
            HtmlInputText inputText = new HtmlInputText();
            inputText.setId("input_" + id);
            String expr = "#{queryInstanceBean." + expression + "['" + parameter.getName() + "']}";
            valueBinding = context.getApplication().createValueBinding(expr);
            inputText.setValueBinding("value", valueBinding);
            inputText.setStyleClass("input_value");
            String title = parameter.getDescription() == null ? parameter.getName() : parameter.getDescription();
            inputText.setTitle(title);
            inputText.setAlt(title);
            inputText.setSize(parameter.getSize());
            if (Query.Parameter.NUMBER.equals(format)) {
                Application application = context.getApplication();
                MethodBinding method = application.createMethodBinding("#{queryInstanceBean.validateNumber}", new Class[] { FacesContext.class, UIComponent.class, Object.class });
                inputText.setValidator(method);
            }
            exprPanelGroup.getChildren().add(inputText);
        }
        Object value = valueBinding.getValue(context);
        if (value == null) {
            String defaultValue = parameter.getDefaultValue();
            if (!StringUtils.isBlank(defaultValue)) {
                valueBinding.setValue(context, String.valueOf(defaultValue));
            }
        }
    } else // selectOneMenu
    {
        HtmlSelectOneMenu selectOneMenu = new HtmlSelectOneMenu();
        selectOneMenu.setId("input_" + id);
        String expr = "#{queryInstanceBean." + expression + "['" + parameter.getName() + "']}";
        ValueBinding valueBinding = context.getApplication().createValueBinding(expr);
        selectOneMenu.setValueBinding("value", valueBinding);
        selectOneMenu.setStyleClass("input_value select");
        id++;
        UISelectItems uiSelectItems = new UISelectItems();
        uiSelectItems.setId("items_" + id);
        expr = "#{queryInstanceBean.parameterSelectItemsMap['" + parameter.getName() + "']}";
        ValueBinding itemsValue = context.getApplication().createValueBinding(expr);
        uiSelectItems.setValueBinding("value", itemsValue);
        selectOneMenu.getChildren().add(uiSelectItems);
        exprPanelGroup.getChildren().add(selectOneMenu);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) UISelectItems(javax.faces.component.UISelectItems) ValueBinding(javax.faces.el.ValueBinding) HtmlInputText(javax.faces.component.html.HtmlInputText) MethodBinding(javax.faces.el.MethodBinding) HtmlSelectOneMenu(javax.faces.component.html.HtmlSelectOneMenu) HtmlCalendar(org.santfeliu.faces.component.jqueryui.HtmlCalendar) Application(javax.faces.application.Application)

Example 2 with HtmlInputText

use of javax.faces.component.html.HtmlInputText in project gdmatrix by gdmatrix.

the class WidgetTestBean method addInputText.

public String addInputText() {
    int size = panel.getChildCount();
    HtmlInputText input = new HtmlInputText();
    input.setId("input_id_" + size);
    input.setValue("child #" + size);
    panel.getChildren().add(input);
    return null;
}
Also used : HtmlInputText(javax.faces.component.html.HtmlInputText)

Example 3 with HtmlInputText

use of javax.faces.component.html.HtmlInputText in project myfaces-build-tools by apache.

the class PhoneNumberConverterTest method testNumOnly.

public void testNumOnly() throws Exception {
    Object obj = phoneNumConverter.getAsObject(facesContext, new HtmlInputText(), "6373824");
    assertNotNull(obj);
    PhoneNumber phoneNum = (PhoneNumber) obj;
    assertEquals(phoneNum.getNumber(), "6373824");
}
Also used : HtmlInputText(javax.faces.component.html.HtmlInputText)

Example 4 with HtmlInputText

use of javax.faces.component.html.HtmlInputText in project liferay-faces-alloy by liferay.

the class OutputRemainingChars method getMaxLength.

@Override
public Integer getMaxLength() {
    Integer maxLength = super.getMaxLength();
    // try to get the maxlength from the associated input component.
    if (maxLength == null) {
        String forComponent = getFor();
        if (forComponent == null) {
            logger.error("getMaxLength: Please specify a 'for' attribute for the outputRemainingChars component.");
        } else {
            UIComponent inputComponent = findComponent(forComponent);
            if (inputComponent != null) {
                if (inputComponent instanceof HtmlInputText) {
                    HtmlInputText htmlInputText = (HtmlInputText) inputComponent;
                    maxLength = htmlInputText.getMaxlength();
                } else if (inputComponent instanceof HtmlInputTextarea) {
                    HtmlInputTextarea htmlInputTextarea = (HtmlInputTextarea) inputComponent;
                    Object maxLengthObject = htmlInputTextarea.getAttributes().get("maxlength");
                    if (maxLengthObject != null) {
                        maxLength = Integer.parseInt(maxLengthObject.toString());
                    }
                }
            }
        }
    }
    return maxLength;
}
Also used : HtmlInputTextarea(javax.faces.component.html.HtmlInputTextarea) UIComponent(javax.faces.component.UIComponent) HtmlInputText(javax.faces.component.html.HtmlInputText)

Example 5 with HtmlInputText

use of javax.faces.component.html.HtmlInputText in project empire-db by apache.

the class TextInputControl method createInputComponents.

@Override
protected void createInputComponents(UIComponent parent, InputInfo ii, FacesContext context, List<UIComponent> compList) {
    // check params
    if (!compList.isEmpty())
        throw new InvalidArgumentException("compList", compList);
    // create
    HtmlInputText input = InputControlManager.createComponent(context, this.inputComponentClass);
    // once
    copyAttributes(parent, ii, input);
    // language
    input.setLang(ii.getLocale().getLanguage());
    // maxlength
    int maxLength = getMaxInputLength(ii);
    if (maxLength > 0) {
        input.setMaxlength(maxLength);
    }
    // add
    compList.add(input);
    // add unit
    String unit = getUnitString(ii);
    if (StringUtils.isNotEmpty(unit)) {
        // add the unit
        compList.add(createUnitLabel("eUnit", ii, unit));
    }
    // add hint
    String hint = StringUtils.toString(ii.getAttribute("hint"));
    if (StringUtils.isNotEmpty(hint) && !ii.isDisabled()) {
        // add the hint (if not an empty string!)
        compList.add(createUnitLabel("eInputHint", ii, hint));
    }
    // update
    updateInputState(compList, ii, context, context.getCurrentPhaseId());
}
Also used : InvalidArgumentException(org.apache.empire.exceptions.InvalidArgumentException) HtmlInputText(javax.faces.component.html.HtmlInputText)

Aggregations

HtmlInputText (javax.faces.component.html.HtmlInputText)10 UIComponent (javax.faces.component.UIComponent)2 ValidatorException (javax.faces.validator.ValidatorException)2 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 Application (javax.faces.application.Application)1 FacesMessage (javax.faces.application.FacesMessage)1 UIInput (javax.faces.component.UIInput)1 UISelectItems (javax.faces.component.UISelectItems)1 HtmlInputTextarea (javax.faces.component.html.HtmlInputTextarea)1 HtmlSelectOneMenu (javax.faces.component.html.HtmlSelectOneMenu)1 FacesContext (javax.faces.context.FacesContext)1 MethodBinding (javax.faces.el.MethodBinding)1 ValueBinding (javax.faces.el.ValueBinding)1 InvalidArgumentException (org.apache.empire.exceptions.InvalidArgumentException)1 UnexpectedReturnValueException (org.apache.empire.exceptions.UnexpectedReturnValueException)1 HtmlCalendar (org.santfeliu.faces.component.jqueryui.HtmlCalendar)1