Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help in getting attributes for mobile device in Adobe CQ 5 Mobile Application Development
    primarykey
    data
    text
    <p>I am new to CQ 5 Mobile Application Development what I want to achieve is, When a mobile device send the request to the page it captures the attributes of mobile like mobile browser, mobile browser version, mobile OS and mobile OS version. I want to LOG this information and in later stage use this to categorize them in different Device Group and render different components in different device groups.</p> <p><strong>Note I have already went through some of these links</strong> <a href="http://dev.day.com/docs/en/cq/5-5/developing/mobile.html" rel="nofollow">CQ5 Mobile Development Docs</a></p> <p><a href="http://www.cognifide.com/blogs/cq/adobe-cq-5-5-mobile-improvements/" rel="nofollow">http://www.cognifide.com/blogs/cq/adobe-cq-5-5-mobile-improvements/</a> <a href="http://wurfl.sourceforge.net/help_doc.php" rel="nofollow">http://wurfl.sourceforge.net/help_doc.php</a></p> <p>I have tried this code which throws Null Pointer Exception, since device has null value. Correct me if I am doing wrong somewhere</p> <pre><code>SlingHttpServletRequest slingRequest = this.request.getSlingRequest(); Device device = slingRequest.adaptTo(Device.class); Map&lt;String, String&gt; deviceAttributes = device.getAttributes(); LOG.info("Request is sent from Device with OS"+deviceAttributes.get("device_os")); </code></pre> <p>Here is the way I am testing this code, whenever a request is sent to the page which has this component which logs the attributes of the mobile device from one of the emulator, I check my LOG Files that </p> <p>Please help me out if I am going wrong in the code or method to get the mobile device's attributes. Please let me know if you need more details on this.</p> <p>Regards, Yash</p> <p>Hi Here is the Stack Trace for this :</p> <pre><code>Caused by: org.apache.sling.api.SlingException: An exception occurred processing JSP page /apps/companyname/components/content/mobilebreadcrum/mobilebreadcrum.jsp at line 5 at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:571) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:496) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:448) at org.apache.sling.scripting.jsp.JspServletWrapperAdapter.service(JspServletWrapperAdapter.java:59) at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:173) at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:84) at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:388) at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:358) ... 147 more Caused by: javax.el.ELException: Error reading 'modelName' on type com.companyname.www.components.content.mobilebreadcrumb.MobileBreadCrum at javax.el.BeanELResolver.getValue(BeanELResolver.java:66) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53) at org.apache.el.parser.AstValue.getValue(AstValue.java:97) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) at org.apache.sling.scripting.jsp.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:923) at org.apache.jsp.apps.companyname.components.content.mobilebreadcrum.mobilebreadcrum_jsp._jspService(mobilebreadcrum_jsp.java:160) at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419) ... 152 more Caused by: java.lang.NullPointerException at com.companyname.www.components.content.mobilebreadcrumb.MobileBreadCrum.getModelName(MobileBreadCrum.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at javax.el.BeanELResolver.getValue(BeanELResolver.java:62) ... 160 more </code></pre> <p>The JSP Code is :</p> <pre><code>&lt;%@include file="/apps/companyname/components/global.jsp"%&gt;&lt;ct:component className="com.companyname.www.components.content.mobilebreadcrumb.MobileBreadCrum" name="mobilebreadcrum" /&gt;${mobilebreadcrum.modelName} </code></pre> <p>The Java Code is:</p> <pre><code> public String getModelName() { SlingHttpServletRequest slingRequest = this.request.getSlingRequest(); String resourceType = slingRequest.getResource().getResourceType(); String resourceSuperType = slingRequest.getResource().getResourceSuperType(); LOG.info("RESOURCE TYPE:"+resourceType); LOG.info("RESOURCE SUPER TYPE:"+resourceSuperType); Device device = request.getCurrentPage().adaptTo(Device.class); device.getAttributes(); return modelName; } </code></pre> <p>Please let me know if you want anything else</p> <p>Regards, Yash</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload