Problem with outputlink on files - jsf

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().

Related

JSF with ExtensionlessURLs / Omnifaces

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.

Question marks instead of Unicode characters with resource bundle in view

I use Primefaces 3.5 + Lifaray 6.2.
I need some internalization in my app.
I use Language_en_US.properties file and others for string resources.
In backbean I use ResourceBundle.getBundle and it's working propertly.
But in view I use
<p:outputLabel value="#{i18n['server-address']}"/>
And with Cyrillic i always got question marks on page
?????? ??????
It's in page code already as question marks, so it's not a browser problem.
If I use ResourceBundle.getBundle directly
<p:outputLabel value="#{adminBean.getString('main')}"/>
then I got Cyrillic.
Is there any way to use i18n without bean?
Liferay expects the resource bundles to be encoded in UTF-8 (unlike PropertyResourceBundle in plain Java, which uses ISO-8859-1).
Check encoding of you Language_ru_RU.properties file - most likely it is not UTF-8. That would explain that ResourceBundle.getBundle works correctly, while #{i18n['server-address']} doesn't.
While it's a deviation from the standard, UTF-8 encoding is quite comfortable, as there's no need for character escaping.
See Localizing JSF Portlets in Liferay documentation.

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"})

Can't Use PrimeFaces Component on the html page - They aren't rendered at all

I am using JSF1.2 and trying to integrate with PrimeFaces1.1. I added the primefaces-1.1.jar file to my META-INF\lib folder. I also added the namespace to the page with "xmlns:p="http://primefaces.prime.com.tr/ui". The page is working but primefaces components arent rendered. Also eclipse doesnt show me components when I write < p: (ctrl+space). How can I solve this problem ?
Thanks in advance,
Maybe it's a typo, but the jar should be put in WEB-INF/lib instead of META-INF/lib.

Resources