【问题标题】:Pretty Faces multiple annotation, which one was loaded?Pretty Faces 多个注解,加载的是哪一个?
【发布时间】:2014-10-15 02:35:29
【问题描述】:

我在托管 Bean 上有多个 PrettyFaces 注释,如何确定页面从哪个入口点加载而不查看传递的参数?

import com.ocpsoft.pretty.faces.annotation.URLAction;
import com.ocpsoft.pretty.faces.annotation.URLMapping;
import com.ocpsoft.pretty.faces.annotation.URLMappings;

@ManagedBean(name = "bean")
    @ViewScoped
    @URLMappings(mappings = {
            @URLMapping(id = "addObject", pattern = "add/type-#{bean.type}", viewId = "/views/object.jsf" ),
            @URLMapping(id = "editObject", pattern = "edit/#{bean.objId}", viewId = "/views/object.jsf")
    })
    public class Bean implements Serializable { 
        private Long type;
        private Long objId;

        @URLAction(onPostback = false)
        public void load() {
                if(objId!=null){
                    //edit mode
                }else{
                    // add mode
                }
        }       
        // getters / setters
    }

【问题讨论】:

    标签: jsf-2 url-routing prettyfaces


    【解决方案1】:

    您可以像这样使用PrettyContext 访问当前映射的ID:

    String id = PrettyContext.getCurrentInstance().getCurrentMapping().getId();
    

    【讨论】:

      猜你喜欢
      • 2013-08-14
      • 2020-03-02
      • 2018-08-17
      • 2011-10-24
      • 2013-04-24
      • 1970-01-01
      • 2020-12-04
      • 2013-07-28
      • 1970-01-01
      相关资源
      最近更新 更多