Prettyfaces:在观察特定的url模式时,将bean属性设置为某个常量值
在pretty-config.xml
编写Prettyfaces的URL映射规则时,我想添加一条规则,即只要在URL中观察到特定模式,就会为bean属性设置一个特定的常量值。 例如,当存在像../products/electronics
这样的模式时,它应该将bean属性bean.category
设置为ELECTRONICS_ITEMS
。 我怎么做 ?
您应该只使用path参数并将URL中的值转换为页面操作方法中的常量。 像这样的东西:
#{bean.action}
和动作方法:
public void action() { if( "electronics".equals(this.category) ) { this.category = "ELECTRONICS_ITEMS"; } // more categories... }
因为我正在使用prettyfaces注释我不知道pretty-config.xml
如果我得到这个条件然后我会在这样的注释中使用它
@URLAction(mappingId = "someMappingId", onPostback = false) public String setConstantValue() { // set your bean here return null; }