Package javax.faces.component.html

Examples of javax.faces.component.html.HtmlInputText


        resetCallbacks(childCallback, facetCallback, immediateFacetCallback);
    }

    public void testSaveRestoreChildrenState() throws Exception {
        HtmlForm form = new HtmlForm();
        HtmlInputText input = new HtmlInputText();
        IterationStateHolderComponent stateHolder = new IterationStateHolderComponent();

        List<UIComponent> children = mockDataAdaptor.getChildren();
        children.add(form);
        form.getChildren().add(input);
        form.getFacets().put("facet", stateHolder);

        mockDataAdaptor.setRowKey(facesContext, Integer.valueOf(0));

        assertFalse(form.isSubmitted());
        assertNull(input.getSubmittedValue());
        assertNull(input.getLocalValue());
        assertTrue(input.isValid());
        assertFalse(input.isLocalValueSet());
        assertNull(stateHolder.getIterationState());

        form.setSubmitted(true);
        input.setSubmittedValue("user input");
        input.setValue("component value");
        input.setValid(false);
        input.setLocalValueSet(true);
        stateHolder.setIterationState("state");

        mockDataAdaptor.setRowKey(facesContext, Integer.valueOf(1));

        assertFalse(form.isSubmitted());
        assertNull(input.getSubmittedValue());
        assertNull(input.getLocalValue());
        assertTrue(input.isValid());
        assertFalse(input.isLocalValueSet());
        assertNull(stateHolder.getIterationState());

        input.setSubmittedValue("another input from user");
        input.setValue("123");
        assertTrue(input.isLocalValueSet());
        stateHolder.setIterationState("456");

        mockDataAdaptor.setRowKey(facesContext, Integer.valueOf(0));
        assertTrue(form.isSubmitted());
        assertEquals("user input", input.getSubmittedValue());
        assertEquals("component value", input.getLocalValue());
        assertFalse(input.isValid());
        assertTrue(input.isLocalValueSet());
        assertEquals("state", stateHolder.getIterationState());

        mockDataAdaptor.setRowKey(facesContext, Integer.valueOf(1));
        assertFalse(form.isSubmitted());
        assertEquals("another input from user", input.getSubmittedValue());
        assertEquals("123", input.getLocalValue());
        assertTrue(input.isValid());
        assertTrue(input.isLocalValueSet());
        assertEquals("456", stateHolder.getIterationState());

        mockDataAdaptor.setRowKey(facesContext, null);
        assertFalse(form.isSubmitted());
        assertNull(input.getSubmittedValue());
        assertNull(input.getLocalValue());
        assertTrue(input.isValid());
        assertFalse(input.isLocalValueSet());
        assertNull(stateHolder.getIterationState());
    }
View Full Code Here


    public void testSaveRestoreChildrenStateNestedDataAdaptors() throws Exception {
        MockDataAdaptor childAdaptor = new MockDataAdaptor();
        childAdaptor.setDataModel(createDataModel());

        HtmlInputText input = new HtmlInputText();

        mockDataAdaptor.getChildren().add(childAdaptor);
        childAdaptor.getChildren().add(input);

        Integer rowKey = Integer.valueOf(2);
        Integer childKey = Integer.valueOf(1);

        mockDataAdaptor.setRowKey(facesContext, rowKey);
        childAdaptor.setRowKey(facesContext, childKey);

        assertNull(input.getSubmittedValue());
        assertNull(input.getLocalValue());
        assertTrue(input.isValid());
        assertFalse(input.isLocalValueSet());

        input.setSubmittedValue("submittedValue");
        input.setValue("value");

        childAdaptor.setRowKey(facesContext, null);
        mockDataAdaptor.setRowKey(facesContext, Integer.valueOf(3));
        childAdaptor.setRowKey(facesContext, Integer.valueOf(0));

        assertNull(input.getSubmittedValue());
        assertNull(input.getLocalValue());
        assertFalse(input.isLocalValueSet());

        childAdaptor.setRowKey(facesContext, null);
        mockDataAdaptor.setRowKey(facesContext, rowKey);
        childAdaptor.setRowKey(facesContext, childKey);

        assertEquals("submittedValue", input.getSubmittedValue());
        assertEquals("value", input.getLocalValue());
        assertTrue(input.isValid());
        assertTrue(input.isLocalValueSet());
    }
