title: How to properly check selectors and extensions via RequestPathInfo
body: <p>I've been working on a component and currently I'm trying to do different things based on the selector chosen for the component.</p>
  <p>So basically if I have a component with this structure</p>
  <pre><code>myComponent/
    dialog.xml
    myComponent.jsp
    altView.jsp
  </code></pre>
  <p>I know that if I have a Node with resourceType myComponent I can request the alt view via browser by requesting &quot;path/to/component/content.altView.html&quot; and everything is hunky dory.</p>
  <p>Similarly I can do a cq include and do something like:</p>
  <pre><code># with cq include
  &lt;cq:include path=&quot;my/path.altView&quot; resourceType=&quot;myComponent&quot;/&gt;
  
  # or with sling include
  &lt;sling:include path=&quot;my/path&quot; resourceType=&quot;myComponent&quot;  replaceSelectors=&quot;altView&quot;/&gt;
  </code></pre>
  <p>However, when I'm handling the request, I've seen some interesting behavior when looking at the <a href="http://dev.day.com/docs/en/cq/5-5/javadoc/org/apache/sling/api/request/RequestPathInfo.html" rel="nofollow noreferrer">RequestPathInfo</a> Object.</p>
  <p>For example, if we look at all 3 of the above cases I might have something like this:</p>
  <pre><code># http://path/to/component/content.altView.html
  slingRequest.getRequestPathInfo().getSelectors(); // {altView}
  slingRequest.getRequestPathInfo().getExtension(); // html
  
  # &lt;sling:include path=&quot;my/path&quot; resourceType=&quot;myComponent&quot;  replaceSelectors=&quot;altView&quot;/&gt;
  slingRequest.getRequestPathInfo().getSelectors(); // {altView}
  slingRequest.getRequestPathInfo().getExtension(); // html
  
  # &lt;cq:include path=&quot;my/path.altView&quot; resourceType=&quot;myComponent&quot;/&gt;
  slingRequest.getRequestPathInfo().getSelectors(); // []
  slingRequest.getRequestPathInfo().getExtension(); // altView
  </code></pre>
  <p>I understand why the cq:include returns different results (we're making a request to my/path.altView and .altView coincidentally serves as the extension in this case). I'm curious if there is a normalized why to pull &quot;altView&quot; (or the selected view) regardless of if it's been used as an extension or selector. Or if this is normal and I just need to check both the extensions and selectors individually.</p>
  <p>i.e</p>
  <pre><code>selectors = get selectors();
  if selectors
     do stuff
  else check extensions
     do stuff
  </code></pre>
  <p>Again thank you very much for your insights, this community is awesome.</p>
  <p>[EDIT]</p>
  <p>In response to an answer, I thought I'd give a little more context to what I'm doing. Basically our component structure is set up so that each of our components has an associated Java Class that handles the business logic. (I.E. apps/myapp/components/myComponent will map to com.mypackage.components.MyComponent) That said, within my component's Class I need to handle the control flow differently depending on how the component was called (i.e. what selectors/extensions/etc). For example, if my component was called normally I'd do the base behavior, but if it was called with selector (for exmaple) &quot;altView&quot; I would need to handle the alternative view differently, and in this alternative view different data will be available, etc.</p>
  <p>My question was along the basis that it seems that i can give the &quot;path&quot; attribute of a &quot;cq:include&quot; tag the selector I want to use:</p>
  <pre><code>&lt;cq:include path=&quot;my/path.altView&quot; resourceType=&quot;myComponent&quot;/&gt;
  </code></pre>
  <p>However, when I check my RequestPathInfo in my component class to decide workflow, &quot;altView&quot; is returned as the extension, not within the String[] selectors. Note, the above compiles fine, and it selectors the correct .jsp file for rendering, the RequestPathInfo object just stores the data in a different place.</p>
  <p>I'm starting to guess that places the selector into the path attribute works because the selectors and extensions modifiers alter the behavior vary similarly. mycomponent.altView.html resolves to altView.jsp whereas if I was to do mycomponent.altView it would also attempt to resolve a mycomponent/altView.jsp just as it would do the same for mycomponent.xml to mycomponent/XML.jsp</p>