Pretty Faces多个注释,哪一个被加载?

时间:2014-10-14 09:30:50

标签: jsf-2 url-routing prettyfaces

我在Managed 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
    }

1 个答案:

答案 0 :(得分:1)

您可以使用PrettyContext访问当前映射的ID,如下所示:

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