"rendered" attribute in "ui:fragment" - jsf

I want to use the rendered attribute in a ui:fragment to conditionally render a span element in my JSF 2.2 facelet. The JSF 2.2 documentation of ui:fragment lists rendered as an allowed attribute. I am using MyFaces 2.2.12 as JSF implementation, however, and the MyFaces 2.2 documentation of ui:fragment does not list rendered as a valid attribute.
I tried using rendered anyway, and it worked. However, my IDE - IntelliJ - rightly highlights the rendered attribute as an error and tells me it is not allowed in the ui:fragment element.
I saw a response in ui:fragment rendered attribute not working after upgrading Facelets to JSF 2 that there was a documentation bug where rendered falsly wasn't listed in the JSF 2.0 documentation, but the response says nothing about JSF 2.2 or MyFaces 2.2 (presumably because it dates before the release of JSF 2.2).
Is the missing rendered attribute in the MyFaces documentation also just a bug?
With multiple such occurances of the ui:fragment element in a single Facelets file, these "false" errors make finding real errors quite cumbersome. What is the recommended solution for this problem, if it really is just a bug in the documentation?

rendered is valid attribute in ui:fragment and ui:component in JSF 2.0, 2.1, 2.2. See JSF 2.2 View Declaration Language.
Some IDEs do not propose this attribute in autocomplete (content assistant) mode and validate it as "Unknown attribute". This happens because the rendered attribute was missing in the tag file declaration in JSF 2.0 (even if attribute was presented in the UIComponent) and the IDE validation is based on the tag file declarations. Issue was fixed in JSF 2.1: the missing attribute was added into the tag file declaration. Validation in IDE not always reflect to this change.

Related

Where can i find the Servlet generated by the JSF file?

When i try to run my jsf file i get this warning:
12:27:49,357 WARNING [javax.enterprise.resource.webcontainer.jsf.renderkit] (http-localhost- 127.0.0.1-8080-7) JSF1090: Navigation case not resolved for component j_idt24.
In order to fix this problem I need to find out which one is the j_idt24 component, And I'm not sure how to do it, so I figured that I would probably find it in the generated servlet file(Am i right?) , So where can i find the generated Servlet file, or what would be a better way?
-Java
You're confusing JSF with JSP. JSF is a MVC framework which can for the "V" part use either JSP, or Facelets or something entirely different.
What you're stating is true for JSP, but not necessarily for JSF. In JSF2, JSP is succeeded by Facelets which is compiled to a XML document, not a Servlet class. You're also confusing "JSF source code" with "JSF component tree". Those autogenerated IDs are not visible in the compiled XML document of Facelets nor Servlet class of JSP. They are only created during generating the HTML output based on the JSF component tree in server's memory during view render time (that JSF component tree is in turn created based on that XML document or Servlet class during view build time).
Coming back to your concrete problem, this warning will occur when you specify an invalid outcome in <h:link> or <h:button> component. Easiest way to naildown the culprit is to give every single <h:link> and <h:button> a fixed ID so that JSF doesn't need to autogenerate them so that you can just do rightclick, View Source in browser and do a Ctrl+F.
<h:link id="fooLink" value="Foo" outcome="foo" />
An alternative is to add <ui:debug> and explore the JSF component tree which is presented "plain text" in the debug popup and then trackback the found component to its declaration in the JSF (XHTML) source code.
See also:
WARNING JSF1090: Navigation case not resolved for component j_idt51
how to debug JSF/EL

role attribute of h:panelGrid

I'm using exaples from the official Java EE tutorial In which contains the follow:
<h:panelGrid columns="2"
headerClass="list-header"
styleClass="list-background"
rowClasses="list-row-even, list-row-odd"
summary="#{bundle.CustomerInfo}"
title="#{bundle.Checkout}"
role="presentation">
But compiler says that attribute role is not defined for h:panelGrid component. How to fix this?
That attribute was introduced in JSF 2.2. As evidence, the role attribute is mentioned in JSF 2.2 <h:panelGrid> documentation, but not in JSF 2.1 <h:panelGrid> documentation.
Your question history confirms that you're using JSF 2.2 on GlassFish 4.0, so this compiler warning is actually wrong. This is not exactly a JSF problem, but an IDE problem. The IDE is somehow thinking that you're not using JSF 2.2, but JSF 2.1 or older. I.e. your toolset is working against you. You didn't mention which IDE you're using, so it's not possible to post the right answer.
If the project runs fine and the JSF page produces the right HTML output (i.e. the role attribute actually ends up in generated HTML <table> element as you can see by rightclick, View Source in webbrowser), then everything is well and it's just the IDE who's pretending to be smarter than it actually is.
I'd start peeking around in IDE project's properties to check if the JSF versions are all right. The JSF facet in project's properties must be set to version 2.2, not lower. The faces-config.xml must be declared conform JSF 2.2, not lower.

Migrating JSF 1.1 with Ajax4jsf 1.x to JSF 2

