Why is <t:inputFileUpload value="#{myBean.uploadedFile}" /> not working? - jsf

I'm using JSF 2.0 and need to allow users to upload images. I thought to use <t:inputFileUpload> and read it behaves similarly to <input type="file"> however I can never see a 'browse' option in any browser I use.
I have configured my web.xml properly and have <h:form enctype="multipart/form-data"> as my form beginning. There is also only one tag inside the form. I also have all necessary jars from what I can gather.
Anyone else experience this?

If you see the <t:inputFileUpload> unparsed in the generated HTML output instead of the <input type="file"> which it is supposed to generate, then it means that the t:xxx namespace is not registered, or that the JAR files containing it are not in the webapp's runtime classpath. This way JSF/Facelets will just treat it as plain text instead of a real JSF tag and it will end up unparsed in the HTML output. The webbrowser only understands HTML tags, so it will do nothing with the unparsed JSF tag and hence you see nothing in the webbrowser's UI presentation.
Make sure that the Tomahawk JAR files are all in /WEB-INF/lib folder of the webapp and make sure that you've declared the t:xxx namespace in the view as follows:
xmlns:t="http://myfaces.apache.org/tomahawk"

Related

Should I use ui:fragment with the render attribute to conditionally render HTML tags in Facelets with JSF 2.2?

I am in the process of upgrading an old project from JSF 1.1 to JSF 2.2. Specifically, I am upgrading the JSF implementation from MyFaces 1.1 to MyFaces 2.2.12, replacing JSPs with Facelets and upgrading/replacing outdated tag libraries. I am mainly using Migrating from JSF 1.2 to JSF 2.0 as a guide.
The project used some tag library called htmLib with the namespace http://jsftutorials.net/htmLib in it's JSP pages. I can't find any documentation about this tag library anymore, neither on the jsftutorials webpage nor elsewhere, but apparently it was used to include plain HTML tags like <div> or <table> in JSP pages.
Since plain HTML tags can now be used in XML Facelets with JSF2, I am right now removing all occurences of tags from the htmLib taglib like <htm:div>...</htm:div> and replace them with plain HTML tags like <div>...</div>.
However, some of the tags used from htmLib contain the render attribute for conditional rendering, like this:
<htmLib:h4 render="someCondition">
...
</htmLib:h4>
Because plain HTML tags don't have a render attribute for this purpose, I was searching for an alternative way to conditionally render plain HTML tags and stumbled upon this answer on SO: How to conditionally render plain HTML elements like <div>s?
So, my idea is to replace a construct like the one above with something like
<ui:fragment render="someCondition">
<h4>
...
</h4>
</ui:fragment>
My questions:
Is wrapping HTML tags inside a <ui:fragment> tag with the render
attribute the recommended way to conditionally render HTML tags, or
is this method only valid and recommended for the case in the linked question?
Are there other ways to conditionally render plain HTML tags in Facelets that should be preferred?
Does the <ui:fragment> wrapping method work, no matter what kind of plain HTML is contained within it?
Can conditionally rendered <ui:fragment> blocks be nested?
There's no limitation in that. Not even for wrapping ui:fragment.
Basically:
In order just to control the inner content, with no extra HTML generation use
ui:fragment.
To generate an extra HTML span element, use h:panelGroup.
To generate an extra HTML div element, use h:panelGroup layout="block".
The HTML you have inside isn't a problem. JSF, being a server side framework, performs all the HTML building/rendering job in the server, so the JSF/facelet tags get translated to HTML before the response being sent. All the plain HTML you use inside will remain HTML.
However, beware of using tag handlers inside UI Components when migrating from 1.x. Tag handlers (ui:include, c:if, c:forEach) evaluate before the UI Components (which tipically contain rendered clauses). This has been a source of conflict in JSF 2.

jsf output html-formatted text

