Page xhtml not displayed with WAS 8.0 , Richfaces 3 and JSF 1 - jsf

I have a web application made with Richfaces 3.3 and JSF 1 (using jsf-facelets-1.1.15.ar), deployed in our local WAS 8.0.0.
Pages are in xhtml and we have declaration namespaces standard:
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
When Websphere 8.0 starts, it's ok, when opening a page from local,
http://localhost:9080/Myapp/pages/home.jsf , we had an error :
viewhandler E Error Rendering View[/pages/home.xhtml]
javax.el.ELException: /pages/home.xhtml: java.lang.NoSuchMethodException: java.util.ArrayList.get(java.lang.Byte)
at com.sun.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:53)
....
Caused by: java.lang.NoSuchMethodException: java.util.ArrayList.get(java.lang.Byte)
at java.lang.Class.throwNoSuchMethodException(Class.java:280)
at java.lang.Class.getMethod(Class.java:843)
With RAD we have set JRE preferences "WebSphere Application Server v8.0 JRE"
and the project has compiler JDK 1.5.
Page error with code jstl : #{myBean.myList.get(indexRuntime).myProperty}
Does not find the get method of JAVA's Arraylist object ?!
With administrative console we have done: WebSphere enterprise applications > application_name > JSP and JSF options, under JSF implementation, selected Sun RI from the drop-down menu.
I'm going crazy.
is a problem with JAVA versions on the pc?
Any Idea?
Thank you so much

This looks like the issue described by BalusC in this post:
In order to access a List item by a fixed index in EL, you need the
brace notation [] instead of performing a direct method call on
List#get(int).
Try accessing myBean.myList via bracket notation:
#{myBean.myList[indexRuntime].myProperty}

Related

PrimeFaces rendered attribute impact on performance

I'm developing a JSF application with PrimeFaces in which i plan to use mainly tabViews (multiple ones). To give you a general idea about how the application is going to work, I have a side menu from which the user should be able to choose "modules" that will display in the center layout as Tabs. Seeing as I have multiple "modules" and there will be more in the future, the solution I've decided on using is writing the code for all the tabs I have in the xhtml and then using the rendered attribute (set to false by default) in order to display them (when the user clicks on the corresponding menu).
Now comes my question, is setting a component's rendered attribute to false equivalent to that component not being there at all (no impact at performance at all)?
Now comes my question, is setting a component's rendered attribute to false equivalent to that component not being there at all (no impact at performance at all)?
It's NOT equivalent. If you set rendered=false, the component is still there in the component tree on the server side. Therefor it costs a little bit performance and memory.
Mojarra also had big performance problems in the past when the component tree is bigger: https://blog.oio.de/2013/05/16/jsf-performance-mojarra-improves-dramatically-with-latest-release/
To use your xhtml page like a template, follow this steps
Step 1 : Create my included page
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
>
<h:form id="form">
...
</h:form>
</ui:composition>
Let say that the name of this page is myTemplate.xhtml
Step 2 : use your template page each time you need it
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="/templates/templateCrb.xhtml"
xmlns:p="http://primefaces.org/ui"
>
<ui:define name="MyContent">
<ui:include src="/pages/.../myTemplate.xhtml">
</ui:include>
</ui:define>
</ui:composition>
In this case i included a complete page, but you can use it in a dialog, a tabView, you can also send parameter to you include element.
You can read more in more informations about include.
Hope that helped you.

jsf - facelets - pack library jar with *.xhtml-s and beans only

I could read the tutorial which describes how to pack facelets to jar to reuse tags as library...
The thing is the instruction recommends using both JSP and JSF in manner as (see code snippet);
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" version="2.0">
<ui:composition>
...
</ui:composition>
</jsp:root>
...and using both .taglib.xml + .tld conf files... :(
So I don't get it may ui:composition in *.xhtml be started as usual by (see code snippet) ...
<ui:composition
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" version="2.0">
...
</ui:composition>
...not to deal with jsp at all? And if, yes, how this kind of library can be added to dynamic web project in eclipse for example?
So my question concerning the tutorial is...
A) is there a way to avoid using *.tld and use have *.taglib.xml only for the lib if the tag library will contain xhtml files only?
B) is there a way to have xhtml-s in non META-INF sub-folder but in some random one?
C) How to automate this kind of library creation process? I mean should I create a project in eclipse (?project category) to have correct folders structure by default to make possible re-compile it and test it and only after that pack it as a jsf library?
I googled a lot but couldn't find solutions variations so please share your experience;
Thanks

