JSTL <c:remove not recognized - jsf

I have tried looking, and its just getting silly.
I am running Glassfish 3.1.1,
JSF version 2
and netbeans 7.0.1
And the following will not work, at all.
< html xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core">
snipped
< c:remove var="test" scope="session"/>
I know it must be something stupid, this is what netbeans keeps saying:
The component library Jstl Core doesn't contain component
And in every JSTL tag library I have checked, it does!

The <c:remove> is originally in the JSTL library for the legacy JSP view technology. Facelets, the successor of JSP, has only a subset of the JSTL tags redefinied (JSP tags doesn't work in Facelets, they have been ported/rewritten). The <c:remove> is not among them.
Your concrete problem has to be solved differently. As the concrete functional requirement is unclear, I can't answer that in detail. But I guess that you actually need a JSF #ViewScoped or a CDI #ConversationScoped bean and store the desired property in there. It'll then be removed when the view scope or the conversation scope ends. Those scopes are well definied and lies in between the request and session scope. See also How to choose the right bean scope?

Related

List of components implementing NamingContainer

I found that there is something called NamingContainer in JSF. It is not clear that which component is a naming container. As far as I know, <h:form> , <h:dataTable> and custom components are naming containers.
Where can I get a list of classes that implement javax.faces.component.NamingContainer?
it depends on libraries you include.
simplest way is to use eclipse type hierarchy.
this is mine, and includes jsf RI 2.2, Primefaces 4.0, Omnifaces 1.7 and a couple of self-made:

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

Iterating over a list in JSF 1.2

Is there any way of iterating over a list in JSF 1.2 without using any third party components? I know I can do it using Tomahawk. I also know that it can be done using JSTL, but I am keeping that as my last resort. Also I cannot use <ui:repeat> since we are using JSF 1.2. Is there any elegant way like <ui:repeat> to do it in jsf 1.2?
The only JSF 1.2 component which can iterate over a List is the <h:dataTable>.
In JSP, the only other "standard" (i.e. not "3rd party") tag which can iterate over a List is the JSTL <c:forEach>. Using JSTL shouldn't harm that much if the List which you'd like to iterate over is already available during view build time. You'll only run into trouble when it's only available during view render time, for example because it's been nested in a <h:dataTable> and should be iterating over a property of table's var. This just won't work due to reasons also mentioned in JSTL in JSF2 Facelets... makes sense?
There are no other ways without using a 3rd party library such as Tomahawk's <t:dataList>, unless you're open to reinventing the wheel by creating a custom UIComponent yourself. This is however not a trivial job.
It's however possible to integrate Facelets 1.x in JSF 1.2. A guide is described in the Facelets 1.x docbook. This is only going to be quite some of work if you already have an existing JSF application using JSP as view technology; you'd need to convert JSP to Facelets. But it'll in end make the upgrade path to JSF 2.x so much easier. See also a.o. Migrating from JSF 1.2 to JSF 2.0 and Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?

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