| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Message |
|
| 0.0;0 |
| 1 | // Copyright 2008 Thiago H. de Paula Figueiredo | |
| 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 br.com.arsmachina.tapestrycrud.components; | |
| 16 | ||
| 17 | import org.apache.tapestry5.MarkupWriter; | |
| 18 | import org.apache.tapestry5.annotations.BeforeRenderTemplate; | |
| 19 | import org.apache.tapestry5.annotations.Parameter; | |
| 20 | ||
| 21 | /** | |
| 22 | * Component that only shows a message if a given text is not null and not empty. | |
| 23 | * It puts the message inside a <code>div</code> with class <code>t-crud-message</code>. | |
| 24 | * One example can be found in | |
| 25 | * <a href="http://ars-machina.svn.sourceforge.net/viewvc/ars-machina/example/trunk/src/main/webapp/project/EditProject.tml?view=markup" | |
| 26 | * >Ars Machina Project Example</a>. | |
| 27 | * | |
| 28 | * @author Thiago H. de Paula Figueiredo | |
| 29 | */ | |
| 30 | 0 | public class Message { |
| 31 | ||
| 32 | /** | |
| 33 | * Generated <code><div></code> CSS class. | |
| 34 | */ | |
| 35 | private static final String CSS_CLASS = "t-crud-message"; | |
| 36 | ||
| 37 | /** | |
| 38 | * Message to be shown. | |
| 39 | */ | |
| 40 | @Parameter(required = true) | |
| 41 | private String message; | |
| 42 | ||
| 43 | @BeforeRenderTemplate | |
| 44 | public boolean render(MarkupWriter writer) { | |
| 45 | ||
| 46 | 0 | if (message != null && message.trim().length() > 0) { |
| 47 | ||
| 48 | 0 | writer.element("div", "class", CSS_CLASS); |
| 49 | ||
| 50 | 0 | writer.element("p"); |
| 51 | 0 | writer.write(message); |
| 52 | 0 | writer.end(); // p |
| 53 | ||
| 54 | 0 | writer.end(); // div |
| 55 | ||
| 56 | } | |
| 57 | ||
| 58 | 0 | return false; |
| 59 | ||
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * Returns the value of the <code>message</code> property. | |
| 64 | * | |
| 65 | * @return a {@link String}. | |
| 66 | */ | |
| 67 | final public String getMessage() { | |
| 68 | 0 | return message; |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * Changes the value of the <code>message</code> property. | |
| 73 | * | |
| 74 | * @param message a {@link String}. | |
| 75 | */ | |
| 76 | final public void setMessage(String message) { | |
| 77 | 0 | this.message = message; |
| 78 | 0 | } |
| 79 | ||
| 80 | } |