Liferay 7 - Get Assets Comments from ADT - java

I'm trying to get the comments of an entry in an ADT.
I tried this:
<#assign MBMessageLocalServiceUtil = serviceLocator.findService("com.liferay.message.boards.kernel.service.MBMessageLocalServiceUtil")>
<#getCommentCount resourcePrimKey=article.getResourcePrimKey()/>
<#macro getCommentsCount resourcePrimKey>
<#assign Messages = MBMessageLocalServiceUtil.getMessages("com.liferay.portlet.journal.model.JournalArticle", resourcePrimKey, 0) />
<#assign MessagesCount = Messages?size-1 />
<#if MessagesCount != 0>
(Comments: ${MessagesCount} )
</#if>
</#macro>
It throws me this error then:
The following has evaluated to null or missing:
==> serviceLocator.findService("com.liferay.message.boards.kernel.service.MBMessageLocalServiceUtil") [in template "20116#20160#38923" at line 35, column 54]
I really have no Idea what I am doing wrong.
I've already used the serviceLocator on this portal and it works. Freemarker restricted Variables and Classes are removed.
Does anyone has an Idea for a Soloution ?

You can use the /comment.commentmanagerjsonws/get-comments action from the liferay jsonws api to access the entry comments. This api is accessible per Javascript / curl / URL, it should do the trick.

In Liferay 7 the configuration was moved from portal.properties to the new OSGi configuration. See this thread for details.

Related

Getting error .. Unable to parse EL function ${class} [duplicate]

Currenty I have a web project with JSF 1.2 and Facelets running in tomcat 6.0.18.0. I decided to upgrade the servlet container, thus i deployed in tomcat 7 and all seemed ok until we hit one view using my custome facelet functions.
javax.el.ELException: Failed to parse the expression [{pz:instanceof(object,'com.project.domain.MyClass')}]
Caused by: org.apache.el.parser.ParseException: Encountered " ":" ": "" at line 1, column 5. Was expecting one of:
"}" ...
"." ...
"[" ...
This error occurs when parsing the following code:
<ui:repeat var="object" value="#{objects}">
<ui:fragment rendered="#{pz:instanceof(object,'com.project.domain.MyClass')}">
...
If i understand correctly it throws an error because of the colon in the expression . I have tracked it down to the jasper-el that come with in the tomcat/lib directory, and if I replace jasper.jar and jasper-el.jar with the ones from tomcat 6.0.18 everythign works well.
Has anyone else had this problem before upgrading their tomcat? And How did they resolve it?
Could I deploy in production tomcat 7 with these jasper jar from tomcat 6, or could this cause further problems.
This is actually a misleading exception. It has a different underlying cause. The function name instanceof is invalid.
The EL 2.2 specification says the following:
1.14 Reserved Words
The following words are reserved for the language and must not be used as
identifiers.
and eq gt true instanceof
or ne le false empty
not lt ge null div mod
Note that many of these words are not in the language now, but they may be in the
future, so developers must avoid using these words.
and
1.19 Collected Syntax
...
Identifier ::= Java language identifier
...
Where the Java language identifier stands for keywords like instanceof, if, while, class, return, static, new, etc. They may not be used as variable/function names in EL. In case you have properties with those names, use the brace notation instead like so #{bean['class'].simpleName} instead of #{bean.class.simpleName}.
This was been fixed in Tomcat 7.0.4 or somewhere near before this version as indicated by issue 50147 wherein someone else pointed out the same problem as you have. So, to solve your problem, you have to rename your EL function name to for example isInstanceOf or something.
Add this line in catalina.properties ([tomcat folder]/conf), and it should fix the issue.
org.apache.el.parser.SKIP_IDENTIFIER_CHECK=true
However, you should not use the reserved words.
You can also try changing the syntax. I had the same exact problem with code that I was maintaining when we were moving from Tomcat 6 to 7. I had to change myobject.class.name to myobject['class'].name. After I made this change my code worked perfectly again.
Great hint, indeed! I had to change in my jspx ${instance.class.simpleName == ...} with ${instance['class'].simpleName eq ...}.
I was moving from vFabric on tomcat 6 to vFabric on tomcat 7

