<commit_before>/*
 * $Id$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wicket.markup.html.form;


import java.io.Serializable;

import java.util.Collection;

import wicket.RequestCycle;
import wicket.markup.ComponentTag;

/**
 * Essentially a drop down choice that doesn't drop down. Instead, it scrolls and displays
 * a given number of rows.
 * @author <NAME>
 */
public final class ListChoice extends DropDownChoice implements FormComponent.ICookieValue
{
    /** Serial Version ID */
	private static final long serialVersionUID = 1227773600645861006L;

	// The default maximum row value
    private static int defaultMaxRows = 8;

    // The maximum number of rows to show
    private int maxRows;

    /**
     * Constructor
     * @param componentName The component name
     * @param model The model
     * @param values The values to select from
     */
    public ListChoice(final String componentName, final Serializable model, final Collection values)
    {
        this(componentName, model, values, defaultMaxRows);
    }

    /**
     * Constructor
     * @param componentName The component name
     * @param model The model
     * @param values The values to select from
     * @param maxRows The maximum number of rows to display
     */
    public ListChoice(final String componentName, final Serializable model,
            final Collection values, final int maxRows)
    {
        super(componentName, model, values);
        this.maxRows = maxRows;
        setRenderNullOption(false);
    }

    /**
     * @see wicket.Component#handleComponentTag(RequestCycle, ComponentTag)
     */
    protected void handleComponentTag(final RequestCycle cycle, final ComponentTag tag)
    {
        super.handleComponentTag(cycle, tag);
        tag.put("size", Math.min(maxRows, getValues().size()));
    }
    
    /**
     * @return Returns the defaultMaxRows.
     */
    public static int getDefaultMaxRows()
    {
        return defaultMaxRows;
    }

    /**
     * @param defaultMaxRows The defaultMaxRows to set.
     */
    public static void setDefaultMaxRows(final int defaultMaxRows)
    {
        ListChoice.defaultMaxRows = defaultMaxRows;
    }
}

///////////////////////////////// End of File /////////////////////////////////<commit_msg>fix for issue 1090226 (ListChoice Does not Support 'expression' binding?)<commit_after>/*
 * $Id$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wicket.markup.html.form;


import java.io.Serializable;

import java.util.Collection;

import wicket.IModel;
import wicket.RequestCycle;
import wicket.markup.ComponentTag;

