Getting error while using adaptTo method of Sling while using Sling Models - aem

We are trying a sample sling model implementation in AEM 6.0.
The sling model class without the imports is like this :
#Model(adaptables = Resource.class)
public class Header {
#Inject
private String link;
#Inject
private String text;
public String getLink() {
return link;
}
public String getText() {
return text;
}
}
The sling model is being called in the jsp using the following lines of code
<sling:adaptTo adaptable="${resource}" adaptTo="com.mysite.models.Header" var="model"/>
<h2>${model.link}</h2>
<h2>${model.text}</h2>
However we are getting the following error :
No tag "adaptTo" defined in tag library imported with prefix "sling"
We have imported the taglib using following statement:
<%#taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling" %>
Initially, the 2.2.0 version of Apache Sling JSP Tag Library bundle was present. We also tried uploading the 2.2.4 version, but it didn't help.
Can somebody please guide if anything else is required for adaptTo tag to be available?

Stumbled across this while trying to help a coworker debug a similar issue. At first I was able to replicate this behavior (AEM 6.1) by copying the segment from the Doc page:
<sling:adaptTo adaptable="${resource}" adaptTo="org.apache.sling.api.resource.ValueMap" var="myProps" />
What I found on my local was that our custom global.jsp file reference the old, pre-Granite version at /libs/foundation/global.jsp. Within that file I saw it had <%#taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>. As a quick test I deleted the /1.0 at the end and refreshed the page and BAM, it worked.

Related

Error using Mads Kristensen's WebEssentials.AspNetCore.PWA with Razor

I am trying to convert a website to a PWA (Progressive Web App) using Mads Kristensen's WebEssentials.AspNetCore.PWA. When looking at the generated code with Chrome F12 Dev tools, the service worker and the web manifest are not found because the paths in the _Layout have an extra ~/ in them (an extra tilde & and extra slash).
I am developing using localhost and .NETCore 2.1. Is this particular package not compatible with localhost or .NET Core 2.1 or Razor? I'm really stuck and would appreciate some help. If I type the generated paths into the URL box manually I get 404s. If I type them in without the extra ~/ if they are found.
I have determined 2 issues.
The WebEssentials.AspNetCore.PWA package injects 2 lines into _Layout.cshtml. The first line, in the head, should be <link rel="manifest" href="/manifest.webmanifest">. Instead, in my configuration (localhost, Windows 10, Visual Studio 2017, ASP.NET Core 2.1, Razor Pages) it generates <link rel="manifest" href="~/manifest.webmanifest">. See the extra ~ . This causes chrome to fail to locate the manifest.webmanifest.
The second line it injects, in html region, should be script nws-csp-add-nonce='true'>'serviceWorker' in navigator and navigator.serviceWorker.register('/serviceworker'). Instead it is injecting script nws-csp-add-nonce='true' 'serviceWorker' in navigator and navigator.serviceWorker.register('~/serviceworker'). Again, see the tilde. My question is what do I need to do to make it generate the code correctly? Is it because I am using .NET Core 2.1 instead of .NET Core 2.0 or is there something else I need to change? Thanks.
https://github.com/madskristensen/WebEssentials.AspNetCore.ServiceWorker/issues/36
appareantly ther is a bug, reverting back to 1.0.33, solved the problem.
Looks like you might be able to fix it yourself if you're so inclined. I'm not sure what the intention of the change was, the commit said "added support when hosted in a virtual directory" but it just added those tilde's to the constants.
File: src/Constants.cs
internal class Constants
{
public const string ServiceworkerRoute = "~/serviceworker";
public const string Offlineroute = "~/offline.html";
public const string DefaultCacheId = "v1.0";
public const string WebManifestRoute = "/manifest.webmanifest";
public const string WebManifestFileName = "manifest.json";
}
Change To:
internal class Constants
{
public const string ServiceworkerRoute = "/serviceworker";
public const string Offlineroute = "/offline.html";
public const string DefaultCacheId = "v1.0";
public const string WebManifestRoute = "/manifest.webmanifest";
public const string WebManifestFileName = "manifest.json";
}

How to add a favicon as a package resource to the header section in Wicket 8?

The way how resources should be added to the header section in Wicket 8 is described in the Reference Guide in the chapter Adding resources to page header section.
In my application, I'm adding the CSS and JavaScript as package resources in following way:
public class BasePage extends WebPage {
#Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
ResourceReference regisCssRef =
new PackageResourceReference(getClass(), "static/css/regis.css");
response.render(CssHeaderItem.forReference(regisCssRef));
ResourceReference jqueryJSRef =
new PackageResourceReference(getClass(), "static/js/jquery.min.js");
response.render(JavaScriptHeaderItem.forReference(jqueryJSRef));
}
}
My question is: how to add a favicon.ico resource in the similar way? So, as a resource created with usage of the PackageResourceReference class.
There is a MetaDataHeaderItem class for purpose of <meta> and <link> elements. Unfortunately, it doesn't support package resources and in fact, any ResourceReference - it misses the method forReference().
I was able to solve my problem with following code, but not sure that's a nice solution:
ResourceReference faviconRef =
new PackageResourceReference(
getClass(), "static/images/favicon.ico");
response.render(
MetaDataHeaderItem.forLinkTag("shortcut icon",
urlFor(faviconRef, null).toString()));
You could use the MetaDataHeaderItem class:
response.render(MetaDataHeaderItem.forLinkTag("icon", "static/fav.ico"));