View Full Code Here

        assertTrue(input.isValid());
        assertTrue(input.isLocalValueSet());
    }

    public void testEventsQueueing() throws Exception {
        HtmlInputText input = new HtmlInputText();

        final TestCallback testCallback = new TestCallback();
        input.addValueChangeListener(new ValueChangeListener() {
            public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
                testCallback.getAndIncrement();
                assertEquals(data.get(1), getVarValue());
            }
        });
View Full Code Here

        facesContext.getViewRoot().broadcastEvents(facesContext, PhaseId.PROCESS_VALIDATIONS);
        assertEquals(1, testCallback.get());
    }

    public void testInvokeOnComponent() throws Exception {
        final HtmlInputText facet = new HtmlInputText();
        final HtmlInputText child = new HtmlInputText();

        mockDataAdaptor.getFacets().put("facet", facet);
        mockDataAdaptor.getChildren().add(child);

        mockDataAdaptor.setId("_data");
        facet.setId("_facet");
        child.setId("_child");

        boolean invocationResult;
        final TestCallback callback = new TestCallback();
        invocationResult = mockDataAdaptor.invokeOnComponent(facesContext, "_data", new ContextCallback() {
            public void invokeContextCallback(FacesContext context, UIComponent target) {
View Full Code Here

            });
        assertFalse(invocationResult);
    }

    public void testVisitChildren() throws Exception {
        final HtmlInputText facet = new HtmlInputText();
        final HtmlInputText child = new HtmlInputText();

        mockDataAdaptor.getFacets().put("facet", facet);
        mockDataAdaptor.getChildren().add(child);

        mockDataAdaptor.setId("_data");
        facet.setId("_facet");
        child.setId("_child");

        VisitContext fullVisitContext = VisitContext.createVisitContext(facesContext);

        final char separatorChar = UINamingContainer.getSeparatorChar(facesContext);
        final Set<String> idsToVisit = new HashSet<String>();
        idsToVisit.add("_data" + separatorChar + "_facet");
        idsToVisit.add("_data" + separatorChar + "0" + separatorChar + "_child");
        idsToVisit.add("_data" + separatorChar + "2" + separatorChar + "_child");

        VisitContext partialVisitContext = VisitContext.createVisitContext(facesContext, idsToVisit,
            EnumSet.of(VisitHint.SKIP_UNRENDERED));

        final TestCallback callback = new TestCallback();
        mockDataAdaptor.visitTree(fullVisitContext, new VisitCallback() {
            public VisitResult visit(VisitContext context, UIComponent target) {
                callback.getAndIncrement();
                assertNotNull(target);

                return VisitResult.ACCEPT;
            }
        });

        assertEquals(1 /* adaptor itself */+ 1 /* facet */+ data.size(), callback.get());

        callback.reset();

        mockDataAdaptor.visitTree(partialVisitContext, new VisitCallback() {
            public VisitResult visit(VisitContext context, UIComponent target) {
                callback.getAndIncrement();
                assertNotNull(target);
                assertTrue(idsToVisit.contains(target.getClientId()));
                return VisitResult.ACCEPT;
            }
        });

        assertEquals(idsToVisit.size(), callback.get());

        callback.reset();

        mockDataAdaptor.visitTree(fullVisitContext, new VisitCallback() {
            public VisitResult visit(VisitContext context, UIComponent target) {
                callback.getAndIncrement();

                if (child.equals(target)
                    && child.getClientId().equals("_data" + separatorChar + "1" + separatorChar + "_child")) {
                    return VisitResult.COMPLETE;
                }

                return VisitResult.ACCEPT;
            }
View Full Code Here

    }
   
    @Override
    protected void createInputComponents(UIComponent parent, InputInfo ii, FacesContext context, List<UIComponent> compList)
    {
        HtmlInputText input;
        if (compList.size()==0)
        {   try {
                input = inputComponentClass.newInstance();
            } catch (InstantiationException e1) {
                throw new InternalException(e1);
            } catch (IllegalAccessException e2) {
                throw new InternalException(e2);
            }
            // once
            copyAttributes(parent, ii, input);
            // language
            input.setLang(ii.getLocale().getLanguage());
            // maxlength
            int maxLength = getMaxInputLength(ii.getColumn());
            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));
            }
        }
        else
        {   // check type
            UIComponent comp = compList.get(0);
            if (!(comp instanceof HtmlInputText))
                throw new UnexpectedReturnValueException(comp.getClass().getName(), "compList.get");
            // cast
            input = (HtmlInputText)comp;
        }

        // disabled
        Object dis = ii.getAttributeEx("disabled");
        if (dis!=null)
            input.setDisabled(ObjectUtils.getBoolean(dis));
        // field-readOnly
        if (ObjectUtils.getBoolean(dis)==false)
            input.setReadonly(ii.isFieldReadOnly());
        // style
        addRemoveDisabledStyle(input, (input.isDisabled() || input.isReadonly()));
        addRemoveInvalidStyle(input, ii.hasError());
       
        // set value
        setInputValue(input, ii);
    }