/**
 * Essentially a drop down choice that doesn't drop down. Instead, it scrolls and displays
 * a given number of rows.
 *
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public final class ListChoice extends DropDownChoice implements FormComponent.ICookieValue
{
    /** Serial Version ID */
	private static final long serialVersionUID = 1227773600645861006L;

	/** The default maximum number of rows to display. */
    private static int defaultMaxRows = 8;

    /** The maximum number of rows to display. */
    private int maxRows;

    /**
     * Constructor that uses the provided {@link IModel}as its model. All components have
     * names. A component's name cannot be null.
     * @param name The non-null name of this component
     * @param model the model
     * @param values the list values
     * @throws wicket.RenderException Thrown if the component has been given a null name.
     */
    public ListChoice(String name, IModel model, final Collection values)
    {
        this(name, model, values, defaultMaxRows);
    }

    /**
     * Constructor that uses the provided instance of {@link IModel}as a dynamic model.
     * This model will be wrapped in an instance of {@link wicket.PropertyModel}using the
     * provided expression. Thus, using this constructor is a short-hand for:
     * 
     * <pre>
     * new MyComponent(name, new PropertyModel(myIModel, expression));
     * </pre>
     * 
     * All components have names. A component's name cannot be null.
     * @param name The non-null name of this component
     * @param model the instance of {@link IModel}from which the model object will be
     *            used as the subject for the given expression
     * @param values the list values
     * @param expression the OGNL expression that works on the given object
     * @throws wicket.RenderException Thrown if the component has been given a null name.
     */
    public ListChoice(String name, IModel model, String expression,
            final Collection values)
    {
        this(name, model, values, defaultMaxRows);
    }

    /**
     * Constructor that uses the provided object as a simple model. This object will be
     * wrapped in an instance of {@link wicket.Model}. All components have names. A
     * component's name cannot be null.
     * @param name The non-null name of this component
     * @param object the object that will be used as a simple model
     * @param values the list values
     * @throws wicket.RenderException Thrown if the component has been given a null name.
     */
    public ListChoice(String name, Serializable object, final Collection values)
    {
        this(name, object, values, defaultMaxRows);
    }

    /**
     * Constructor that uses the provided object as a dynamic model. This object will be
     * wrapped in an instance of {@link wicket.Model}that will be wrapped in an instance
     * of {@link wicket.PropertyModel}using the provided expression. Thus, using this
     * constructor is a short-hand for:
     * 
     * <pre>
     * new MyComponent(name, new PropertyModel(new Model(object), expression));
     * </pre>
     * 
     * All components have names. A component's name cannot be null.
     * @param name The non-null name of this component
     * @param object the object that will be used as the subject for the given expression
     * @param expression the OGNL expression that works on the given object
     * @param values the list values
     * @throws wicket.RenderException Thrown if the component has been given a null name.
     */
    public ListChoice(String name, Serializable object, String expression,
            final Collection values)
    {
        this(name, object, expression, values, defaultMaxRows);
    }

    /**
     * Constructor that uses the provided {@link IModel}as its model. All components have
     * names. A component's name cannot be null.
     * @param name The non-null name of this component
     * @param model the model
     * @param values the list values
     * @throws wicket.RenderException Thrown if the component has been given a null name.
     */
    public ListChoice(String name, IModel model, final Collection values, final int maxRows)
    {
        super(name, model, values);
        setRenderNullOption(false);
        this.maxRows = maxRows;
    }

    /**
     * Constructor that uses the provided instance of {@link IModel}as a dynamic model.
     * This model will be wrapped in an instance of {@link wicket.PropertyModel}using the
     * provided expression. Thus, using this constructor is a short-hand for:
     * 
     * <pre>
     * new MyComponent(name, new PropertyModel(myIModel, expression));
     * </pre>
     * 
     * All components have names. A component's name cannot be null.
     * @param name The non-null name of this component
     * @param model the instance of {@link IModel}from which the model object will be
     *            used as the subject for the given expression
     * @param values the list values
     * @param expression the OGNL expression that works on the given object
     * @throws wicket.RenderException Thrown if the component has been given a null name.
     */
    public ListChoice(String name, IModel model, String expression,
            final Collection values, final int maxRows)
    {
        super(name, model, expression, values);
        setRenderNullOption(false);
        this.maxRows = maxRows;
    }

    /**
     * Constructor that uses the provided object as a simple model. This object will be
     * wrapped in an instance of {@link wicket.Model}. All components have names. A
     * component's name cannot be null.
     * @param name The non-null name of this component
     * @param object the object that will be used as a simple model
     * @param values the list values
     * @throws wicket.RenderException Thrown if the component has been given a null name.
     */
    public ListChoice(String name, Serializable object, final Collection values, final int maxRows)
    {
        super(name, object, values);
        setRenderNullOption(false);
        this.maxRows = maxRows;
    }

    /**
     * Constructor that uses the provided object as a dynamic model. This object will be
     * wrapped in an instance of {@link wicket.Model}that will be wrapped in an instance
     * of {@link wicket.PropertyModel}using the provided expression. Thus, using this
     * constructor is a short-hand for:
     * 
     * <pre>
     * new MyComponent(name, new PropertyModel(new Model(object), expression));
     * </pre>
     * 
     * All components have names. A component's name cannot be null.
     * @param name The non-null name of this component
     * @param object the object that will be used as the subject for the given expression
     * @param expression the OGNL expression that works on the given object
     * @param values the list values
     * @throws wicket.RenderException Thrown if the component has been given a null name.
     */
    public ListChoice(String name, Serializable object, String expression,
            final Collection values, final int maxRows)
    {
        super(name, object, expression, values);
        setRenderNullOption(false);
        this.maxRows = maxRows;
    }

    /**
     * @see wicket.Component#handleComponentTag(RequestCycle, ComponentTag)
     */
    protected void handleComponentTag(final RequestCycle cycle, final ComponentTag tag)
    {
        super.handleComponentTag(cycle, tag);
        tag.put("size", Math.min(maxRows, getValues().size()));
    }
    
    /**
     * Gets the default maximum number of rows to display.
     * @return Returns the defaultMaxRows.
     */
    protected static int getDefaultMaxRows()
    {
        return defaultMaxRows;
    }

    /**
     * Sets the default maximum number of rows to display.
     * @param defaultMaxRows The defaultMaxRows to set.
     */
    protected static void setDefaultMaxRows(final int defaultMaxRows)
    {
        ListChoice.defaultMaxRows = defaultMaxRows;
    }

    /**
     * Gets the maximum number of rows to display.
     * @return the maximum number of rows to display
     */
    public int getMaxRows()
    {
        return maxRows;
    }

    /**
     * Sets the maximum number of rows to display.
     * @param maxRows the maximum number of rows to display
     * @return This
     */
    public ListChoice setMaxRows(int maxRows)
    {
        this.maxRows = maxRows;
        return this;
    }
}
{'fraction_non_alphanumeric': 0.09069483949613978, 'fraction_numerical': 0.004469727752945957, 'mean_word_length': 2.792295839753467, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7483962', 'n_tokens_mistral': 3204, 'n_tokens_neox': 3118, 'n_words': 1346}