I am using Tomahawk's fileupload component <t:inputfileupload> for uploading files. I've set enctype of form as
enctype="multipart/form-data"
and I used <h:commandButton> to submit the form.
But the UploadedFile property in the bean is null. What am I doing wrong and how can I fix it?
Ensure that you've configured the ExtensionsFilter as per their documentation. It's the one responsible for processing multipart/form-data requests and setting the appropriate parts as bean properties.
See also:
Uploading files with JSF
Ensure that you are not using nested forms. Because upload component dont run in nested forms.
It will throw null pointer exception.
I got this issue when I had started on the basis of faces extensions -> the stuff where you put
<%# taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
and use myfaces-extensions-1.0.9.jar.
There is a tutorial on that approach at onjava.com but the tutorial is from year 2005 and does not work with the current jsf1.2 versions. Being fighting with that very old solution tutorial found with google I realized it's worth of checking always that you're using uptodate tutorials also not just uptodate jar-versions.
I wanted to give this solution to those who also have started this thing from upside down.
Related
I have a new project and it's my first time using spring MVC and Thymeleaf.
The error message that I'm getting seems obvious:
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers
I have googled a lot and saw many people with similar issues. However, none of the solutions helped me find out why my setup does not work.
Instead of classpath:/templates I have also tried variations like templates and /templates
some questions:
What is the "basedir" from which the relative path is being looked for?
Is it possible to run spring in debug to see how these kind of configurations are set? i.e. call when I call localhost:8080 and there's a breakpoint somewhere: would it be possible to see how the file index.html is being looked for?
edit On line 23 in the document on the right (BetterCommuteApplication.java) you can see that Intellij is able to resolve the reference to my template file.
This screenshot shows my configuration and I think it should suffice as enough information to get the answer.
Thank you for your time! :-)
ugh, I tried to combine Spring boot with thymeleaf manually here.
(I'm used to developing back-ends ^^")
This doesn't make much sense as initialising spring MVC does this right out of the box.
The solution was to init this as springMVC, use #Controller instead of #Restcontroller because I want the class to be handled as MVC class... and the return could be as simple as return 'index' (because my html file in the default location is called index.html)
basically I would have known, if I'd simply followed the tutorial on SpringMVC... but hey, why would anyone RTFM? :-)
so it looks like this:
As the title states, I'm having issues rendering static values via EL 3 in JSF.
There's a similar issue like mine but it's in JSP and there was a workaround (see this Access static property or method in JSP via EL 3.0 (JEE7; Tomcat 8) )
The issue is nothing is being rendered when I use something as simple as this in any of my .xhtml files
#{Boolean.TRUE}
Although this site https://java.net/projects/el-spec/pages/StaticField says the following would work.
#{T(java.lang.Boolean).TRUE}
It also failed with an error similar to
javax.el.ELException: Function 'T' not found
I've gone ahead and tried the workaround that was mentioned in Access static property or method in JSP via EL 3.0 (JEE7; Tomcat 8). The workaround, which worked for JSP guys, is to replace the jsp-api.jar with javax.servlet.jsp-api-2.3.2-b01.jar in their Tomcat lib.
This DIDN'T work for me either :(
What does work for me is the standalone implementation, like so
ELProcessor elp = new ELProcessor();
Object ret = elp.eval("Boolean.FALSE");
getLog().info("Output Value: " + ret);
And I do get the correct output like so
2015-10-07 17:38:13 INFO WelcomeAction:38 - Output Value: false
I've tried with both true and false value and they worked fine. Not sure if this info will help, but I'm using spring 4.1.1 with webflow 2.4.1. I've also tried on two different tomcat instances 8.0.14 and 8.0.27 and neither worked.
There's no way that I'm the only one dealing with this. I have yet to find a bug report regarding this, although one was reported and solved for JSP https://java.net/jira/browse/GLASSFISH-20778
Would really appreciate some help right about meow. Thanks in advance. Aloha!
The issue is nothing is being rendered when I use something as simple as this in any of my .xhtml files
#{Boolean.TRUE}
Unfortunately, that works in JSP only via ${Boolean.TRUE}, not in Facelets.
Although this site https://java.net/projects/el-spec/pages/StaticField says the following would work.
#{T(java.lang.Boolean).TRUE}
That site contains only proposals/prototypes. The final implementation is indeed done differently. For the final implementation, read EL 3.0 specification document instead.
Basically, the change needs to be done in Facelets side, not in EL side. EL 3.0 provides support for static fields, but Facelets simply isn't utilizing it. Even the EL 3.0 import handler after all doesn't work in Facelets. It's likely an oversight. I've pinged the JSF EG on this.
In the meanwhile, your best bet is to create a custom taghandler which does the job. JSF utility library OmniFaces has exactly such taghandler in its assortiment, the <o:importConstants>.
I'am new to Java Spring MVC. Official documentation is very poor and i've got a lot of questions about rendering pages in Spring.
I have page and top block with menu. This menu must be dynamic and must be displayed on all pages. In PHP frameworks this is very common and very easy task. But Spring makes my brain explode.. How can i separate rendering of this menu in some peace of logic and tell spring to render it all the time? For example in JSP. Shoud I use beans or other stuff?
Thanks for your answers!
Official documentation is very poor
No it isn't. Its the one place I always refer back to.
I use a jsp include and yes pass a java bean to the jsp from the controller. The included jsp will be cached the first time it is included. In other places I connect to a controller using jquery and ajax, which dynamically updates the page.
I'd suggest the official tutorials, and krams as good starting points.
You won't find much information about this in the Spring documentation because it's out of the scope of Spring.
You can use JSP includes just as you would do PHP includes. This will however force you to repeat the page layout and the include in each and every page of the application :
<jsp:include page="/menu.jspf" />
Or use a templating engine, like Sitemesh or Apache Tiles (see http://static.springsource.org/spring/docs/3.1.0.RC1/spring-framework-reference/html/view.html#view-tiles for Tiles integration in Spring).
The easiest way would be to use <jsp:include page="/menu.jsp" /> where "/menu.jsp" is a path to your menu jsp.
There are other solutions like using tiles, but <jsp:include> should do.
$(function() {
$("#ac1").autocomplete('getdata.jsp');
}
I'm calling that page in liferay6..
so, What sort of changes I will have to make in portlet.xml and another file ..
I'm getting this error....
http://localhost:8080/web/guest/getdata.jsp?q=abc 404 Not Found
(This error is coming in Firebug not in UI)
Thanks in Advance,
Mayur Patel
First of all, if you are using a portlet specific resource as the data, you should probably be using portlet:resourceURL or liferay-portlet:resourceURL instead of a static address to the file getdata.jsp. ResourceURLs create fully qualified URLs that target your own portlet. The resource served are supposed to be content fragments instead of full blown pages. That way they are especially suitable for AJAX-calls.
Where is the getdata.jsp file located? You could define the full path to the file i.e. /my-service/getdata.jsp instead of relying on the relative address that points to the /web/guest url-mapping. That way you can be sure that the file is found provided that you are not going to share the portlet with others that might not install the portlet the same way as you have done.
I just wants to know that is it possible to integrate Displaytag with spring web mvc ?
If it is possible then can anybody please provide some tutorial or links for that ?
Thanks in advance..
A quick google for "DisplayTag Spring" suggests it works.
From DisplayTag with Spring
There is no extra configuration needed
to use the displayTag with Spring.
Just drop in the jar file to
WEB-INF/lib and start using it in your
jsps
From How to use display tag library in Spring MVC
Place these three jars under
WEB-INF/lib folder displaytag-1.2.jar,
displaytag-export-poi-1.2.jar and
displaytag-portlet-1.2.jar.
Before using it in your jsp you should
have the below line <%# taglib
uri="://displaytag.sf.net"
prefix="display"%>and now you can use
it how ever you want like
note - prefix uri with http.
Btw. a common problem that occurs
with Displaytag + Spring canned
*FormController is that onSubmit is (by default) only called on POST
requests. Keep in mind that displaytag
uses GET requests for sorting and
pagination (as it should), so you may
have to play with overriding the
isFormSubmission method in your
controller, if you want to handle
sorting and pagination in onSubmit