Can I use jquery.js directly in Struts 2? - java

I already have a simple application, to experiment I am implementing the same in Struts 2. In an old app I've used jQuery, now can I use directly the same jquery.js here or shall I opt for Struts 2 jQuery Plugin?
I tried with jquery.js, I am getting null pointer exception. So I am confused now. Some one tell the difference between two. Both are jQuery only wright?

Try setting loadAtOnce in <sj:header> tag to true to disable on demand script loading. So the jQuery script will be loaded at page load. You should be able to use your own library scripts without manually loading your own copy of jquery.js.
Ref. Here

If you have got NullPointerException, it doesn't mean that JQuery or plugin has bugs. You are getting errors because you are doing something wrong in the code, misunderstanding or something.
Struts 2 JQuery is a tag library that you can use with Struts 2 framework. It contains the JQuery inside it. JQuery is only a JavaScript library. Using the plugin you have Ajax support with Struts 2 framework.

Related

Is there any way to use Thymeleaf in grails instead of GSPs?

I am building an application with react+grails, where grails is the wrapper. However, the react application is based on Create React App, due to this the output template of react is index.html. However, grails don't allow rendering .html files. So, is there anyway to use thymeleaf instead of gsp ?
I have other ways like render text: htmlText, contentType:"text/html", encoding:"UTF-8" but this seems very hacky.
So, is there anyway to use thymeleaf instead of gsp ?
Yes. One way to do that is to use the Spring Boot Thymeleaf support.
However, grails don't allow rendering .html files
That isn't true. We render .html files all the time. You can render any static file from a Grails app, including .html files.
EDIT:
See the project at github.com/jeffbrown/ganeshkhadkahtml.
If you run that app and send a request to http://localhost:8080/showMeSomeHtml that will render the HTML file at src/main/webapp/static/index.html.
You could also send a request to http://localhost:8080/static/index.html to render that same file if you wanted to support that.

Instantiating tag of jsp 2.0 in java code

I am migrating my java web-application project from JSP to thymeleaf.
I want temporarily to have ability to reuse some simple custom JSP tags in thymeleaf pages. It seems not a problem with custom tags defined in old fashion, as java files. I just instantiate tag, set fake PageContext, request and response, attribtes - and call doStartTag / doEndTag.
However I could not find a way how to instantiate object representing JSP 2.0 tag (i.e. defined in a ".tag" file. How can I achieve this?
Thanks in advance for any ideas!
It looks there are two ways:
Use jspc-maven-plugin to get precompiled classes from jsp and tag files - I checked that works - however latest version of this plugin is 2.0-alpha-3 and it is 4 years old now.
Access servlet-container jsp compiler (in most cases jasper) and do the same thing as in first variant, but on demand, in execution time. However, this makes application container-dependent.
(My personal opinion now is that it would better to avoid the idea at whole - all solutions looks too unreliable to use in production)

Can any one help me how to use dojo framework of ajax in my my struts2 application

I want to change the content of a select box when the values in another select box changes.
Please tell me how to use dojo. How to call the struts 2 action & get the result through ajax.
with struts2-core there comes a tag but this does not work with ajax.
The struts2 dojo tag is marked as deprecated so it is better not to use it in a new project.
In the Wiki for the Struts2 jQuery Plugin is a example for an AJAX based Double Select, maybe this is an option for you.

Wicket & jQuery Overlap/Collision

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.

quick fix for JSP with in Eclipse?

I'm running Eclipse 3.4 java enterprise adition and writing JSP pages with it. It does not appear to support quick fix, for example ArrayList ourList; comes up as an error but there isn't a quick fix option to add the import java.util.ArrayList statement. Is there a way to improve quick fix capabilities, or another set of Eclipse Plugins that provides quick fix for jsp?
I tried the Ctrl+spacebar and it automatically added the import for me. Maybe that's good enough?
MyEclipse is something that you could try for improved JSP editing. I think it's only about $30 for a version with the JSP editing.
Apart from this particular problem (which you could solve by using Eclipse for Java EE which has the WTP integrated), this implies that you're writing raw Java code inside a JSP file. This is considered bad practice. JSP is a view technology wherein you ought to control the flow and output using taglibs (e.g. JSTL) and to access the data using EL. Raw Java code actually belongs in a real Java class, like a Servlet, Filter, Javabean, DAO, Utility, etcetera. Keep the JSP clean from scriptlets. If you ever need to do something which isn't doable using taglibs/EL, then the particular code most likely belongs in a Java class.
Creating an ArrayList ought to be done inside a Servlet class, either directly or indirectly (business class). Use the doGet() to preprocess data for display and use the doPost() to postprocess data after submit. Inside the JSP you can iterate over an ArrayList using the JSTL c:forEach tag.
Good luck.

Categories