View Full Code Here

            init(); //lazy init

            if(uiComponent instanceof HtmlInputText)
            {
                HtmlInputText htmlInputText = (HtmlInputText)uiComponent;

                if (this.forceComponentInitialization)
                {
                    htmlInputText.setMaxlength((Integer) maxLength);
                }
                else
                {
                    Integer initialMaxLength = (Integer)
                        htmlInputText.getAttributes().get(INITIAL_MARKUP_META_DATA_KEY);

                    if (initialMaxLength == null)
                    {
                        initialMaxLength = htmlInputText.getMaxlength(); //value overriden by the component
                        htmlInputText.getAttributes().put(INITIAL_MARKUP_META_DATA_KEY, initialMaxLength);
                    }

                    // only override maxlength if not already set by xhtml definition
                    if (initialMaxLength <= 0)
                    {
                        htmlInputText.setMaxlength((Integer) maxLength);
                    }
                }
            }
            else if(uiComponent instanceof HtmlInputSecret)
            {
View Full Code Here


    @Override
    protected UIComponent createComponentToTest()
    {
        return new HtmlInputText();
    }
View Full Code Here

        return selectOne;
    }

    private static UIInput createInputForStringProperty() {
        HtmlInputText inputText = FacesComponentUtility.createComponent(HtmlInputText.class, null);

        //TODO: check if this has units, then apply the correct style
        inputText.setStyleClass(CssStyleClasses.PROPERTY_VALUE_INPUT);
        //      inputText.setStyle(INPUT_TEXT_WIDTH_STYLE_WITH_UNITS);
        inputText.setMaxlength(PropertySimple.MAX_VALUE_LENGTH);

        // Disable browser auto-completion.
        inputText.setAutocomplete("off");
        return inputText;
    }
View Full Code Here

        if (input instanceof HtmlInputText) {
            //         TODO: will this still work now that we use the style def'n "width:185px;" to define the input field width?
            // For text inputs with values that are too long to fit in the input text field, add a "title" attribute set to
            // the value, so the user can see the untruncated value via a tooltip.
            // (see http://jira.jboss.com/jira/browse/JBNADM-1608)
            HtmlInputText inputText = (HtmlInputText) input;
            if ((propertyValue != null) && (propertyValue.length() > INPUT_TEXT_COMPONENT_WIDTH))
                inputText.setTitle(propertyValue);
            inputText.setOnchange("setInputTitle(this)");
        }
    }
View Full Code Here

TOP

Related Classes of javax.faces.component.html.HtmlInputText

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.