Re: Rewriting problem

Splash Forums PrettyFaces Users Rewriting problem Re: Rewriting problem

#20777

You probably want to use a negative lookahead to prevent the infinite loop:

Guide to Regular Expressions in Java (Part 2)

<rewrite match="/(?!.*\.xhtml.*)(.*)" substitute="/faces/public/$1.xhtml" redirect="chain" outbound="false"/>

You may or may not need the \. or . depending on your requirements.

You probably also want another rule set up to fix URLs that point to XHTML files. My example might cause an infinite loop, in which case we are working on updating this regex engine to support “stops” so that when a certain condition has been reached, rewriting is halted. Right now prettyfaces works much better with <url-mappings>, so you should consider using DynaView instead:

// to fix inbound URLs pointing to XHTML files

<rewrite match="/faces/public/(.*).xhtml" substitute="/$1" redirect="301"/>

http://ocpsoft.com/docs/prettyfaces/3.2.0/en-US/html/Configuration.html#config.dynaview

//using dynaview instead of rewrite:

<url-mapping id="global">
<pattern value="/*" />
<view-id> #{bean.getViewPath} </view-id>
</url-mapping>

@Named("bean")
@RequestScoped
public class Bean {

public String getViewPath() {

URL url = PrettyContext.getCurrentInstance().getRequestURL();
String viewId = url.toString();
if(viewId.endsWith(".xhtml") return viewId;
else return viewId + ".xhtml";

}
}

~Lincoln