Malformed schema version 1,000

I have a problem whereby the generator is producing a malformed schema version. Does anyone know why this is the case?
public class MyDaoGenerator {
public static void main(String[] args) throws Exception {
Schema schema = new Schema(1000, "com.mydomain");
...
}
}
OUTPUT
public class MyDaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 1,000;
...
}
The fix will be available today in maven central. Update your greenDAO generator version to 1.3.1.
Probably this is a error coming from freemarker that occurs in greendao-generator <= 1.3.0.
Freemarker is used by greendao-generator to generate the *.java-files. If not configured freemarker uses a locale-sensitive output (for numbers).
See the Freemarker Manual
If you want to use greendao with schema-version > 999 you probably have to add this line in greendao-generator-project rebuild it and use the modified greendao-generator.jar. This causes all numbers used in the templates to be without grouping signs.
File DaoGenerator.java (line 63):
config.setNumberFormat("#*");
Another way would be to manually edit the schema version in your generated file. But you would have to repeat this everytime you regenerate your code.

Property not found on type org.javassist.tmp.java.lang.Object_$$_javassist_seam_2

I am trying to create a with a list to choose from.
I am using JBoss 5.1 and Seam 2.2.
My list should be dynamically populated from my DB, but for the moment I am trying to create a simple list. Which is not working!!
My html:
<h:selectOneMenu>
<f:selectItems value="#{browseQuarters.qList}"></f:selectItems>
</h:selectOneMenu>
The bean has a "qList" member:
#In(required=false)
private List<SelectItem> qList = new ArrayList<SelectItem>();
Which has getters and setters:
public List<SelectItem> getqList(){
qList.add(new SelectItem(1,"one"));
return qList;
}
public void setqList(List<SelectItem> qList) {
this.qList = qList;
}
However, when I try running the page, I get this exception:
Property not found on type org.javassist.tmp.java.lang.Object_$$_javassist_seam_2
My project is generated using Jboss Tools, and I saw the other pages generated from the DB (to generate the entities) have a page.xml with the parameters defined..When creating this new form with New -> Seam form I only got a xhtml page and corresponding bean.
What's going wrong? I am of course a Seam/Java EE newbie, but have to do this ASAP :(
I think Seam/JSF will look for a method called getQList rather than the method you have, getqList. Try changing the names of the getter & setter.
Tip: Eclipse can generate compliant getters & setters for you.

Eclipse RCP: How to access internal classes of plugins?

I want to use the default XML editor (org.eclipse.wst.xml.ui) of Eclipse in an RCP application. I need to read the DOM of the xml file currently open. The plugin doesn't offer any extension point, so I'm trying to access the internal classes. I am aware that the I should not access the internal classes, but I don't have another option.
My approach is to create a fragment and an extension point to be able to read data from the plugin. I'm trying not to recompile the plugin, that's why I thought that a fragment was necessary. I just want to load it and extract the data at runtime.
So, my question is: is there another way to access the classes of a plugin? if yes, how?
Any tutorial, doc page or useful link for any of the methods is welcome.
Since nobody answered my question and I found the answer after long searches, I will post the answer for others to use if they bump into this problem.
To access a plugin at runtime you must create and extension point and an extension attached to it into the plugin that you are trying to access.
Adding classes to a plugin using a fragment is not recommended if you want to access those classes from outside of the plugin.
So, the best solution for this is to get the plugin source from the CVS Repository and make the modifications directly into the source of the plugin. Add extension points, extensions and the code for functionality.
Tutorials:
Getting the plugin from the CVS Repository:
http://www.eclipse.org/webtools/community/tutorials/DevelopingWTP/DevelopingWTP.html
Creating extensions and extension points and accessing them:
http://www.vogella.de/articles/EclipseExtensionPoint/article.html
http://www.eclipsezone.com/eclipse/forums/t97608.rhtml
I ended up extending XMLMultiPageEditorPart like this:
public class MultiPageEditor extends XMLMultiPageEditorPart implements
IResourceChangeListener {
#Override
public void resourceChanged(IResourceChangeEvent event) {
// TODO Auto-generated method stub
setActivePage(3);
}
public Document getDOM() {
int activePageIndex = getActivePage();
setActivePage(1);
StructuredTextEditor fTextEditor = (StructuredTextEditor) getSelectedPage();
IDocument document = fTextEditor.getDocumentProvider().getDocument(
fTextEditor.getEditorInput());
IStructuredModel model = StructuredModelManager.getModelManager()
.getExistingModelForRead(document);
Document modelDocument = null;
try {
if (model instanceof IDOMModel) {
// cast the structured model to a DOM Model
modelDocument = (Document) (((IDOMModel) model).getDocument());
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
setActivePage(activePageIndex);
return modelDocument;
}
}
This is not a clean implementation, but it gets the job done.