Growable text area in wicket

时光怂恿深爱的人放手 提交于 2019-12-13 05:10:12

问题


I'm looking to create a text area that grows vertically where I can still see the first line of the text.

Currently I'm trying to use this:

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

    }

}

My output is a just a normal text area that similar to the stack overflow text area. What is wrong here?


回答1:


You can use a jQuery plugin fir this like this: http://www.jacklmoore.com/autosize/



来源:https://stackoverflow.com/questions/19424251/growable-text-area-in-wicket

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!