01: /*
02: * Created on Jul 27, 2005
03: */
04: package uk.org.ponder.rsf.components;
05:
06: /**
07: * Peers with any tag/control in markup which is associated with a URL. In HTML,
08: * for example, these controls are links(<a>), <img>, <frame>,
09: * <iframe> and <script> tags. In the case the component simple
10: * navigational link, operating this link is expected to give rise to an
11: * idempotent ("render") request. In the case where the control accepts some
12: * text (links), this may be supplied as the <code>linktext</code> field,
13: * which may be either a direct String value or a bound String such as a
14: * {@link UIMessage}. For more complex command contents including bound ones,
15: * leave <code>linktext</code> as null and add rendering components as childen
16: * of the link in the template.
17: *
18: * @author Antranig Basman (antranig@caret.cam.ac.uk)
19: */
20: public class UILink extends UIComponent {
21: /**
22: * A string representing the target of this link - e.g. in an HTML system, a
23: * URL. In HTML in particular, the special prefix $context/ will be resolved
24: * onto the context for the current webapp - that is, the directory
25: * immediately above WEB-INF.
26: *
27: * <p/> For an InternalLink this will be filled in by a fixup from the
28: * ViewParameters member.
29: */
30: public UIBoundString target;
31:
32: /** A bound String representing any text to be rendered for this control * */
33: public UIBoundString linktext;
34:
35: /**
36: * Construct a navigation link.
37: *
38: * @param parent Container to which the link is to be added.
39: * @param ID RSF ID of this link.
40: * @param text Text to be rendered for this link.
41: * @param target
42: * @see {@link #target}
43: */
44: public static UILink make(UIContainer parent, String ID,
45: String linktext, String target) {
46: UIBoundString linktextnew = null;
47: if (linktext != null) {
48: linktextnew = new UIOutput();
49: linktextnew.setValue(linktext);
50: }
51: return make(parent, ID, linktextnew, target);
52: }
53:
54: /**
55: * Construct a navigation link with a bound control (e.g. UIMessage) forming
56: * the link text.
57: */
58: public static UILink make(UIContainer parent, String ID,
59: UIBoundString linktext, String target) {
60: UILink togo = new UILink();
61: togo.ID = ID;
62: togo.target = new UIOutput();
63: if (target != null) {
64: togo.target.setValue(target);
65: }
66: togo.linktext = linktext;
67: parent.addComponent(togo);
68: return togo;
69: }
70:
71: /**
72: * Construct a navigation link which will leave nested markup unchanged from
73: * the template.
74: */
75: public static UILink make(UIContainer parent, String ID,
76: String target) {
77: return make(parent, ID, (UIBoundString) null, target);
78: }
79:
80: /**
81: * Construct a navigation link which will leave both link target and nested
82: * markup unchanged from the template. This is useful, say, for conditionally
83: * rendering a relative link from the template.
84: */
85: public static UILink make(UIContainer parent, String ID) {
86: return make(parent, ID, (UIBoundString) null, null);
87: }
88:
89: }
|