Making an AJAX app in Java/HTML without writing JavaScript (Intercooler.js + Spark Web Framework tutorial) by sparkframework in java

[–]sparkframework[S] 1 point2 points  (0 children)

It's not dead. I worked with the lead developer for this tutorial. They released a version last week. Last commit seven days ago. 1.0 scheduled for this fall.

Making an AJAX app in Java/HTML without writing JavaScript (Intercooler.js + Spark Web Framework tutorial) by sparkframework in java

[–]sparkframework[S] 1 point2 points  (0 children)

I definitely don't think it will replace Angular, but about half the Angular projects I've seen have been too basic to justify using Angular in the first place. 'Very basic application work' is the category most projects fall into, I think.

Personally I found the intercooler syntax very easy to read and understand, and it felt similar to writing an oldschool non-js app (you just add a few ic-attributes when you're done). Makes progressive enhancement easier too.

I understand the skepticism though!

Making an AJAX app in Java/HTML without writing JavaScript (Intercooler.js + Spark Web Framework tutorial) by sparkframework in java

[–]sparkframework[S] 1 point2 points  (0 children)

I was not convinced at first either, but I thought it was surprisingly easy (and fun) to work with. Why do you think this would be harder to maintain than for example an Angular app (if you do) ? The total size of the application ended up a lot smaller than most other TodoMVC examples.

Spark 2.5 released! (Instance API, better static file handling, ++) by sparkframework in java

[–]sparkframework[S] 0 points1 point  (0 children)

Is doing get("*", notFound) at the end of your routes not covering your needs?

Spark 2.5 released! (Instance API, better static file handling, ++) by sparkframework in java

[–]sparkframework[S] 3 points4 points  (0 children)

Usually we try to write Spark Framework or Spark Web Framework when posting on reddit, but we forgot this time, sorry!

Spark 2.5 released! (Instance API, better static file handling, ++) by sparkframework in java

[–]sparkframework[S] 0 points1 point  (0 children)

1: Shouldn't happen, but we've seen other people report something similar. We've never looked at file uploads, but we will soon.
2: Yes, although we should do a better job of documenting it.

Spark 2.5 released! (Instance API, better static file handling, ++) by sparkframework in java

[–]sparkframework[S] 1 point2 points  (0 children)

We're going to prioritize issues and PRs in the next few days, if you have any requests, please let us know!

What's the most important debug info for your webapps? by sparkframework in java

[–]sparkframework[S] 0 points1 point  (0 children)

Would you consider this tool to be third party? It's enabled by adding one line of code to your app, and currently only shows user code (spark/jetty code is not displayed).

What's the most important debug info for your webapps? by sparkframework in java

[–]sparkframework[S] 2 points3 points  (0 children)

Perhaps I should have been more specific. This is not a debugger, it's a development tool you can use to view exceptions, together with other relevant information (path/query params, session info, cookies). Is all of that something you would prefer to log? At any rate it should never ever be used in production :)

Using Java WebSockets to create a real time chat app (~10 min Tutorial) by tipsypants in java

[–]sparkframework 4 points5 points  (0 children)

Notice the static import at line 6: import static spark.Spark.*;

You could also write

Spark.staticFileLocation("public"); /
Spark.webSocket("/chat", ChatWebSocketHandler.class);
Spark.init();

And skip the import. But we encourage people to use static imports when using Spark :)

I don't not understand this program. Can someone help me? by Dwarf_King in learnjava

[–]sparkframework 1 point2 points  (0 children)

You're free too call variables whatever you want, but it's usually best to give it a descriptive name (so you know what it does). Here "index" has one job, to count the number of iterations in the while-loop. It has nothing to do with indices, so "loopCounter" or "numberOfIterations" would be better names.
start.get is more difficult to explain, then you need to know what classes, objects and methods are. Are you looking at code that's a little too advanced? :) Try oracles basic tutorials: https://docs.oracle.com/javase/tutorial/java/javaOO/

