Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wicket中的可增长文本区域_Wicket - Fatal编程技术网

wicket中的可增长文本区域

wicket中的可增长文本区域,wicket,Wicket,我希望创建一个垂直增长的文本区域,在那里我仍然可以看到文本的第一行 目前,我正在尝试使用以下方法: public class GrowableTextArea extends TextArea { /** * */ private static final long serialVersionUID = 1L; int initialRowSize = 1; int fixedColSize = 40; int current

我希望创建一个垂直增长的文本区域,在那里我仍然可以看到文本的第一行

目前,我正在尝试使用以下方法:

public class GrowableTextArea extends TextArea {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    int initialRowSize = 1;

    int fixedColSize = 40;

    int currentRowSize = initialRowSize;

    float temp = 1.0f;

    String inputValue;

    public GrowableTextArea(String id) {

        super(id);

        setModel(new PropertyModel(this, inputValue));

        setOutputMarkupId(true);

        add(new GrowableBehavior("onkeyup"));

    }

    /***
     * Set the rows here. So that every time component is rendered,
     * 
     * rows value is updated.
     **/

    @Override
    public void onComponentTag(ComponentTag tag) {

        super.onComponentTag(tag);

        tag.put("rows", currentRowSize);

        tag.put("cols", fixedColSize);

    }

    /*** Getters and setters ***/

    public int getCurrentRowSize() {

        return currentRowSize;

    }

    public void setCurrentRowSize(int currentRowSize) {

        this.currentRowSize = currentRowSize;

    }

    public String getInputValue() {

        return inputValue;

    }

    public void setInputValue(String inputValue) {

        this.inputValue = inputValue;

    }


    private class GrowableBehavior extends AjaxFormComponentUpdatingBehavior

    {

        /***
         * Tell it to fire the onkeyup event every 1/2 sec.
         **/

        public GrowableBehavior(String event) {

            super(event);

            setThrottleDelay(Duration.milliseconds(500));

        }

        /***
         * First the model is updated and then
         * 
         * length is checked to see the
         * 
         * whether rowcount should be incremented
         **/

        @Override
        protected void onUpdate(AjaxRequestTarget target) {

            Component comp = getComponent();

            TextArea textarea = (TextArea) comp;

            String value = (String) textarea.getConvertedInput();

            if (value != null) {

                int currentLength = value.length();

                float f = (float) currentLength / fixedColSize;

                if (f > temp) {
                    currentRowSize++;

                    temp = temp + 1;

                    target.add(comp);
                }

            }

        }
    }

    public void setThrottleDelay(Duration milliseconds) {
        // TODO Auto-generated method stub

    }

}

我的输出只是一个普通的文本区域,类似于堆栈溢出文本区域。这里出了什么问题?

您可以像这样使用jQuery插件:

IMHO最好使用普通javascript(不需要额外的服务器调用来调整文本区域的大小)。您是否尝试在“onUpdate”的某个位置设置断点,只是为了检查带有“onkeyup”事件的GrowtableBehavior是否正常工作?编辑:可能“getConvertedInput”为空;尝试使用“getRawInput”…感谢您提供的提示,但我将使用下面的自动大小示例