001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.markup.html.pages;
018
019import org.apache.wicket.markup.head.IHeaderResponse;
020import org.apache.wicket.markup.head.JavaScriptHeaderItem;
021import org.apache.wicket.markup.html.form.Form;
022import org.apache.wicket.markup.html.panel.GenericPanel;
023import org.apache.wicket.model.IModel;
024import org.apache.wicket.protocol.http.ClientProperties;
025import org.apache.wicket.request.resource.JavaScriptResourceReference;
026import org.apache.wicket.request.resource.ResourceReference;
027
028/**
029 * Form for posting JavaScript properties.
030 */
031public class BrowserInfoForm extends GenericPanel<ClientProperties>
032{
033        private static final long serialVersionUID = 1L;
034        
035        public static final ResourceReference JS = new JavaScriptResourceReference(BrowserInfoForm.class, "wicket-browser-info.js");
036
037        /**
038         * The special form that submits the client/browser info
039         */
040        private final Form<ClientProperties> form;
041
042        /**
043         * Constructor.
044         * 
045         * @param id
046         *            component id
047         */
048        public BrowserInfoForm(String id, IModel<ClientProperties> properties)
049        {
050                super(id, properties);
051
052                this.form = createForm("postback", properties);
053                form.setOutputMarkupId(true);
054                add(form);
055        }
056
057        /**
058         * Creates the form
059         *
060         * @param componentId
061         *      the id for the Form component
062         * @return the Form that will submit the data
063         */
064        protected Form<ClientProperties> createForm(String componentId, IModel<ClientProperties> properties)
065        {
066                Form<ClientProperties> form = new Form<ClientProperties>(componentId, properties)
067                {
068                        private static final long serialVersionUID = 1L;
069
070                        @Override
071                        protected void onSubmit()
072                        {
073                                getModelObject().read(getRequest().getPostParameters());
074
075                                afterSubmit();
076                        }
077                };
078                return form;
079        }
080
081        protected void afterSubmit()
082        {
083        }
084
085        @Override
086        public void renderHead(IHeaderResponse response)
087        {
088                super.renderHead(response);
089
090                response.render(JavaScriptHeaderItem.forReference(JS));
091        }
092
093        /**
094         * @return The markup id of the form that submits the client info
095         */
096        public String getFormMarkupId()
097        {
098                return form.getMarkupId();
099        }
100}