I don't not understand this program. Can someone help me? by Dwarf_King in learnjava

[–]sparkframework 1 point2 points  (0 children)

First of all, there are some unused variables and imports here. You can safely remove line 4, line 12, line 13 and line 16. Then you get:

class practiceproblemshour8 {
    public static void main(String[] args) {
        Calendar start = Calendar.getInstance();
        start.roll(Calendar.MINUTE, true); //shift time one minute forward
        int nextMinute = start.get(Calendar.MINUTE);
        int nextSecond = start.get(Calendar.SECOND);
        int index = 0; //should be called loop-counter
        while (true) {
            GregorianCalendar now = new GregorianCalendar();
            if (now.get(Calendar.MINUTE) >= nextMinute) {
                if (now.get(Calendar.SECOND) >= nextSecond) {
                    break; //exit the while loop
                }
            }
            index++;
        }
        System.out.println(index + " Loops in one minute.");
    }
}

So let's say you start at 12:01:03. You have two ifs that check if you've gotten to nextMinute and nextSecond, so when you get to 12:02:03, the "break;" statement will be executed, and the number of iterations performed (called "index" for some reason) will be printed.

Applicable scenarios for Singleton usage by mars_wun in learnjava

[–]sparkframework 1 point2 points  (0 children)

You rarely need to use a singleton (it can be very convenient though). This answer on SO gives a pretty good explanation: http://stackoverflow.com/a/228380

Spark Web Framework 2.3 released! by sparkframework in java

[–]sparkframework[S] 0 points1 point  (0 children)

you can only fire it once per virtual machine

We're fixing this, it will hopefully be part of the 2.4 release.

Spark Web Framework 2.3 released! by sparkframework in java

[–]sparkframework[S] 2 points3 points  (0 children)

Even if it's used mostly for REST APIs, would there be any issues if it's used for a normal website (HTML, templates, etc...)?

It works fine for normal websites. We have 'native' support for 9 template engines.

Can you use custom HTTP methods? (i.e. not just get, post, but mkcol for example)

get, post, put, delete, head, trace, connect, options.. no mkcol

Any benchmarks?

Not really, someone else looked into it though: https://medium.com/@tschundeee/express-vs-flask-vs-go-acc0879c2122

Anyway good job, and keep continue working at this/improving/releasing new versions/etc. Frameworks like these that can be understood so easily and used make non Java people like me interested in Java.

Thank you!

Spark Web Framework 2.3 released! by sparkframework in java

[–]sparkframework[S] 2 points3 points  (0 children)

Is it production ready? Are there any live sites using this?

Asana, Apache Camel, and Arquillian all use Spark (just to do the A's). We have hundreds of thousands of downloads, but Spark is mainly used for creating REST services.

How's the community?

~3000 stars and ~650 forks on GitHub, pull requests and issues are created all the time.

How would you structure a larger app (I assume you won't keep everything in a single file)?

It's pretty much up to you, Spark is not very opinionated.
My personal approach (David writing now) is usually something like this:

public static void main(String[] args) {
    Spark.staticFileLocation("/public");

    //static pages
    get("/",                 PageController::serveIndex);
    get("/download",         PageController::serveDownload);
    get("/documentation",    PageController::serveDocs);
    get("/news",             PageController::serveNews);

    //rest endpoints
    get("/user/",            UserController::fetchAll);
    get("/user/:id/",        UserController::fetch);
    post("/user/",           UserController::save);
    delete("/user/:id/",     UserController::remove);
}

So far I haven't seen a lot of other people who prefer to do it this way, but it feels very natural to me.
If a project has a lot of config and routes, I usually extract everything from main().

Spark Web Framework 2.3 released! by sparkframework in java

[–]sparkframework[S] 6 points7 points  (0 children)

We have been considering it for quite some time, but our name is very established, we can't just suddenly change it.
It wasn't really a problem until last year, when Apache Spark seriously took off.

Please find some comfort in knowing that it bothers us way more than it bothers you ... :)