I have what it seems to be a very trivial question for you jsf expert out there...
I'm working in a JSF 2.0 application. Said that I have managed bean with a property containing an html portion to display to the user, which faces control should I use to emit that html directly on the page, without encoding it?
Did you try that:
<h:outputText value="#{myBean.myProperty}" escape="false"/>
By default, escape attribute is set to true in order to escape the HTML / XML characters.

Problems with displaying image in portlet using jsf

I need some help with showing images in my portlet. I have images somewhere on
HDD. I wrote servlet ImageServlet with doGet() method. I registered servlet
in web.xml with mapping /images/*.
The problem begins when i try to show image:
<h:graphicImage url="/images/image.png" />
The doGet() method in servlet is not called. HTML output I get is:
<img src="/PortletName/images/image.png"/>
However when I'm using other tag, for example:
<jsp:include file="/images/image.png"/>
doGet() in ImageServlet is called (it doesn't work
obviously, but it shows that servlet is registered correctly).
I tried mapping /PortletName/images/*, but it didn't help. And I can't write url without '/' in the beginning (I get an exception - Liferay
forbids it).
Am I missing something while calling servlet from h:graphicImage? Or is there any way to get rid of /PortletName/ in the generated HTML? Or is there other way to display image (using include or something)?
Help would be appreciated :)
Edit:
JSF 1.1; DTD portlet application 4.3.0; portlet-app_1_0.xsd; org.apache.portals.bridges.portletfilter.FilterPortlet
I managed to do it. I used Liferay PortalDelegateServlet:
http://longgoldenears.blogspot.com/2008/03/portaldelegateservlet-servlet-session.html
and I used <img> tag.

how to generate dynamic rich:panelMenu?

i have a problem to generate dynamic menu, i'm using JSF1.2. I tried the c:forEach with an arrayList to generate dynamic rich:panelMenu as BalusC advised in a related forum, but get Accessor never triggered in c:forEach. it ruined me a day. can anyone provide me a solution ?
<c:forEach items="#{serviceListBean.services}" var="child">
<rich:panelMenuItem mode="none">
<h:outputText value="#{child.serviceId}"></h:outputText>
</rich:panelMenuItem>
</c:forEach>
what's wrong in this code? can anyone enlighten me?. For info, serviceListBean is request scoped bean.
Two possible causes:
JSTL is not declared as taglib in JSP or Facelets. To confirm this, rightclick page in browser and choose View Source. Do you see <c:forEach> tag unparsed among the generated HTML? If you're using JSP, declare it as follows:
<%#taglib prefic="c" uri="http://java.sun.com/jsp/jstl/core" %>
Or if you're using Facelets, declare it as follows in root element:
xmlns:c="http://java.sun.com/jsp/jstl/core"
On some servers like Tomcat, which doesn't ship with JSTL out the box, you would also need to install JSTL first, see also this info page.
This piece of code is in turn been placed inside a JSF repeating component, like <h:dataTable> with a var="serviceListBean". This is also not going to work. You would need to replace the JSF repeating component by <c:forEach> as well.

tool or plugin available to convert HTML to JSF tags

Is there any tool or plugin available to convert HTML code to JSF tags?
If you are using Facelets, you can add for any HTML tag the jsfc attribute that will indicate which JSF component is related to the HTML tag. For example:
<input id="bar" type="text" jsfc="h:inputText" value="#{foo.bar}"/>
I am not sure that automatically generate JSF code from HTML code is a good idea. JSF uses JSP or XHTML pages as a XML description of a page structure. The HTML code is automatically generated by the JSF framework. If you generate the JSF code from the HTML code, you will have a lot of garbage code in your JSP/XHTML files, and I am not sure that the generated code will work correctly.
It is quite dependent of the quality of the HTML you have in fact...
However, you may have a look at the phoenix solution and then clean the generated JSF code.
Maybe you could try this tools: http://docs.oracle.com/cd/E13226_01/workshop/docs92/studio33/JSF/ConvertingHTMLtoJSF.html

Resources