I have 3 questions:
Each and every action in Vaadin makes a call to the server. is there a way to avoid calls to server for every actions? like having a code at client side for particular actions that is used many times? Like in CSValidation add-on.
I want to know how to add Javascript/JQuery in Vaadin 7. It seems easy in Vaadin 6. But, I couldn't get it working in Vaadin 7. I hope they would have made it more easy now. Can anyone show me some examples regarding this. If it is JQuery, It will help me a lot.
And also will
Javascript.getCurrent().execute("");
'execute the javascript' or 'add specified script' in to the code. Will this help me to solve my 2nd question?
1) Each and every action in Vaadin makes a call to the server. Is there a way to avoid calls to server for every actions? like having a code at client side for particular actions that is used many times? Like in CSValidation add-on.
This depends on the client-side code. Vaadin is built with a server side programming model, but if you need to restrict the amount of server calls, you need to do it yourself. Vaadin 7 made it relatively easier to include third party libraries as it was in Vaadin 6.
2) I want to know how to add Javascript/JQuery in Vaadin 7. It seems easy
in Vaadin 6. But, I couldn't get it working in Vaadin 7. I hope they
would have made it more easy now. Can anyone show me some examples
regarding this. If it is JQuery, It will help me a lot.
Here you have a nice tutorial on how to integrate jQuery with Vaadin 7: http://java.dzone.com/articles/integrating-html-and-0
It basically goes about creating a JavascriptExtension class, this is the main part of the solution:
#JavaScript({ "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" })
public class JavascriptJQueryExtension extends AbstractJavaScriptExtension {
... // Please see the link above for an example of implementation
}
The path can either be an URL or an internal path to the jQuery library.
3) 'execute the javascript' or 'add specified script' in to the code.
The following code snippet will be executed, as stated in the Book of Vaadin 7 (https://vaadin.com/book/vaadin7/-/page/advanced.javascript.html)
// Shorthand
JavaScript.getCurrent().execute("alert('Hello')");
The JavaScript is executed after the server request that is currently
processed returns. (...)
I would suggest for you to take a good look at the Book of Vaadin. It contains a lot of important information that is usually helpful to solve most of the problems that arise when working with Vaadin.
I am not expert of Vaadin Framework...
I can tell you that your Question No.3 is to run JavaScript commands through that..
You can also run jQuery command through that..
But for that you must have jQuery included in the page..
for Question 1: I can say it is possible, as Vaadin have the functionality that overrides function..
JavaScript.getCurrent().addFunction("com.example.foo.myfunc",
new JavaScriptFunction() {
#Override
public void call(JSONArray arguments) throws JSONException {
Notification.show("Received call");
}
});
Link link = new Link("Send Message", new ExternalResource(
"javascript:com.example.foo.myfunc()"));
Now in absence of supporting code, you must identify the actual plugin's function that is making call to server on each action.
Make sure if you override the function.. you will require that functionality at some point.. so do not override the actually required function....
Question 2,
yes the jQuery is available with vaadin, refer forum
it says you can call jQuery directly like this $wnd.JQuery
I hope this will help...
Related
I've been having terrible luck trying to get this to work, so I'm hopeful someone can help here.
In Java, I need to be able to take an HTML page with JavaScript within it and detect any JavaScript errors without, preferably without executing the JavaScript code.
I found this article:
Javascript parser for Java
And I've attempted to figure out how I'm supposed to use Caja to do this, but I'm having a difficult time finding any documentation with working examples of anything close to what I'm doing.
As a result I took a look at Nashorn also referenced in that article. I found a few examples which show how to execute JavaScript code from Java, but this doesn't process the whole HTML page. Even then, the execution doesn't seem to include the ability to validate common JavaScript functions (e.g. It hadn't heard of "alert").
Can anyone recommend something that might be able to do what I want, and point me in the right direction for their documentation or give me an example?
jshint as a standalone product seems to be a good fit for this:
it can run in java inside rhino (see https://github.com/jshint/jshint/)
a nodejs package exists (see https://www.npmjs.com/package/jshint)
it works with nashorn but it's quite tricky
I will only cover the technical difficulties around 3rd solution as I finally managed to make it work too...
Spoiler alert: "alert()" is not detected yet... Solution nb 2 will help there...
You first need to grab this specific release of jshint: https://github.com/jshint/jshint/releases/tag/2.4.4
Anything later than v2.7.0 will fail for now and I personally gave up patching intensively prototypes and namespaces... Releases from v2.4.4 until v2.6.3 work without modification but are limited in functionalities.
In the release notes, it's specifically written that "support for the Nashorn JavaScript engine" is working on this release. I'm using JDK8 nashorn 1.8.0_45 for this test.
Next step is to extract from this release this single file jshint-2.4.4/dist/jshint-rhino.js
Now you need to run nashorn/jjs in scripting mode and you need to be specific about the single file you wish to verify. In solution 2 (nodejs based) you can do multiple files or a complete hierarchy below a folder...
Create a simple file file.js:
function(){}
Now run the following command (please note the presence of -- ):
jjs -scripting jshint-rhino.js -- file.js
This will give you the following output:
Missing name in function declaration. (file.js:1:9)
> function(){}
So this covers the how to run jshint in a simple manner with nashorn... With the 3rd solution, at least you can find missing semicolons and several typical errors. But it's not a silver bullet and to me it's not a real alternative.
My personal preference would be to stick to solution 2 only. If you've the possibility to install either nodejs or iojs on your dev platform, go and grab https://www.npmjs.com/package/jshint. Not only will you be able to do more than the 3rd solution, you'll also be able to configure a jshintrc file as described at http://jshint.com/docs/
We made our own api for airbrake.io in java. This works fine but airbrake is displaying parameters and stacktraces in some kind of Rails style. This is somewhat annoying. Anyone know of similar services made for java?
Example of how data is displayed:
Parameters
{"controller"=>"", "action"=>""}
Stacktrace
/testapp/app/models/user.rb:53:in `public'
/testapp/app/controllers/users_controller.rb:14:in `index'
UPDATE 2015-02-13: This service no longer exists. The GitHub account linked below is gone, as is the company website.
Have you tried using Coalmine https://github.com/coalmine/coalmine_java Its meant to be used with the Coalmine service: https://getcoalmine.com/
I work at Coalmine and we have been using this internally for some time now. We just open sourced the java connector this week and I would be happy to help you get started with it. You can send me an email at brad#builtfromsource.com
Have you tried using http://code.google.com/p/hoptoad/ . It's a little out of date, but it should just need to update an endpoint to http://api.airbrake.io .
A quick google lead me to http://logdigger.com/ which is designed specific for JAVA specific sites.
I work at Airbrake, and I would be happy to work with you to make our site more JAVA friendly. Please get in touch ben#airbrake.io, and I'll see how we can better display java specific information.
Just adding to the others suggested here, but Raygun (http://raygun.io) has first class support for Java.
Read more here: http://raygun.io/java
I work for Mindscape who built Raygun so can answer any questions you may have about it: jd#mindscape.co.nz. We already have a large number of organizations using Raygun with their Java apps, although Raygun does support other platforms (.NET, Node, Rails, PHP, etc)
I'm trying to create a user interface using Google Web Toolkit v2.4. For a variety of reasons, I need to specify the contents of the interface on the server, at run-time. I don't just mean the the buttons need dynamic labels etc, but rather the whole UI needs to be created at run-time.
Much of my UI can be specified as straight-forward HTML. But I also want widgets like Scrollpane. Of course I need to somehow attach actions to things like buttons.
I tried creating the UI server-side by creating instances of com.google.gwt.user.client.ui.Button, and returning them to the client via RPC call. However the Button class is not serializable. (Also the package name is telling me this is an object which should live on the client only.)
I considered generating a UiBinder template on the fly. However it seems UI binder templates need to be compiled.
I'm now looking at sending HTML to the client with placeholder XML elements where the GWT widgets should go. On the client, I would use DOM methods to find and replace them with GWT widgets. But it feels I've gone far astray, at this point.
It feels like there should be a straight-forward way to do this, but it is eluding me.
Suggestions?
GWT has no built-in support for stuff like this (since it is totally missing the point of gwt).
So you have two choices,
build your own framework, so you will be able to send from server to client some layout page data, client will parse it and will create ui
or
you can use some other framework, for example Vaadin which basically does what you want, or a combination of some JavaScript UI Framework + Node.js where you can easily share the code between client and server.
You should look at Vaadin. Server-side control generating client side GWT.
I think you are looking for XForms. There are several implementations of XForms (http://www.w3.org/MarkUp/Forms/wiki/XForms_Implementations) and some of them work on the server side and some of them work in browser. Some of the second type may work as a browser plugin, flash or java script, but my favouite is EMC Formula XForms Engine (https://community.emc.com/docs/DOC-4345) that was developed to work with GWT.
If you need some example, here it is: http://svn.yuppy.pl/projects/trunk/sample-gwt-xforms/.
You can refer link http://code.google.com/p/acris/wiki/DynamicUiBinder for dynamicUiBinder
I am starting using Liferay Portal and I have two basic needs which I would like to achieve with Liferay.
Is there a posibility to add content to CMS through API level? I would like to insert some data "from code".
More important. How to achieve such situation that for every created user there will be its own homepage generated with some predefined template elements on it?
I have tried to Google something so far, but I did not find it helpful. Maybe some keywords?
After some analysis of documentation devoted to services and ServiceBuilder I realized that it is not what I want.
Let me show an example based on Websphere.
In Websphere we have bunch of EJB components available to perform some actions, exchange information with portal, easy to use. Isn't there any similar mechanism in Liferay not involving web services?
My recommendation for this kind of question is to take a look at the sevencogs-hook sourcecode. The structure of this hook is basically just a long script that runs once, setting up a complete demo site with users, sites, pages, content etc. The code runs once (after the first deployment) and then never again. There are no (obvious) conditionals, no context to understand etc.
You can basically just step through everything and - in that process - understand how content (and pages, images, blog posts, etc.) are created and positioned on pages in Liferay.
This hook accesses the Java API, a very similar API is available through Webservices. Basically all of Liferay's portlets also use the same API to do their business.
Edit: Additional information to keep this answer valuable/current: Sevencogs is discontinued, but still available in old releases (source & binary). The API has slightly changed, so compiling/running it will need a bit of work. James Falkner has blogged about the leftovers and lessons learnt - those snippets are extracted from sevencogs and contain the relevant code pieces to work with the API.
Looking at this page from the documentation: It smells like a SOAP interface (they mention some sort of document uploader service and I've read axis).
You'll find some url examples that should give a list of available webservices.
For number 1, you can use the one of the:
JournalArticleLocalServiceUtil.addArticle()
methods to programmatically add Liferay Web Content from a portlet. If you download the Liferay Portal Source you can see the structure of these methods.
For number 2, can create page templates with preconfigured portlets on them (through the Plugins-SDK), and then use the API to programmatically create the pages using one of the:
LayoutLocalServiceUtil.addLayout()
methods.
If you have any more speific questions about these comment back, and I hope this helps!
I am currently working on a web app using Wicket and started using jQuery core (UI also) in it today. I ran into an issue I troubleshooted as a jQuery function (show(), slideDown()) colliding with some of the javascript Wicket auto-generated for an external form link.
Before I get deeper into this project I am wondering if anyone has had similar experiences. Are there a lot of places where the jQuery effects/actions collide with Wicket generated javascript/HTML? Are there clean ways to avoid this, or mitigate it?
I have seen Wicketext as possibly a cleaner "integrator" of the two, but mostly it seems to just be a way of doing more of the jQuery-ish code in the Java instead of JS.
This is an interesting problem since jQuery occupies it's own namespace. I'm guessing that there is a conflict with the $ jQuery variable. To get around this you can have jQuery occupy a different namespace like so:
var $j = jQuery.noConflict();
You can do this after you've loaded both sets of code and the $ will be returned to its original value. A bit of a headache but it can fix things in a pinch. See using jQuery with other libraries for more info.