我在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
}
答案 0 :(得分:1)
您可以使用PrettyContext
访问当前映射的ID,如下所示:
String id = PrettyContext.getCurrentInstance().getCurrentMapping().getId();