Skip to content

Commit 2d27cfb

Browse files
committed
Added 'relative' attribute to urlbuffer component. Thanks to 0swald for the patch.
1 parent 9572fc3 commit 2d27cfb

5 files changed

Lines changed: 44 additions & 3 deletions

File tree

‎CHANGELOG.txt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
------------------------------------
2+
VERSION 3.3.4
3+
------------------------------------
4+
5+
Features & Enhancements:
6+
* Added 'relative' attribute to urlbuffer component. Thanks to 0swald for the patch.
7+
8+
Bugfixes:
9+
* Fixed bug that caused URL to get decoded twice (#16)
10+
11+
112
------------------------------------
213
VERSION 3.3.3
314
------------------------------------

‎core/src/main/java/com/ocpsoft/pretty/faces/component/renderer/UrlBufferRenderer.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ public void encodeBegin(final FacesContext context, final UIComponent component)
5555
throw new PrettyException("Mapping id was null when attempting to build URL for component: "
5656
+ component.toString() + " <" + component.getClientId(context) + ">");
5757
}
58+
59+
String relative = (String) urlBuffer.getAttributes().get("relative");
5860

5961
PrettyContext prettyContext = PrettyContext.getCurrentInstance(context);
6062
PrettyConfig prettyConfig = prettyContext.getConfig();
6163
UrlMapping urlMapping = prettyConfig.getMappingById(mappingId);
6264

63-
String href = context.getExternalContext().getRequestContextPath()
64-
+ urlBuilder.build(urlMapping, true, urlBuilder.extractParameters(component));
65+
String prettyHref = urlBuilder.build(urlMapping, true, urlBuilder.extractParameters(component));
66+
String contextPath = context.getExternalContext().getRequestContextPath();
67+
String href = (relative == null || "false".equals(relative)) ? contextPath + prettyHref : prettyHref;
6568

6669
context.getExternalContext().getRequestMap().put(var, href);
6770
}

‎core/src/main/java/com/ocpsoft/pretty/faces/component/tag/UrlBufferTag.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class UrlBufferTag extends PrettyTagBase
2727
{
2828
private String var;
2929
private String mappingId;
30+
private String relative;
3031

3132
@Override
3233
public String getComponentType()
@@ -53,6 +54,7 @@ protected void setProperties(final UIComponent component)
5354
super.setProperties(component);
5455
setAttributeProperites(component, "var", var);
5556
setAttributeProperites(component, "mappingId", mappingId);
57+
setAttributeProperites(component, "relative", relative);
5658

5759
}
5860

@@ -76,4 +78,13 @@ public void setMappingId(final String mappingId)
7678
this.mappingId = mappingId;
7779
}
7880

81+
public String getRelative()
82+
{
83+
return relative;
84+
}
85+
86+
public void setRelative(final String relative)
87+
{
88+
this.relative = relative;
89+
}
7990
}

‎core/src/main/resources/META-INF/ocpsoft-pretty-faces.tld‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,5 +363,16 @@
363363
Accessed via #{requestScope.var}
364364
</description>
365365
</attribute>
366+
<attribute>
367+
<name>relative</name>
368+
<required>false</required>
369+
<rtexprvalue>false</rtexprvalue>
370+
<type>java.lang.Boolean</type>
371+
<description>
372+
Boolean flag defining whether url should be relative to
373+
web application context path ("true") or server root ("false").
374+
Default value is "false".
375+
</description>
376+
</attribute>
366377
</tag>
367378
</taglib>

‎docs/src/main/docbook/en-US/Custom_components.xml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<title>The &lt;pretty:urlbuffer&gt; component</title>
5454
<para>
5555
PrettyFaces provides a JSF component to generate a URL for use as a page scoped variable
56-
through El. This tag requires a mapping-id (specified in the pretty-config.xml)
56+
through El. This tag requires a mapping-id (specified in the pretty-config.xml).
5757
</para>
5858
<example>
5959
<title>Using the URL buffer component</title>
@@ -75,6 +75,11 @@
7575
<para>Output:</para>
7676
<programlisting> /store/shoes/24?language=en_US</programlisting>
7777
</example>
78+
<para>
79+
URL can be relative to context path or server root, which is determined by &quot;relative&quot; attribute.
80+
When set to &quot;true&quot;, generated URL will be relative to web application context path.
81+
</para>
82+
7883
</section>
7984

8085
<section id="components.jsf">

0 commit comments

Comments
 (0)