Prettyfaces:在观察特定 url 模式时将 bean 属性设置为某个常量值 [英] Prettyfaces: Set a bean property to some constant value, on observing a specific url pattern

查看:13
本文介绍了Prettyfaces:在观察特定 url 模式时将 bean 属性设置为某个常量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