--- title: Using Parameters With Views order: 14 layout: page --- [[using-parameters-with-views]] = Using parameters with Views When the Navigator API is in use, one can pass "parameters" to Views in the URI fragment. The remainder of the fragment that is left after the (longest) view name matched is removed, is considered to be "fragment parameters". These are passed to the View in question, which can then handle the parameter(s). Basically: `#viewname/parameters`. Continuing from the basic navigation example, let's make a View that displays a message passed as a fragment parameter: [source,java] .... import com.vaadin.navigator.View; import com.vaadin.ui.Label; import com.vaadin.ui.Panel; public class MessageView extends Panel implements View { public static final String NAME = "message"; public MessageView() { super(new VerticalLayout()); setCaption("Messages"); } @Override public void enter(ViewChangeEvent event) { if(event.getParameters() != null){ // split at "/", add each part as a label String[] msgs = event.getParameters().split("/"); for (String msg : msgs) { ((Layout)getContent()).addComponent(new Label(msg)); } } } } .... Let's register `MessageView` along with the other Views: [source,java] .... import com.vaadin.navigator.Navigator; import com.vaadin.navigator.Navigator.SimpleViewDisplay; import com.vaadin.server.Page; import com.vaadin.server.WrappedRequest; import com.vaadin.ui.UI; public class NavigationtestUI extends UI { @Override public void init(VaadinRequest request) { // Create Navigator, make it control the ViewDisplay Navigator navigator = new Navigator(this, this); // Add some Views navigator.addView(MainView.NAME, new MainView()); // no fragment // #count will be a new instance each time we navigate to it, counts: navigator.addView(CountView.NAME, CountView.class); // #message adds a label with whatever it receives as a parameter navigator.addView(MessageView.NAME, new MessageView()); } } .... Finally, we'll add two labels to the MainView so we don't have to type in the browsers address-bar to try it out: [source,java] .... import com.vaadin.navigator.View; import com.vaadin.server.ExternalResource; import com.vaadin.ui.Link; import com.vaadin.ui.Panel; public class MainView extends Panel implements View { public static final String NAME = ""; public MainView() { VerticalLayout layout = new VerticalLayout(); Link lnk = new Link("Count", new ExternalResource("#!" + CountView.NAME)); layout.addComponent(lnk); lnk = new Link("Message: Hello", new ExternalResource("#!" + MessageView.NAME + "/Hello")); layout.addComponent(lnk); lnk = new Link("Message: Bye", new ExternalResource("#!" + MessageView.NAME + "/Bye/Goodbye")); layout.addComponent(lnk); setContent(layout); } @Override public void enter(ViewChangeEvent event) { } } .... Simple! Let's just conclude by noting that it's usually a good idea to make sure the parameters are URI encoded, or the browser might disapprove. option> Apache XML Graphics FOP: https://github.com/apache/xmlgraphics-fopwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/area/inline/Character.java
blob: 2135162e655e35b0e76d5416e87891c373bbc2c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * $Id: Character.java,v 1.4 2003/03/05 16:45:43 jeremias Exp $
 * ============================================================================
 *                    The Apache Software License, Version 1.1
 * ============================================================================
 * 
 * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modifica-
 * tion, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if any, must
 *    include the following acknowledgment: "This product includes software
 *    developed by the Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself, if
 *    and wherever such third-party acknowledgments normally appear.
 * 
 * 4. The names "FOP" and "Apache Software Foundation" must not be used to
 *    endorse or promote products derived from this software without prior
 *    written permission. For written permission, please contact
 *    apache@apache.org.
 * 
 * 5. Products derived from this software may not be called "Apache", nor may
 *    "Apache" appear in their name, without prior written permission of the
 *    Apache Software Foundation.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
 * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * ============================================================================
 * 
 * This software consists of voluntary contributions made by many individuals
 * on behalf of the Apache Software Foundation and was originally created by
 * James Tauber <jtauber@jtauber.com>. For more information on the Apache
 * Software Foundation, please see <http://www.apache.org/>.
 */ 
package org.apache.fop.area.inline;

import org.apache.fop.render.Renderer;

/**
 * Single character inline area.
 * This inline area holds a single character.
 */
public class Character extends InlineArea {
    private char character;

    /**
     * Create a new characater inline area with the given character.
     *
     * @param ch the character for this inline area
     */
    public Character(char ch) {
        character = ch;
    }

    /**
     * Render this inline area.
     *
     * @param renderer the renderer to render this character area
     */
    public void render(Renderer renderer) {
        renderer.renderCharacter(this);
    }

    /**
     * Get the character for this inline character area.
     *
     * @return the character
     */
    public char getChar() {
        return character;
    }
}