|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| Submit.java | 100% | 100% | 100% | 100% |
|
||||||||||||||
| 1 | // Copyright 2004, 2005 The Apache Software Foundation | |
| 2 | // | |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 | // you may not use this file except in compliance with the License. | |
| 5 | // You may obtain a copy of the License at | |
| 6 | // | |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | // | |
| 9 | // Unless required by applicable law or agreed to in writing, software | |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 | // See the License for the specific language governing permissions and | |
| 13 | // limitations under the License. | |
| 14 | ||
| 15 | package org.apache.tapestry.form; | |
| 16 | ||
| 17 | import org.apache.tapestry.IMarkupWriter; | |
| 18 | import org.apache.tapestry.IRequestCycle; | |
| 19 | ||
| 20 | /** | |
| 21 | * Implements a component that manages an HTML <input type=submit> form element. [ <a | |
| 22 | * href="../../../../../ComponentReference/Submit.html">Component Reference </a>] | |
| 23 | * <p> | |
| 24 | * This component is generally only used when the form has multiple submit buttons, and it is | |
| 25 | * important for the application to know which one was pressed. You may also want to use | |
| 26 | * {@link ImageSubmit}which accomplishes much the same thing, but uses a graphic image instead. | |
| 27 | * | |
| 28 | * @author Howard Lewis Ship | |
| 29 | */ | |
| 30 | ||
| 31 | public abstract class Submit extends AbstractSubmit | |
| 32 | { | |
| 33 | 6 | protected boolean isClicked(IRequestCycle cycle, String name) |
| 34 | { | |
| 35 | // How to know which Submit button was actually | |
| 36 | // clicked? When submitted, it produces a request parameter | |
| 37 | // with its name and value (the value serves double duty as both | |
| 38 | // the label on the button, and the parameter value). | |
| 39 | ||
| 40 | // If the value isn't there, then this button wasn't | |
| 41 | // selected. | |
| 42 | 6 | return cycle.getParameter(name) != null; |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter, | |
| 47 | * org.apache.tapestry.IRequestCycle) | |
| 48 | */ | |
| 49 | 9 | protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle) |
| 50 | { | |
| 51 | 9 | writer.beginEmpty("input"); |
| 52 | 9 | writer.attribute("type", "submit"); |
| 53 | 9 | writer.attribute("name", getName()); |
| 54 | ||
| 55 | 9 | if (isDisabled()) |
| 56 | 3 | writer.attribute("disabled", "disabled"); |
| 57 | ||
| 58 | 9 | String label = getLabel(); |
| 59 | ||
| 60 | 9 | if (label != null) |
| 61 | 3 | writer.attribute("value", label); |
| 62 | ||
| 63 | 9 | renderIdAttribute(writer, cycle); |
| 64 | ||
| 65 | 9 | renderInformalParameters(writer, cycle); |
| 66 | ||
| 67 | 9 | writer.closeTag(); |
| 68 | } | |
| 69 | ||
| 70 | /** parameter */ | |
| 71 | public abstract String getLabel(); | |
| 72 | ||
| 73 | } |
|
||||||||||