Enum properties are not retrieved by OmniFaces in Spring / JSF projects

Given the following enum.
package util;
public enum IntegerConstants
{
DATA_TABLE_PAGE_LINKS(10);
private final int value;
private IntegerConstants(int con) {
this.value = con;
}
public int getValue() {
return value;
}
}
The constant given here should be retrieved on an XHTML page like as follows.
<ui:composition template="/WEB-INF/admin_template/Template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:o="http://omnifaces.org/ui">
<ui:define name="title">Test</ui:define>
<ui:define name="content">
<h:form id="form" prependId="true">
<o:importConstants var="const" type="util.IntegerConstants"/>
DATA_TABLE_PAGE_LINKS : #{const.DATA_TABLE_PAGE_LINKS.value}
</h:form>
</ui:define>
</ui:composition>
This works in an enterprise application having JSF managed beans running on GlassFish 4.0.
This same thing, however does not work in a project that uses Spring (4.0 GA), JSF 2.2.6, PrimeFaces 5.0 final, PrimeFaces Extensions 2.0.0 final running on Tomcat 8.0.3.0.
This should not be related to Spring.
The enum given is available (its class file) in the WEB-INF/classes folder under the application's build folder.
It is difficult to find out the actual cause of the problem because no error or exception is thrown. The page on the browser is just left blank and there is nothing to see on the server terminal.
The OmniFaces version is 1.7.
Given it a try on OmniFaces 1.8-SNAPSHOT but the problem remained stationary.
Partial answer :
This worked, when I changed the value of the var attribute of <o:importConstants> from const to something different like as follows.
<o:importConstants var="literal" type="util.IntegerConstants"/>
DATA_TABLE_PAGE_LINKS : #{literal.DATA_TABLE_PAGE_LINKS.value}
Apparently, the value const appears to have been reserved somewhere but that's too difficult to believe because the same thing with the value const works fine in another application as mentioned above!
This is more related to EL than to JSF/Spring/OmniFaces. The Apache EL implementation as used by Tomcat is indeed quite restrictive as to reserved keywords. So is for example #{bean.class.name} (as in, print bean.getClass().getName()) possible in Oracle EL implementation as used by GlassFish, but not in Apache EL implementation as used by Tomcat. You should instead be writing it as #{bean['class'].name}. All other Java keywords listed in chapter 3.9 of Java Language specification which are not listed in chapter 1.17 of EL specification are also blocked by the Apache EL implementation. The const is indeed among them.
On a side note, it's recommended to start the constants var with an uppercase. This convention allows better distinguishing between managed bean instances and constant references in the EL scope. It also instantly solves your problem as Const is not the same as const.
<o:importConstants var="Const" type="util.IntegerConstants" />
DATA_TABLE_PAGE_LINKS : #{Const.DATA_TABLE_PAGE_LINKS.value}
Or just rename the enum, the var defaults namely to Class#getSimpleName().
<o:importConstants type="util.Const" />
DATA_TABLE_PAGE_LINKS : #{Const.DATA_TABLE_PAGE_LINKS.value}

Manual for updating JSF 2.0 Project to 2.2

