prettyfaces:在观察特定的url模式时,将bean属性设置为某个常量值 [英] Prettyfaces: Set a bean property to some constant value, on observing a specific url pattern
问题描述
在pretty-config.xml
中为Prettyfaces编写URL映射规则时,我想添加一条规则,即只要在URL中观察到特定模式,就应为bean属性设置一个特定的常量值.
例如如果存在类似../products/electronics
的模式,则应将bean属性bean.category
设置为ELECTRONICS_ITEMS
.我该怎么办?
While writing the URL mapping rules for Prettyfaces in pretty-config.xml
I would like to add a rule that whenever a particular pattern is observed in URL then set a specific constant value to bean property.
For e.g. when there is a pattern like ../products/electronics
then it should set bean property bean.category
to ELECTRONICS_ITEMS
. How do I do that ?
推荐答案
您应该只使用路径参数,并通过页面操作方法将URL的值转换为常量.像这样:
You should simply use a path parameter and convert the value from the URL to your constant in a page action method. Something like this:
<url-mapping id="products">
<pattern value="/products/#{bean.category}/" />
<view-id value="/faces/shop/store.jsf" />
<action>#{bean.action}</action>
</url-mapping>
动作方法:
public void action() {
if( "electronics".equals(this.category) ) {
this.category = "ELECTRONICS_ITEMS";
}
// more categories...
}
这篇关于prettyfaces:在观察特定的url模式时,将bean属性设置为某个常量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!