Javascript native method throws unexpectedly exception

I am updating a vaadin project from vaadin 6 version to vaadin 7. It contains some native Javascript methods which work well in the old version. However some of them throw an exception when they should be called. I am not acquainted enough to Javascript programming and therefore I am not able to identify the source of the error. In particular the method is:
protected static native void addSthToImg()
/*-{
$wnd.$(document).ready(function() {
var = $wnd.$;
var('.settingswrapper > img').addClass("imgStartup");
if (var('.settingswrapper > img').hasClass("imgStartup")) {
console.log("imgStartup exist");
var('.settingswrapper > img')
.animate(null, 300, function() {
var('.settingswrapper > img').removeClass("imgStartup");
var('.settingswrapper > img').addClass("imagePopIn");
});
}
});
}-*/;
On the Console in Chrome I see the error stack trace:
Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError) : Object [object global] has no method '$'
What could be a possible cause of the error and why is it working in the old version? Is a jar/library missing?
Seems like jQuery alias $ is not defined in the global scope (denoted by $wnd). Are you sure your page includes jQuery?
You should have something like <script src="/js/jquery.js" type="text/javascript"></script> (but pointing to the actual location of jquery.js in your project) in your HTML source. I don't know if Vaadin manages JavaScript libraries automatically, since I'm not familiar with the framework.

Route to upload file in Play Framework 2.10

