0

I have a multiple PrettyFaces annotation on a Managed Bean, how do I determine from which entry point the page was loaded without looking at parameters passed ?

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
    }
Lincoln
  • 3,151
  • 17
  • 22
alexedy
  • 1
  • 1

1 Answers1

1

You can access the ID of the current mapping usind the PrettyContext like this:

String id = PrettyContext.getCurrentInstance().getCurrentMapping().getId();
chkal
  • 5,598
  • 21
  • 26