使用正则表达式在Pretty Faces中

huangapple 未分类评论83阅读模式
英文:

Using regular expression in Pretty Faces

问题

我有一个项目,我在其中使用Pretty Faces进行URL重写。
这是pretty-config.xml文件。

<url-mapping parentId="level2" id="level3">
    <pattern value="/#{bean.urlLiv3}">
    </pattern>
    <view-id value="/index.xhtml" />
    <action>#{bean.loadLiv3}</action>
</url-mapping>

<url-mapping parentId="level2" id="level2">
    <pattern value="/#{bean.urlLiv2}">
    </pattern>
    <view-id value="/index.xhtml" />
    <action>#{bean.loadLiv2}</action>
</url-mapping>

<url-mapping parentId="main" id="level1">
    <pattern value="#{ /.*-.*/ bean.urlLiv1 }" >
    </pattern>
    <view-id value="/index.xhtml" />
    <action>#{bean.loadLiv1}</action>
</url-mapping>

<url-mapping id="main">
    <pattern value="/" />
    <view-id value="/index.xhtml" />
    <action>#{bean.loadLiv0}</action>
</url-mapping>

它一直延伸到第5级。
在第1级上没有正则表达式/.*-.*/时,每个级别都正常工作,但是当我添加它时,在尝试导航到第3、4和5级时会出错。
这是错误信息:

Error parsing url: </urlliv1-8/urlliv2-43/urlliv3-20>,参数与模式中的编译段不匹配:/#{ /.*-.*/ bean.urlLiv1 }/#{bean.urlLiv2}/#{ bean.urlLiv3 }

有人知道为什么会出现这个错误吗?
谢谢

英文:

I have a project in which I am using Pretty Faces for url rewriting.
This is the pretty-config.xml.

&lt;url-mapping parentId=&quot;level2&quot; id=&quot;level3&quot; &gt;
	&lt;pattern value=&quot;/#{bean.urlLiv3 }&quot;&gt;
	&lt;/pattern&gt;
	&lt;view-id value=&quot;/index.xhtml&quot; /&gt;
	&lt;action&gt;#{bean.loadLiv3}&lt;/action&gt;
&lt;/url-mapping&gt;

&lt;url-mapping parentId=&quot;level2&quot; id=&quot;level2&quot; &gt;
	&lt;pattern value=&quot;/#{bean.urlLiv2}&quot;&gt;
	&lt;/pattern&gt;
	&lt;view-id value=&quot;/index.xhtml&quot; /&gt;
	&lt;action&gt;#{bean.loadLiv2}&lt;/action&gt;
&lt;/url-mapping&gt;

&lt;url-mapping parentId=&quot;main&quot; id=&quot;level1&quot; &gt;
	&lt;pattern value=&quot;#{ /.*-.*/ bean.urlLiv1 }&quot; &gt;&lt;/pattern&gt;
	&lt;view-id value=&quot;/index.xhtml&quot; /&gt;
	&lt;action&gt;#{bean.loadLiv1}&lt;/action&gt;
&lt;/url-mapping&gt;
	
&lt;url-mapping id=&quot;main&quot;&gt;
	&lt;pattern value=&quot;/&quot; /&gt;
	&lt;view-id value=&quot;/index.xhtml&quot; /&gt;
	&lt;action&gt;#{bean.loadLiv0}&lt;/action&gt;
&lt;/url-mapping&gt; 

'''
It goes on up to level 5.
Without the regular expression /.*-.*/ on level 1 it works fine for every level, but when I add it I get an error when trying to navigate on levels 3, 4 and 5.
This is the error
> Error parsing url: &lt;/urlliv1-8/urlliv2-43/urlliv3-20&gt;, a parameter did not match compiled segment in pattern: /#{ /.*-.*/ bean.urlLiv1 }/#{bean.urlLiv2}/#{ bean.urlLiv3 }

Does anyone has an idea why I get this error?
Thanks

答案1

得分: 0

抱歉,对于稍微令人困惑的错误消息。这可能是因为您在 urlLiv1 的正则模式中使用了 .*

.*. 的一个主要问题是这些模式会匹配 / 字符。尝试使用类似这样的内容:[^/]* 而不是 . 匹配器。

英文:

sorry for the slightly confusing error message. This is likely due to the fact that you are using .* in your regex patterns for urlLiv1.

A major problem with .* or . is that these patterns will match / characters. Try using something like this instead: [^/]* of the . matcher.

huangapple
  • 本文由 发表于 2020年8月14日 18:12:03
  • 转载请务必保留本文链接:https://java.coder-hub.com/63410814.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定