I upload files to /upload folder, then I want to directly access my files, like:
http://localhost/upload/xxx.jpg
when I add routes as below:
GET /upload/*file controllers.Assets.at(path="/upload", file)
It causes another error:
not enough arguments for method at: (path: String, file: String)play.api.mvc.Call. Unspecified value parameter file.
<link rel="stylesheet" media="screen" href="#routes.Assets.at("stylesheets/main.css")">
Then, after I change #routes.Assets.at("stylesheets/main.css") to #routes.Assets.at("stylesheets/", "main.css"), there is another error:
[MatchError: (stylesheets/,main.css) (of class scala.Tuple2)]
(path: #unchecked, file: #unchecked) match {
Can somebody help me with this route? Thanks.
finnal, I got answer from playframework website, it not very obvious to find..
http://www.playframework.com/documentation/2.0.4/Assets
from this page:
However, if you define two mappings for the Assets.at action, like this:
GET /javascripts/*file controllers.Assets.at(path="/public/javascripts", file)
GET /images/*file controllers.Assets.at(path="/public/images", file)
Then you will need to specify both parameters when using the reverse router:
<script src="#routes.Assets.at("/public/javascripts", "jquery.js")"></script>
<image src="#routes.Assets.at("/public/images", "logo.png")">
but this may not solve my problem yet, it turn out to appear the second error mention in the question.
Be Careful, check the path param, it must be the same as you described in routes file. as:
when I set:
GET /public/*file controllers.Assets.at(path="/public", file)
in the html file, I should write as below:
#routes.Assets.at("/public", "stylesheets/main.css")
besides, if you use another folders, like /upload, adding below code in project/Build.scala in play.Project is essential. thanks TizianoPiccardi
playAssetsDirectories <+= baseDirectory / "foo"
You should add this line in project/Build.scala:
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
playAssetsDirectories <+= baseDirectory / "upload"
)
More info:
https://github.com/playframework/Play20/wiki/Assets

Changing value of a variable in the file to be imported; Freemarker

File testMacro.txt
<#import "./importMe.txt" as my>
<#assign a=0 >
<#my.macro1 />
${a}
File importMe.txt
<#macro macro1 >
${a}
</#macro>
Now from java file, when I execute it it says.
Exception in thread "main" java.lang.RuntimeException: freemarker.core.InvalidReferenceException: Expression a is undefined on line 3, column 3 in importMe.txt at msjava.hdom.examples.DbQuery.main(DbQuery.java:59)
Caused by: freemarker.core.InvalidReferenceException: Expression a is undefined on line 3, column 3 in importMe.txt
But if I dont do the import but instead define the macro inside the file testMacro.txt then it works fine.
What I want to do is that I want to change the value a in the file testMacro.txt , within the file importMe.txt, such that it gets reflected later in the testMacro.txt.
Thanks.
An important point of #import is exactly that it prevents interferences among the templates by giving them their own namespaces. So that's why it doesn't work. If you want the templates to share that variable, use a global variable: <#global a = 0> instead of #assign. Or, you can set the variable in the imported namespace like <#assign a = 0 in my>.

Java cfObject with method names that are CF reserved words

I've been working on a Braintree integration in ColdFusion. Braintree does not directly support CF, but they provide a Java library and everything I've done so far has worked really well... until now. It appears that some of the objects (particularly the search functionality) have methods that are not accessible from CF and I suspect it's because they are CF reserved words, such as "is" and "contains". Is there any way to get around this?
<cfscript>
gate = createObject( "java", "com.braintreegateway.BraintreeGateway" ).init(env,merchant.getMerchantAccountId(), merchant.getMerchantAccountPublicSecret(),merchant.getMerchantAccountPrivateSecret());
req = createObject( "java","com.braintreegateway.CustomerSearchRequest").id().is("#user.getUserId()#");
customer = gate.customer().search(req);
</cfscript>
The error thrown: Invalid CFML construct ... ColdFusion was looking at the following text: is
This represents a bug in the CF compiler. There is no rule in CF that one cannot define a method called either is() or this(), and indeed in basic situations there's no problem with calling them either. This code demonstrates:
<!--- Junk.cfc --->
<cfcomponent>
<cffunction name="is">
<cfreturn true>
</cffunction>
<cffunction name="contains">
<cfreturn true>
</cffunction>
</cfcomponent>
<!--- test.cfm --->
<cfset o = new Junk()>
<cfoutput>
#o.is()#<br />
#o.contains()#<br />
</cfoutput>
This - predictably - outputs:
true
true
However we have problems if we introduce a init() method to Junk.cfc, thus:
<cffunction name="init">
<cfreturn this>
</cffunction>
And then adjust test.cfm accordingly:
#o.init().is()#<br />
#o.init().contains()#<br />
This causes a compiler error:
Invalid CFML construct found on line 4 at column 19.
ColdFusion was looking at the following text:
is
[...]
coldfusion.compiler.ParseException: Invalid CFML construct found on line 4 at column 19.
at coldfusion.compiler.cfml40.generateParseException(cfml40.java:12135)
[etc]
There is no valid reason why o.init().is() should not be OK if o.is() is fine.
I recommend you file a bug. I'll vote for it.
As a workaround you should be fine if you use intermediary values, rather than method chaining.
You can probably use the Java Reflection API to invoke the is() method on your object.
I'd also raise a call with Adobe to see if they'll fix it or provide their own workaround. I can understand disallowing defining your own method or variable called 'is', but attempting to invoke it here should be safe.
Here is a solution to this problem. At least a fix to get you up and running.
Try this code.
<cfscript>
//Get our credentials here, this is a custom private function I have, so your mileage may vary
credentials = getCredentials();
//Supply the credentials for the gateway
gateway = createObject("java", "com.braintreegateway.BraintreeGateway" ).init(credentials.type, credentials.merchantId, credentials.publicKey, credentials.privateKey);
//Setup the customer search object
customerSearch = createObject("java", "com.braintreegateway.CustomerSearchRequest").id();
//can't chain the methods here for the contains, since it's a reserved word in cf. lame.
customerSearchRequest = customerSearch.contains(arguments.customerId);
//Build the result here
result = gateway.customer().search(customerSearchRequest);
</cfscript>

Categories

Resources