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.form; 018 019import org.apache.wicket.markup.html.link.AbstractLink; 020import org.apache.wicket.model.IModel; 021 022/** 023 * Abstract class for links that are capable of submitting a form. 024 * 025 * @author Matej Knopp 026 * 027 */ 028public abstract class AbstractSubmitLink extends AbstractLink implements IFormSubmittingComponent 029{ 030 private static final long serialVersionUID = 1L; 031 032 /** 033 * Target form or null if the form is parent of the link. 034 */ 035 private Form<?> form; 036 037 /** 038 * If false, all standard processing like validating and model updating is skipped. 039 */ 040 private boolean defaultFormProcessing = true; 041 042 /** 043 * Construct. 044 * 045 * @param id 046 * @param model 047 */ 048 public AbstractSubmitLink(String id, IModel<?> model) 049 { 050 super(id, model); 051 } 052 053 /** 054 * 055 * Construct. 056 * 057 * @param id 058 */ 059 public AbstractSubmitLink(String id) 060 { 061 super(id); 062 } 063 064 /** 065 * Construct. 066 * 067 * @param id 068 * @param model 069 * @param form 070 */ 071 public AbstractSubmitLink(String id, IModel<?> model, Form<?> form) 072 { 073 super(id, model); 074 this.form = form; 075 } 076 077 /** 078 * Construct. 079 * 080 * @param id 081 * @param form 082 */ 083 public AbstractSubmitLink(String id, Form<?> form) 084 { 085 super(id); 086 this.form = form; 087 } 088 089 /** 090 * Sets the defaultFormProcessing property. When false (default is true), all validation and 091 * form updating is bypassed and the onSubmit method of that button is called directly, and the 092 * onSubmit method of the parent form is not called. A common use for this is to create a cancel 093 * button. 094 * 095 * TODO: This is a copy and paste from Button 096 * 097 * @param defaultFormProcessing 098 * defaultFormProcessing 099 * @return This 100 */ 101 @Override 102 public final AbstractSubmitLink setDefaultFormProcessing(boolean defaultFormProcessing) 103 { 104 if (this.defaultFormProcessing != defaultFormProcessing) 105 { 106 addStateChange(); 107 } 108 109 this.defaultFormProcessing = defaultFormProcessing; 110 return this; 111 } 112 113 @Override 114 public boolean getDefaultFormProcessing() 115 { 116 return defaultFormProcessing; 117 } 118 119 @Override 120 public Form<?> getForm() 121 { 122 if (form != null) 123 { 124 return form; 125 } 126 else 127 { 128 return findParent(Form.class); 129 } 130 } 131 132 @Override 133 public String getInputName() 134 { 135 return Form.getRootFormRelativeId(this); 136 } 137}