New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

o:url - deactivate bookmarkable url feature #416

Closed
djmj opened this Issue Nov 12, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@djmj

djmj commented Nov 12, 2017

<o:url> is a nice feature to create bookmarkable url's to reuse as a param.

But it lacks support of simple url building for external urls like:

<o:url var="varMapsSrc" href="https://www.google.com/maps/embed/v1/place">
	<o:param name="key" value="mykey"/>
	<o:param name="language" value="#{view.locale.language}"/>
	<o:param name="q" value="#{bean.address}" converter="#{addressConverter}/>
</o:url>

<iframe src="#{varMapsSrc}"></iframe>

I came across this requirement since i forgot to UTF-8 encode the params when creating url by concatenating dynamic params.

Workaround:

I extended my previously posted 'BookmarkableUrlConverter' in ticket #113 to allow external links using following function:

<o:outputFormat var="varMapsSrc" value="https://www.google.com/maps/embed/v1/place" converter="BookmarkableUrlConverter">
	<o:param name="key" value="mykey"/>
	<o:param name="language" value="#{view.locale.language}"/>
	<o:param name="q" value="#{bean.address}" converter="#{addressConverter}/>
</o:url>


/**
 * Appends the given parameters to the query string of the given uri
 *
 * @param uri
 * @param params Optional query string parameters to add
 *
 * @return
 */
public static String BuildUri(final String uri, final Collection<ParamHolder> params)
{
	Objects.requireNonNull(uri, "uri must not be null");

	final UriBuilder uriBuilder = UriBuilder.fromUri(uri);
	if (params != null)
	{
		for (final ParamHolder param : params)
		{
			final Object paramValue = param.getValue();
			if (paramValue != null)
				uriBuilder.queryParam(param.getName(), paramValue);
		}
	}

	return uriBuilder.build().toString();
}

Converter

if (component != null)
{
	params = Components.getParams(component);

	// external link
	boolean isLink = FacesContextUtils.coerceToBoolean(context, component.getAttributes().get(BookmarkableUrlConverter.ATTRIBUTE_LINK));

	// external link
	if (isLink)
	{
		final String url = BookmarkableUrlConverter.BuildUri(value, params);
		return url;
	}

	// rest of code
}
@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Dec 3, 2017

Member

Makes sense.

Member

BalusC commented Dec 3, 2017

Makes sense.

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Dec 10, 2017

Member

Implemented in 3.0-SNAPSHOT.

<o:url value="https://www.google.com/maps/embed/v1/place" var="varMapsSrc">
	<o:param name="key" value="mykey"/>
	<o:param name="language" value="#{view.locale.language}"/>
	<o:param name="q" value="#{bean.address}" converter="#{addressConverter}/>
</o:url>

When value attribute is specified, viewId and domain are ignored.

Member

BalusC commented Dec 10, 2017

Implemented in 3.0-SNAPSHOT.

<o:url value="https://www.google.com/maps/embed/v1/place" var="varMapsSrc">
	<o:param name="key" value="mykey"/>
	<o:param name="language" value="#{view.locale.language}"/>
	<o:param name="q" value="#{bean.address}" converter="#{addressConverter}/>
</o:url>

When value attribute is specified, viewId and domain are ignored.

@BalusC BalusC closed this Dec 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment