第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

構(gòu)造 vaadin 14 文本字段,僅接受數(shù)字,不接受其他內(nèi)容

構(gòu)造 vaadin 14 文本字段,僅接受數(shù)字,不接受其他內(nèi)容

DIEA 2024-01-25 21:37:35
我需要制作只能接受數(shù)字的 vaadin 14 文本字段。文本字段的標(biāo)準(zhǔn)如下1.文本字段只能接受數(shù)字,不能接受其他任何內(nèi)容,因?yàn)槲蚁雽⒃撐谋咀侄斡米魇謾C(jī)號(hào)碼字段。2.以這樣的方式進(jìn)行驗(yàn)證:如果用戶嘗試輸入字母,則文本字段中不得反映任何內(nèi)容。文本字段中只能輸入數(shù)字。3.任何警告或錯(cuò)誤不得顯示在用戶界面中,因?yàn)槲覀儗iT為手機(jī)號(hào)碼制作了文本字段。我嘗試過的事情是活頁(yè)夾,但允許在焦點(diǎn)丟失事件之后輸入字母,它們會(huì)驗(yàn)證并提供錯(cuò)誤消息我不希望出現(xiàn)這種行為。還嘗試了 vaadin 數(shù)字字段,但允許字符“e”只是簡(jiǎn)單而直接,我正在尋找僅輸入數(shù)字的文本字段。如果用戶嘗試輸入字母,則文本字段中不得反映任何內(nèi)容。
查看完整描述

3 回答

?
子衿沉夜

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊

服務(wù)器端

您可以執(zhí)行多種選項(xiàng),

binder.forField(textFieldForNumber)
??????.withValidator(new?RegexpValidator("Only?1-9?allowed","\\d*"))
??????.bind(YourEntity::getNo,?YourEntity::setNo);

客戶端

還可以使用textField.setPattern(..)方法在客戶端執(zhí)行相同的檢查和輸入過濾,例如:

textFieldForNumber.setPattern("\\d*");

此外,可以通過以下方式防止輸入與模式完全不匹配

textFieldForNumber.setPreventInvalidInput(true);

備用小部件:NumberField

第三種選擇是使用NumberField組件。


查看完整回答
反對(duì) 回復(fù) 2024-01-25
?
臨摹微笑

TA貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個(gè)贊

我找到了答案的解決方案我在 Vaadin 新測(cè)試版中提取了整數(shù)文本字段的源代碼


代碼如下


@Tag("vaadin-integer-field")

@HtmlImport("frontend://bower_components/vaadin-text-field/src/vaadin-integer-field.html")

@JsModule("@vaadin/vaadin-text-field/src/vaadin-integer-field.js")

public class BigIntegerField extends AbstractNumberField<BigIntegerField, BigInteger> {


    private static final SerializableFunction<String, BigInteger> PARSER = valueFormClient -> {

        if (valueFormClient == null || valueFormClient.isEmpty()) {

            return null;

        }

        try {

            return new BigInteger(valueFormClient);

        } catch (NumberFormatException e) {

            return null;

        }

    };


    private static final SerializableFunction<BigInteger, String> FORMATTER = valueFromModel -> valueFromModel == null

            ? ""

            : valueFromModel.toString();


    /**

     * Constructs an empty {@code IntegerField}.

     */

    public BigIntegerField() {


          super(PARSER, FORMATTER, Double.MIN_VALUE, Double.MAX_VALUE);

  //      super(PARSER, FORMATTER, new BigInteger(String.valueOf(Integer.MIN_VALUE)), new BigInteger(String.valueOf(Integer.MAX_VALUE)));

    }


    /**

     * Constructs an empty {@code IntegerField} with the given label.

     *

     * @param label

     *            the text to set as the label

     */

    public BigIntegerField(String label) {

        this();

        setLabel(label);

    }


    /**

     * Constructs an empty {@code IntegerField} with the given label and

     * placeholder text.

     *

     * @param label

     *            the text to set as the label

     * @param placeholder

     *            the placeholder text to set

     */

