tool or plugin available to convert HTML to JSF tags - jsf

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

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.

how to use <input/> in xhml using JSF of java?

i want to know how to use
of HTML in xhtml page using jsf framework. or please suggest me how to use bootstrap in jsf framework. i tried to use jsf tags instead of HTML tags
but the bootstrap theme and css are not loading properly. can anybody suggest me how to use bootstrap in jsf or any alternate solution?
You can't.
As per w3schools :
XHTML Elements
XHTML elements must be properly nested
XHTML elements must always be closed
XHTML elements must be in lowercase
XHTML documents must have one root element
Related to your problem, Bootstrap can be used with JSF with no problem. Just simply include .css and .js provided by Bootstrap and use them normally in XHTML files as you would do in HTML, but taking care of the above restrictions.

How to include pages in a JSPX and Trinidad project in run-time without breaking the JSF lifecycle?

I am struggling to figure out a way to include dynamically determined pages in run-time in a JSPX and Trinidad project. You will have an idea when you see what I have, which is:
<tr:panelAccordion>
<tr:showDetailItem
text="Test tab">
<jsp:include page=".test.jspx" /> <!-- This part is working fine -->
</tr:showDetailItem>
<jsp:scriptlet>
BackingTest backing = (BackingTest) session.getAttribute("backingTest");
for (CaseTabConfigurationDTO tab : backing.getTabs()) {
java.io.File f = new java.io.File(request.getRealPath(tab.getPagePath()));
if (f.exists()) {
pageContext.include(tab.getPagePath(), true);
}
}
</jsp:scriptlet>
</tr:panelAccordion>
jsp:include part is working fine, nothing is breaking the JSF lifecycle.
jsp:scriplet part is successful for including the correct pages. However, it is breaking the later actions in JSF lifecycle including still persisting backing beans of dialogs opened using useWindow="true".
In order to be make it complaint with Facelet, thus not breaking JSF lifecycle. I tried using tr:forEach, c:forEach, ui:include, ui:repeat approaches without any luck of actually including pages.
Can you share a proper solution for it? Thanks in advance!
You probably want to reconfigure your project so you can use Facelets with Trinidad. After reconfiguring your project can use Facelets for templating. You will end up using xhtml instead of jspx though.
See also:
When to use <ui:include>, tag files, composite components and/or custom components?
How to include another XHTML in XHTML using JSF 2.0 Facelets?

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

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"

ui:calendar tag rendering issue

I'm new to this JSF world, please bear with me if I'm asking some silly thing
i'm using UI tags for my application and I have a scenario that I need to generate a calendar control to make the user to select the date I followed the ui tags documentation and wrote the code like this:
<table width="100%">
<tr>
<td>
<ui:calendar binding="#{booking.calDate}"
id="calDate"
dateFormatPattern="dd/MM/yyyy"
label="Date ::"/>
</td>
</tr>
</table>
and my backing bean contains
private Calendar calDate = new Calendar();
with appropriate getters and setters
when I tried to load the page I'm getting the calendar component disorted.
I'm getting cross marks and nonsense things with some javascript errors.
please help me in resolving this issue
Thanks in anticipation
I got the solution by myself - the issue is with the javascript code. it reads the javascript from themes.jar, which i placed in web-inf/lib folder still it was unable to access that. so I extracted the same and placed it in web-inf and it's working fine
The component is coming from which JSF library?
In others words, what do you have at the beginning of your XHTML file?
The only library I know is coming from Facelets, and it does not provide any component!
In addition, if calDate is a **java.util.**Calendar class, then you cannot bind this class to a JSF component!
Maybe you can have a look to Tomahawk, or Richfaces, that provide good calendar component...
Are you using MyFaces? If so, you may need to configure the MyFaces filter. This loads up the JavaScript and images etc. and may be the cause of your JavaScript and image loading problems.
Obviously if you're not using MyFaces this wont be an issue!

Resources