ui:calendar tag rendering issue - jsf

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!

Related

Embed JSF code in a xhtml

I need to complete a xhtml page with some JSF code (with p:panel and p:datatables, etc.) from a managed bean, but I'm not sure that is possible.
My attemps:
1º
<h:outputText escape="true" value="#{controller.jsfString}"/>
It's not be able to understand "p:" components, only simple html.
2º
<ui:include src="#{controller.jsfString}">
It expects a xhtml path, not a String.
I don't know what else try... Is it even possible?
It's not be able to understand "p:" components, only simple html.
Of course it is not!
The h:outputText value is evaluated at view render time, so if you render JSF tags, they won't be evaluated again since rendering is done.
In principle, it could have been possible to add JSF tags this way using the JSTL <c:out>, but it is not available in JSF facelets.
Anyway, just tell yourself that it prevents you from making bad design.
We'll need more information regarding what the controller is supposed to output in order to help you.
Here p means prime-faces u need to include prime-faces dependency in pom and enable tag lib for prime-faces in XHTML then u can use the all the prime-faces components.

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?

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