We are migrating JSF 1.1 (MyFaces) project to JSF 2. The idea is to migrate periodically by keeping both JSP and XHTML together for some time. We use many ajax4jsf-1.1.1 tags in JSP pages. We don't use RichFaces. After configuring the system to JSF 2 (with all config changes mentioned in tutorial by Balusc) When tried to access the JSP page with ajax4jsf.jar in classpath, we get an exception:
Caused by: java.lang.IllegalStateException: setViewHandler may not be executed after a lifecycle request has been completed
at org.apache.myfaces.application.ApplicationImpl.setViewHandler(ApplicationImpl.java:853)
at org.ajax4jsf.framework.ajax.InitPhaseListener.beforePhase(InitPhaseListener.java:92)
at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersBefore(PhaseListenerManager.java:76)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:131)
It looks ajax4jsf.jar is not compatible with JSF 2. Looks some issue with LifeCycle configuration.
Is there any way we can make a4j work with JSF 2 JSPs? I know when we use XHTML we don't need all this.
Get rid of Ajax4jsf 1.x altogether. It's indeed not compatible with JSF2. Instead, JSF2 offers a new main ajax tag <f:ajax> which covers all the core functionality as previously offered by Ajax4jsf 1.x.
If upgrading to RichFaces 4 is not an option (because, as you said yourself, you aren't using RichFaces components anywhere), then just remove Ajax4jsf 1.x and replace all <a4j:xxx> tags by standard JSF2 equivalents.
<a4j:ajaxListener>: use <f:ajax listener>.
<a4j:keepAlive>: just put managed bean in the view scope by #ViewScoped.
<a4j:log>: use jsf.ajax.addOnEvent() or jsf.ajax.addOnError() in JS context.
<a4j:commandLink>: just nest <f:ajax> inside <h:commandLink>.
<a4j:outputPanel>: use <h:panelGroup> and remember to include its ID in <f:ajax render> or PrimeFaces <p:outputPanel>.
<a4j:repeat>: just use standard <ui:repeat>.
<a4j:form>: just use <h:form>, it will autorecognize <f:ajax>.
<a4j:htmlCommandLink>: just nest <f:ajax> inside <h:commandLink>.
<a4j:jsFunction>: just use standard <h:commandScript>. It was however introduced late in JSF 2.3. If you can't upgrade to JSF 2.3 then consider OmniFaces <o:commandScript> or PrimeFaces <p:remoteCommand>.
<a4j:region>: just use <f:ajax execute>, you can even wrap <f:ajax> around a group of components.
<a4j:loadBundle>: just use standard <f:loadBundle>.
<a4j:status>: use jsf.ajax.addOnEvent() or jsf.ajax.addOnError() in JS context.
<a4j:actionparam>: just use standard <f:param>.
<a4j:loadScript>: just use standard <h:outputScript>.
<a4j:mediaOutput>: no replacement. Consider PrimeFaces <p:media>.
<a4j:poll>: no replacement. Consider OmniFaces <o:commandScript> or PrimeFaces <p:poll>.
<a4j:commandButton>: just nest <f:ajax> inside <h:commandButton>.
<a4j:include>: just use standard <ui:include>.
<a4j:loadStyle>: just use standard <h:outputStylesheet>.
<a4j:support>: just use standard <f:ajax>.
You also need to rename/rewrite JSP files to Facelets files. In simple cases, this is usually just a matter of changing root declarations and file extensions. Facelets makes it easier to replace all duplicated code by a single template. The following answer applies:
Migrating from JSF 1.2 to JSF 2.0

Attribute align invalid for tag panelGrid according to TLD

i have developed application with following facets
Dynamic Web Module 2.5
JavaServer Faces 1.2
Java 5
and i m using Rich Faces 3.2, Sever is Tomcat 6
i get an error
Attribute align invalid for tag panelGrid according to TLD.
i did followed the link
Layout out invalid according to TLD
but it didnt solve my problem since i m already using JSF 1.2. What could be the possible cause of this error. I can give following hints
the project was initially developed with no JavaServer Facet installed
i add JSF 1.2 and Rich faces (for some enhancement that i needed to be incorporated).
ever since then i started getting this error.
Thanks in Advance.
The other question is irrelevant. It's about the layout attribute while you're attempting to use the align attribute. The layout attribute of <h:panelGrid> was introduced in JSF 1.2. The align attribute was never supported by <h:panelGrid>. This attribute is not listed among the supported attributes of the <h:panelGrid> tag for JSF 1.2, as per its TLD documentation.
So, remove that align attribute and do whatever you're trying to do using CSS instead.

Migrating from JSF1.2 to JSF2.0: What to do with JSTL?

we are going to migrate our JSF 1.2 project to JSF 2. We are already using facelets (not JSPs) as our presentation technology.
We are using lot of JSTL -> "xmlns:c="http://java.sun.com/jstl/core"
We are using lot of <c:if> statements. I know that JSF2 brings rendered attribute, which should also evaluate boolean expressions.
Should I bother rewriting stuff to new rendered attribute or is it ok to continue using JSTL in JSF2?
JSTL works the same way in JSF2 as it worked in JSF1. The rendered attribute is not JSF2 specific, it has been in JSF all the lifetime long. If those JSTL tags have always worked as intended in your JSF 1.2 application, then you don't necessarily need to migrate them for JSF2. You only need to change the taglib uri to include the /jsp (!!) path.
xmlns:c="http://java.sun.com/jsp/jstl/core"
However, whenever possible, using the rendered attribute definitely is more recommended than relying on JSTL tags. For sure if you plan to bind JSTL tag attributes to a #ViewScoped bean. See also Communication in JSF 2.0 - #ViewScoped fails in taghandlers.

Resources