    public BigIntegerField(String label, String placeholder) {

        this(label);

        setPlaceholder(placeholder);

    }


    /**

     * Constructs an empty {@code IntegerField} with a value change listener.

     *

     * @param listener

     *            the value change listener

     *

     * @see #addValueChangeListener(ValueChangeListener)

     */

    public BigIntegerField(

            ValueChangeListener<? super ComponentValueChangeEvent<BigIntegerField, BigInteger>> listener) {

        this();

        addValueChangeListener(listener);

    }


    /**

     * Constructs an empty {@code IntegerField} with a value change listener and

     * a label.

     *

     * @param label

     *            the text to set as the label

     * @param listener

     *            the value change listener

     *

     * @see #setLabel(String)

     * @see #addValueChangeListener(ValueChangeListener)

     */

    public BigIntegerField(String label,

            ValueChangeListener<? super ComponentValueChangeEvent<BigIntegerField, BigInteger>> listener) {

        this(label);

        addValueChangeListener(listener);

    }


    /**

     * Constructs a {@code IntegerField} with a value change listener, a label

     * and an initial value.

     *

     * @param label

     *            the text to set as the label

     * @param initialValue

     *            the initial value

     * @param listener

     *            the value change listener

     *

     * @see #setLabel(String)

     * @see #setValue(Object)

     * @see #addValueChangeListener(ValueChangeListener)

     */

    public BigIntegerField(String label, BigInteger initialValue,

            ValueChangeListener<? super ComponentValueChangeEvent<BigIntegerField, BigInteger>> listener) {

        this(label);

        setValue(initialValue);

        addValueChangeListener(listener);

    }


    /**

     * Sets the minimum value of the field. Entering a value which is smaller

     * than {@code min} invalidates the field.

     * 

     * @param min

     *            the min value to set

     */

    public void setMin(int min) {

        super.setMin(min);

    }


    /**

     * Gets the minimum allowed value of the field.

     *

     * @return the min property of the field

     * @see #setMin(int)

     */

    public int getMin() {

        return (int) getMinDouble();

    }


    /**

     * Sets the maximum value of the field. Entering a value which is greater

     * than {@code max} invalidates the field.

     *

     * @param max

     *            the max value to set

     */

    public void setMax(int max) {

        super.setMax(max);

    }


    /**

     * Gets the maximum allowed value of the field.

     *

     * @return the max property of the field

     * @see #setMax(int)

     */

    public int getMax() {

        return (int) getMaxDouble();

    }


    /**

     * Sets the allowed number intervals of the field. This specifies how much

     * the value will be increased/decreased when clicking on the

     * {@link #setHasControls(boolean) control buttons}. It is also used to

     * invalidate the field, if the value doesn't align with the specified step

     * and {@link #setMin(int) min} (if specified by user).

     * 

     * @param step

     *            the new step to set

     * @throws IllegalArgumentException

     *             if the argument is less or equal to zero.

     */

    public void setStep(int step) {

        if (step <= 0) {

            throw new IllegalArgumentException("The step cannot be less or equal to zero.");

        }

        super.setStep(step);

    }


    /**

     * Gets the allowed number intervals of the field.

     *

     * @return the step property of the field

     * @see #setStep(int)

     */

    public int getStep() {

        return (int) getStepDouble();

    }


}

這實(shí)際上解決了我有關(guān)手機(jī)號(hào)碼輸入的問題。


查看完整回答
反對(duì) 回復(fù) 2024-01-25
?
慕妹3242003

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊

您可以使用活頁(yè)夾在現(xiàn)場(chǎng)進(jìn)行驗(yàn)證,例如

binder.forField(textFieldForNumber)
      .withValidator(new RegexpValidator("Only 1-9 allowed","\\d*"))
      .bind(YourEntity::getNo, YourEntity::setNo);


查看完整回答
反對(duì) 回復(fù) 2024-01-25
  • 3 回答
  • 0 關(guān)注
  • 217 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)