unfortunately there are no working tutorials to update a Eclipse (KEPLER) JSF 2.0 Project to JSF 2.2.
Should this update be done or should a new project be created (and import all files)?
What are the Steps to update the used JSF version properly and clean?
I'm just getting errors (from FactoryNotFound to StartupServletContextListener problems), when I change the faces.xml header to:
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
I additionally updated the library to Majorra 2.2.0 (JSF 2.2) and dynamic web project to 3.0 and java to 1.7 (in the preferences), but the server just prints errors and does not work...
From the JSF 2.2. Reference implementation manual
Faces 2.2 is backwards compatible with Faces 2.1 and 2.0. This means that a web-application that was developed to run
with Faces 2.1 or 2.0 won’t require any modification when run with Faces 2.2
Due to an error in previous versions of the specification, exceptions were silently being swallowed that now will
bubble up to the exception handler. Code that was relying on this incorrect behavior may need to be modified to
account for fixing this problem.
And also:
Any additional attributes on <composite:attribute/> are exposed as attributes accessible from the
getValue() and attributeNames() methods on PropertyDescriptor. The return type from getValue()
must be a ValueExpression with the exception of the getValue(“type”). The return type from
getValue(“type”) must be Class. If the value specified for the type attribute of <cc:attribute/>
cannot be converted to an actual Class, a TagAttributeException must be thrown, including the Tag and
TagAttribute instances in the constructor.
Conclusion: there is minimal breakage between JSF2.1. and 2.2.
EDIT: Some new things in JSF2.2:
New namespaces:
xmlns:f="http://xmlns.jcp.org/jsf/core" can replace xmlns:f="http://java.sun.com/jsf/core" and also
xmlns:h="http://xmlns.jcp.org/jsf/html" can replace xmlns:h="http://java.sun.com/jsf/html"
Based on your comment:
The preRenderView event type from the following construct in JSF2.0:
<f:metadata>
<f:event type="preRenderView" listener="#{viewActionManagedBean.validateUser()}"/>
</f:metadata>
Can be replaced with the following brand new <f:viewAction/> tag in JSF2.2:
<f:metadata>
<f:viewAction action="#{viewActionManagedBean.validateUser()}"/>
</f:metadata>
This tag also provides support for executing the managed bean method during specific phases of the request lifecycle with the phase attribute. Valid options are
RESTORE_VIEW (Restore View)
APPLY_REQUEST_VALUES(Apply Request Values)
PROCESS_VALIDATIONS(Process Validations)
UPDATE_MODEL_VALUES(Update Model Values)
INVOKE_APPLICATION(Invoke Application)
RENDER_RESPONSE(Render Response)
The tag also supports the if attribute that defines a boolean condition on which the action will be run. Take the following for example:
<f:metadata>
<f:viewAction action="#{viewActionManagedBean.validateUser()}" if="#{viewActionManagedBean.verifyCondition}" phase="APPLY_REQUEST_VALUES"/>
</f:metadata>
Note that this tag is available only in the new namespace xmlns:f="http://xmlns.jcp.org/jsf/core"
You can get your copy of the specification below. Look under the /Preface/Changes between 2.1. and 2.2. /Backwards Compatibility with Previous Versions
http://jcp.org/aboutJava/communityprocess/final/jsr344/index.html
Just replace the prototype of faces-config by :
`<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">`
Then: select your web project, right click > property > Project facets > deselect jsf version > press ok.
Finaly : right click on your project than maven > update project ...
Restart your server ...
I hope that it help, it work for me

PrimeFaces components don't appear in browser

I'm using JSF 2.2 in my Project (Tomcat 7.42, Mojarra 2.2.1), and i want to use p:calendar from PrimeFaces library. I have included primefaces-4.0.jar into my Project Libraries, and add xmlns:p="http://primefaces.org/ui" namespace, and everything looks ok. Here is my code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:body>
<p:calendar value="#{calendarBean.date2}" id="popupCal" />
</h:body>
</html>
But, in browser, calendar doesn't appear. Standard h: components work great, but from PrimeFaces - nothing works.
I know that PF 4.0 should support JSF 2.2, but i have some issue.
I appreciate any help?
In jsf 2.2 namespaces are changed so you shoud use xmlns.jcp.org instead of java.sun.com
I managed to solve the problem! I am really sorry, but a PrimeFaces' "Getting Started" really confused me. The problem is that I had added PrimeFaces as a library into build path of my project, which is not correct. The right way is to put primefaces-4.0.jar into lib folder under web project. Things are better now. Anyway, thanks people.

Resources