JSF with ExtensionlessURLs / Omnifaces - jsf

I´m trying to use ExtensionlessURLs in my JSF app...
I´m using already: https://showcase.omnifaces.org/facesviews/ExtensionlessURLs
This works fine, but if I have a URL with a parameter it´s still with:
mypage.jsf?myparameter=12345
Is there a possibility to exclude here also .jsf, so the URL will be:
mypage?myparameter=12345
I know also Prettyfaces is available, but here I guess I have to define for each JSF page a mapping? Therefore I was using Omnifaces...
Any idea to help here?

It appears that you've an existing JSF application whose FacesServlet is mapped to *.jsf instead of *.xhtml and are trying to enable extensionless URLs through OmniFaces FacesViews using its default "minimal" configuration.
This will indeed not work without making other changes to the existing JSF application.
FacesViews expects that you have already mapped the FacesServlet to the URL pattern of *.xhtml which is recommended since JSF 2.0. So you need to make the following adjustments:
Change FacesServlet mapping from *.jsf to *.xhtml in web.xml.
Find & replace all occurrences of .jsf throughout source code with .xhtml. So e.g.
ec.redirect(ec.getRequestContextPath() + "/portal/employeeEdit.jsf" + "?id=" + id);
must become
ec.redirect(ec.getRequestContextPath() + "/portal/employeeEdit.xhtml" + "?id=" + id);
A bit decent IDE can do this in a few clicks (e.g. Eclipse Ctrl+H, File Search, find .jsf in Enclosing project and replace by .xhtml).
Alternatively, wait for OmniFaces 2.7.11 or 3.11 or 4.0-M8 to be released. I've today fixed this backwards compatibility issue in these versions as per issue 623. With this fix, the existing *.jsf URLs will properly be automatically 301-redirected to the extensionless ones.
Note that this problem is not specifically related to URLs with parameters. It would also happen to URLs without parameters.

Related

What is the equivalent tag for ScriptCollector?

We want to migrate our project from IBM WebSphere 6.1 to Tomcat 6, but in our JSP-JSF UI pages we have extensively used below IBM JSF tags.
ScriptCollector
PanelRowCaregory
PagerWeb
OutPutSelections
InputRowSelect
InputHelperDatePicker
InputHelperAssist
ConvertMask
And to replace above tags, we are trying to find the equivalent tags from Sun JSF or any other open source libraries, but we didn't find any equivalent tags.
I wanted to know whether any body has already worked on this kind of migration project, if yes can you please share the equivalent tags?
or if you solved it differently even that info also will be useful.
Thanks in Advance.
There's no standard JSF equivalent for the <hx:scriptCollector> (although the JSF 2.0 <h:head> comes close). The <hx:scriptCollector> is only required by those IBM-specific <hx:xxx> components. It's designed to collect all JavaScript files required by those <hx:xxx> components and then render the desired <script> tag(s) without potential duplicates when multiple components require the same JS files. It's not required by any standard JSF component.
In other words, just get rid of it without replacement.
As to other tags, just check the available standard components in tag documentation or Java EE tutorial. If none is available, just pick a component library like PrimeFaces or RichFaces. If you still can't figure out, ask an individual question for the particular tag.

How to upload a file JSF 2.0 while having web.xml mapped to .html instead of .jsf?

I am following this guide: http://balusc.blogspot.com/2009/12/uploading-files-with-jsf-20-and-servlet.html and everything has gone smoothly except that I noticed it would only work if my web.xml is mapped to .jsf. Any ideas?
I am on tomcat 7.0.12 jsf 2.1.17 from mojarra and that is why I'm not using Tomahawk.
You need to make sure that the URL pattern of the filter mapping of the file upload filter also matches the desired JSF requests. Assuming that your FacesServlet has a <url-pattern>*.html</url-pattern>, then this should do:
#WebFilter(urlPatterns={"*.html"})
Even better, if you're going to use it exclusively for file uploads via JSF, then you can also map it on the servlet name of the faces servlet. Assuming that you've a <servlet-name>facesServlet</servlet-name>, then this should do:
#WebFilter(servletNames={"facesServlet"})

What are the benefits of using JSF2 resources?

Should I use JSF2 resources instead of plain html like <link href... or url(image.png)? What are the benefits? For me this is a bit annoying when web-designer creates layout with XHTML, CSS and all that stuff and I need to spend time to replace plain HTML paths and tags to JSF resource tags like#{resource[...]}.
Is there any other way? Like to put all CSS/image files in web root and use normal links?
Your choice.
The major benefit is that you can declare them on a per-component basis. If you need to include them on every single page anyway, then the benefit is little. But if you need to include component-specific CSS/JS code in for example a composite component which is reused more than once in a single view, then for example an <h:outputScript> in a composite component would end up in it being included only once instead of that many times as the composite component is been used as would happen with <script>. The same applies to the #ResourceDependency annotation on real UIComponent classes.
Please note that you are not required to use JSF2 resources only. Just plain vanilla <img>, <link>, <script>, etc is also perfectly fine. It can even point to the JSF resources folder.

Problem with outputlink on files

I'm working on a JSF 2.0 project using Mojarra, PrimeFaces and Tomcat 6.x.
I created some outputlink that point to files. These files are external of my WAR in a directory under Apache HTTPD's control.
<h:outputLink value="#{fileItem.linkTarget.sourceUrl}">#{fileItem.boname} (#{fileItem.linkTarget.mediaType})</h:outputLink>
The sourceUrl is value like /dir/subDir/file.pdf. When my sourceUrl doesn't contains space it's work. But when its contains space, they are are replace by +.
/dir/subDir/big file.pdf become /dir/subDir/big+file.pdf. When i replace the + with space in a normal webbrowser, it's work?
What's wrong and how can I fix it?
I get the same problem with graphicImage of mojarra and i solve by using Primefaces's graphicImage.
In general I would not recommend to use blank spaces in urls.
If you have no influence on the file names in the url's you should url-encode these names as described here URL-Encoding. The blank space has to be replaced by %20. Maybe there is a java class that does the encoding for you. I only know it from PHP, there you have a function like urlEncode().

ww.w3.org/1999/xhtml]. JAR containing the TLD may not be in the classpath

when i am trying to running jsf project using the ice faces i am getting this error 10:56:54,144 ERROR JspPageToDocument:104 - Can't find TLD for location www.w3.org/1999/xhtml]. JAR containing the TLD may not be in the classpath . waht needs to be add to get rid of this error.
Older versions of IceFaces' parser seem to have problems with JSPX.
Either upgrade IceFaces to latest version, or use Facelets instead of JSPX, or use "plain" JSP instead of JSPX (i.e. get rid of <jsp:xxx> tags).

Resources