Reply To: Outbound rule for Internationalize your URLs

Splash Forums Rewrite Users Outbound rule for Internationalize your URLs Reply To: Outbound rule for Internationalize your URLs

#27137

brnovais
Participant

Yes, I am positive. When I remove this part of the code, it works.
Just created a new project. Full source code below.

ConfigurationProviderLocalized.java

@RewriteConfiguration
public class ConfigurationProviderLocalized extends HttpConfigurationProvider {
	@Override
	public int priority() {
		return 50;
	}

	@Override
	public Configuration getConfiguration(ServletContext context) {
		ConfigurationBuilder lReturnConfig = ConfigurationBuilder.begin();

		lReturnConfig.addRule(Join.path("/{lang}/{path}").to("/{path}.xhtml"))
		.where("path").transposedBy(LocaleTransposition.bundle("test.Routes", "lang"));

		return lReturnConfig;
	}
}

ConfigurationProviderDebug.java

@RewriteConfiguration
public class ConfigurationProviderDebug extends HttpConfigurationProvider {
	@Override
	public int priority() {
		return 1;
	}

	@Override
	public Configuration getConfiguration(ServletContext context) {
		ConfigurationBuilder lReturnConfig = ConfigurationBuilder.begin();

		lReturnConfig.addRule()
		.when(Direction.isInbound().and(Path.matches("{path}")))
		.perform(Log.message(Level.INFO, "INBOUND: {path}"))
		.where("path").matches(".*");

		lReturnConfig.addRule()
		.when(Direction.isOutbound().and(Path.matches("{path}")))
		.perform(Log.message(Level.INFO, "OUTBOUND: {path}"))
		.where("path").matches(".*");

		return lReturnConfig;
	}
}

signin.xhtml

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
	<h:head>
		<meta charset="utf-8" />
		<title>Test</title>
	</h:head>
	<h:body>
		<h:link outcome="/signin.xhtml" value="Test">
			<f:param name="lang" value="en" />
		</h:link>
	</h:body>
</html>

Routes_en.properties
signin=signin

Routes_pt.properties
entrar=signin

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
		http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

	<context-param>
		<param-name>javax.faces.PROJECT_STAGE</param-name>
		<param-value>Development</param-value>
	</context-param>

	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
	</servlet>

	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.xhtml</url-pattern>
	</servlet-mapping>
</web-app>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>test</groupId>
	<artifactId>accounts</artifactId>
	<packaging>war</packaging>
	<version>0.0.1</version>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.2</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.wildfly.plugins</groupId>
				<artifactId>wildfly-maven-plugin</artifactId>
				<version>1.0.2.Final</version>
			</plugin>
		</plugins>
	</build>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.faces</groupId>
			<artifactId>javax.faces-api</artifactId>
			<version>2.2</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.enterprise</groupId>
			<artifactId>cdi-api</artifactId>
			<version>1.2</version>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>org.ocpsoft.rewrite</groupId>
			<artifactId>rewrite-servlet</artifactId>
			<version>3.0.0.Alpha6</version>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.ocpsoft.rewrite</groupId>
			<artifactId>rewrite-integration-faces</artifactId>
			<version>3.0.0.Alpha6</version>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.ocpsoft.rewrite</groupId>
			<artifactId>rewrite-integration-cdi</artifactId>
			<version>3.0.0.Alpha6</version>
			<scope>compile</scope>
		</dependency>
	</dependencies>
</project>