⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dropdownchoice.java

📁 Wicket一个开发Java Web应用程序框架。它使得开发web应用程序变得容易而轻松。 Wicket利用一个POJO data beans组件使得它可以与任何持久层技术相结合。
💻 JAVA
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 org.apache.wicket.markup.html.form;import java.util.List;import org.apache.wicket.RequestContext;import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;import org.apache.wicket.markup.ComponentTag;import org.apache.wicket.model.IModel;import org.apache.wicket.protocol.http.portlet.PortletRequestContext;/** * A choice implemented as a dropdown menu/list. * <p> * Java: *  * <pre> * List SITES = Arrays.asList(new String[] { &quot;The Server Side&quot;, &quot;Java Lobby&quot;, &quot;Java.Net&quot; }); *  * // Add a dropdown choice component that uses Input's 'site' property to designate the * // current selection, and that uses the SITES list for the available options. * // Note that when the selection is null, Wicket will lookup a localized string to * // represent this null with key: &quot;id + '.null'&quot;. In this case, this is 'site.null' * // which can be found in DropDownChoicePage.properties * form.add(new DropDownChoice(&quot;site&quot;, SITES)); * </pre> *  * HTML: *  * <pre> *   	&lt;select wicket:id=&quot;site&quot;&gt; *   		&lt;option&gt;site 1&lt;/option&gt; *   		&lt;option&gt;site 2&lt;/option&gt; *   	&lt;/select&gt; * </pre> *  * </p> *  * <p> * You can can extend this class and override method wantOnSelectionChangedNotifications() to force * server roundtrips on each selection change. * </p> *  * @author Jonathan Locke * @author Eelco Hillenius * @author Johan Compagner */public class DropDownChoice extends AbstractSingleSelectChoice implements IOnChangeListener{	private static final long serialVersionUID = 1L;	/**	 * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String)	 */	public DropDownChoice(final String id)	{		super(id);	}	/**	 * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String, List)	 */	public DropDownChoice(final String id, final List choices)	{		super(id, choices);	}	/**	 * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String,	 *      List,IChoiceRenderer)	 */	public DropDownChoice(final String id, final List data, final IChoiceRenderer renderer)	{		super(id, data, renderer);	}	/**	 * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String, IModel, List)	 */	public DropDownChoice(final String id, IModel model, final List choices)	{		super(id, model, choices);	}	/**	 * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String, IModel, List,	 *      IChoiceRenderer)	 */	public DropDownChoice(final String id, IModel model, final List data,			final IChoiceRenderer renderer)	{		super(id, model, data, renderer);	}	/**	 * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String, IModel)	 */	public DropDownChoice(String id, IModel choices)	{		super(id, choices);	}	/**	 * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String, IModel,IModel)	 */	public DropDownChoice(String id, IModel model, IModel choices)	{		super(id, model, choices);	}	/**	 * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String,	 *      IModel,IChoiceRenderer)	 */	public DropDownChoice(String id, IModel choices, IChoiceRenderer renderer)	{		super(id, choices, renderer);	}	/**	 * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String, IModel,	 *      IModel,IChoiceRenderer)	 */	public DropDownChoice(String id, IModel model, IModel choices, IChoiceRenderer renderer)	{		super(id, model, choices, renderer);	}	/**	 * Called when a selection changes.	 */	public final void onSelectionChanged()	{		convertInput();		updateModel();		onSelectionChanged(getModelObject());	}	/**	 * Processes the component tag.	 * 	 * @param tag	 *            Tag to modify	 * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)	 */	protected void onComponentTag(final ComponentTag tag)	{		checkComponentTag(tag, "select");		// Should a roundtrip be made (have onSelectionChanged called) when the		// selection changed?		if (wantOnSelectionChangedNotifications())		{			// url that points to this components IOnChangeListener method			CharSequence url = urlFor(IOnChangeListener.INTERFACE);			Form form = (Form)findParent(Form.class);			if (form != null)			{				RequestContext rc = RequestContext.get();				if (rc.isPortletRequest())				{					// restore url back to real wicket path as its going to be interpreted by the					// form itself					url = ((PortletRequestContext)rc).getLastEncodedPath();				}				tag.put("onchange", form.getJsForInterfaceUrl(url));			}			else			{				// TODO: following doesn't work with portlets, should be posted to a dynamic hidden				// form				// with an ActionURL or something				tag.put("onchange", "window.location.href='" + url +						(url.toString().indexOf('?') > -1 ? "&amp;" : "?") + getInputName() +						"=' + this.options[this.selectedIndex].value;");			}		}		super.onComponentTag(tag);	}	/**	 * Template method that can be overridden by clients that implement IOnChangeListener to be	 * notified by onChange events of a select element. This method does nothing by default.	 * <p>	 * Called when a option is selected of a dropdown list that wants to be notified of this event.	 * This method is to be implemented by clients that want to be notified of selection events.	 * 	 * @param newSelection	 *            The newly selected object of the backing model NOTE this is the same as you would	 *            get by calling getModelObject() if the new selection were current	 */	protected void onSelectionChanged(final Object newSelection)	{	}	/**	 * Whether this component's onSelectionChanged event handler should be called using javascript	 * <tt>window.location</tt> if the selection changes. If true, a roundtrip will be generated	 * with each selection change, resulting in the model being updated (of just this component) and	 * onSelectionChanged being called. This method returns false by default. If you wish to use	 * Ajax instead, let {@link #wantOnSelectionChangedNotifications()} return false and add an	 * {@link AjaxFormComponentUpdatingBehavior} to the component using the <tt>onchange</tt>	 * event.	 * 	 * @return True if this component's onSelectionChanged event handler should called using	 *         javascript if the selection changes	 */	protected boolean wantOnSelectionChangedNotifications()	{		return false;	}	/**	 * @see org.apache.wicket.MarkupContainer#getStatelessHint()	 */	protected boolean getStatelessHint()	{		if (wantOnSelectionChangedNotifications())		{			return false;		}		return super.getStatelessHint();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -