Primefaces 3.4.2 javascript error - jsf-2

I'm developing a web application using the 3.4.2 version of Primefaces. I have a p:pickList on it. Application is working using a general template and each page replaces the general_content of the template, which is being reloaded for every request. My problem is that the picklist is not working (cannot interact with it) because some JavaScript error happens when I load the page. This is my xhtml:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui"
template="/templates/general_template.xhtml">
<ui:define name="metadata">
<f:metadata>
<f:viewParam id="user" name="user"
value="#{navegableUserData._ParamUser}" />
<f:viewParam id="NavIndex" name="NavIndex"
value="#{navegableUserData._QueueIndex}" />
<f:event type="preRenderView"
listener="#{navegableUserData.initialize}" />
</f:metadata>
<h:message for="user" />
</ui:define>
<ui:define name="general_content">
<h:form id="SystemUserForm">
<p:pickList id="rolePickList" value="#{navegableUserData._ListRoles}"
var="role" itemValue="#{role}" converter="rolConverter">
<f:facet name="sourceCaption">
<h:outputText value="#{msg.AVAILABLE}" />
</f:facet>
<f:facet name="targetCaption">
<h:outputText value="#{msg.ASSIGNED}" />
</f:facet>
<p:column>
<h:outputText value="#{role._Nombre}" />
</p:column>
</p:pickList>
</h:form>
</ui:define>
This is the JavaScript error I have:
Firebug in Firefox
Firebug is telling me the element 'a' cannot be found in the first line of primefaces.js
"a is undefined"
PrimeFaces={escapeClientId:function(a){return"#"+a.replace(/:/g,"\\:")},
...
Inspector in Chrome
Uncaught TypeError: Cannot call method 'replace' of undefined primefaces.js.xhtml:1
PrimeFaces.escapeHTML primefaces.js.xhtml:1
(anonymous function) primefaces.js.xhtml:27
bG.extend.each jquery.js.xhtml:14
bG.fn.bG.each jquery.js.xhtml:14
PrimeFaces.widget.PickList.PrimeFaces.widget.BaseWidget.extend.generateItems primefaces.js.xhtml:27
PrimeFaces.widget.PickList.PrimeFaces.widget.BaseWidget.extend.init primefaces.js.xhtml:27
e.(anonymous function) jquery.js.xhtml:373
c jquery.js.xhtml:373
PrimeFaces.createWidget primefaces.js.xhtml:1
PrimeFaces.cw primefaces.js.xhtml:1
(anonymous function)
It looks like some jquery is failing. With the previous version of Prime, 3.4.1, everything is working fine.

p:pickList (primefaces v3.4.2) requires itemLabel to be specified.
Just add
itemLabel="#{role}"
to your p:pickList

Related

Composite method do not resolve parameter if in template

it's a bit similar to this problem https://issues.jboss.org/browse/RF-11469
I have a template containing a composite defined like this:
<h:form id="transfer_list">
<ccs:criteriaPanel header="Critère de recherche"
filterAction="#{controller.filter()}">
<form:criteriaForm bean="#{controller.transferCriteria}"
rendered="#{! empty controller.transferSearchForm}"
mode="UPDATE"
controller="#{controller}" />
</ccs:criteriaPanel>
</h:form>
Controller is defined with a ui:param in the template child.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/pages/transfer/transferList.xhtml">
<ui:param name="controller" value="#{transferListOpenController}" />
</ui:composition>
Here is the composite impl (criteriaPanel):
<cc:interface>
<cc:attribute name="header" default="#{i18n['HEADER_SEARCH_CRITERIA']}" />
<cc:attribute name="filterAction" method-signature="java.lang.Object filter()" />
<cc:attribute name="update" default="#(.ui-datatable)" />
</cc:interface>
<cc:implementation>
<div id="#{cc.clientId}">
<p:panel header="#{cc.attrs.header}" toggleable="true">
<cc:insertChildren />
<f:facet name="footer">
<p:commandButton id="search_btn"
value="#{i18n['BUTTON_FILTER']}"
action="#{cc.attrs.filterAction}"
icon="ui-icon-search"
update="#{cc.attrs.update}" />
<p:commandButton value="#{i18n['BUTTON_CLEAR_FILTER']}"
action="#{cc.attrs.filterAction}"
process="#this"
immediate="true"
update="#{cc.attrs.update}">
<p:ajax update="#form" resetValues="true" />
</p:commandButton>
</f:facet>
<p:defaultCommand target="search_btn" />
</p:panel>
</div>
</cc:implementation>
Clicking on the button "filterAction" result into this:
javax.faces.FacesException: #{cc.attrs.filterAction}:
javax.el.PropertyNotFoundException: Target Unreachable, identifier
[controller] resolved to null at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at
org.primefaces.application.DialogActionListener.processAction(DialogActionListener.java:45)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
I use Tomcat 8.5 for this and Mojarra 2.2.13. It works if I don't put the whole thing in a composite component (criteriaPanel)
UPDATE
Sample available here: https://github.com/Rapster/primefaces-test/tree/issue-sof-45834296
Works fine with MyFaces 2.2.11 and Mojarra 2.2.8-23 and 2.3.2 (I don't know how impactful upgrading to 2.3 can be though...) From what I read here https://stackoverflow.com/a/42656386/4605161, Mojarra 2.2.8 is aimed for WebLogic but it seems I will need this one (and i'm running on Tomcat)
WORKAROUND
Writing this make it work (but that's a workaround i'd rather use template):
<ui:composition xmlns="http://www.w3.org/1999/xhtml">
<ui:param name="controller" value="#{testView}" />
<ui:decorate template="/template.xhtml">
</ui:decorate>
</ui:composition>
Funny thing is if I put ui:param inside ui:decorate I'll end up with the same exception
Should be fixed in 2.2.15, see github.com/javaserverfaces/mojarra/issues/4271

Cannot load WEB-INF from browser

I start test my app with primefaces and spring integration but I stop on p:commandButton component. When I click on it, I want show p:growl popup component like here, but unfortunately page is redirect to view in location /WEB-INF/WEB-INF/intro.xhtml (but view is located in /WEB-INF/intro.xhtml) with error of 'resource not found'. May be some one know the problem? I download some example project from GIT and then get the same problem. I change some view code in
/springmvcfacelets/src/main/webapp/templates/maintemplate.xhtml
and paste code from primefaces
<h:form>
<p:growl id="growl" life="2000" />
<p:commandButton value="Ajax Submit" id="ajax" update="growl" actionListener="#{buttonView.buttonAction}" styleClass="ui-priority-primary" />
<p:commandButton value="Non-Ajax Submit" id="nonAjax" actionListener="#{buttonView.buttonAction}" ajax="false" />
<p:commandButton value="With Icon" id="withIcon" actionListener="#{buttonView.buttonAction}" update="growl" icon="ui-icon-disk" />
<p:commandButton actionListener="#{buttonView.buttonAction}" id="iconOnly" update="growl" icon="ui-icon-disk" title="Icon Only" />
<p:commandButton value="Disabled" id="disabled" disabled="true" />
to body in view. Bean was also added and registered.
View 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:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title><ui:insert name="title">Default title</ui:insert></title>
</h:head>
<h:body>
<h:form>
<p:panel id="panel" header="New User">
<h:form>
<p:growl id="growl" life="2000" />
<p:commandButton value="Ajax Submit" id="ajax" update="growl"
actionListener="#{buttonView.buttonAction}"
styleClass="ui-priority-primary" />
<p:commandButton value="Non-Ajax Submit" id="nonAjax"
actionListener="#{buttonView.buttonAction}" ajax="false" />
<p:commandButton value="With Icon" id="withIcon"
actionListener="#{buttonView.buttonAction}" update="growl"
icon="ui-icon-disk" />
<p:commandButton actionListener="#{buttonView.buttonAction}"
id="iconOnly" update="growl" icon="ui-icon-disk" title="Icon Only" />
<p:commandButton value="Disabled" id="disabled" disabled="true" />
</h:form>
</p:panel>
</h:form>
</h:body>
</html>
This has nothing to do with primefaces neither the commandbutton component.
You simply can't access files located in the WEB-INF directory using browser. It would be security bug. Web-Inf would be good for loading integrated tempates using <ui:include> (for example) or for storing your configuration (faces-config.xml, web.xml, app-context.xml ...).
Move your file to any other webapp directory excluding web-inf and change the submit result (where page goes, either from form action or from bean) and let us know the result.
Problem was in web.xml(missing appropriate path for JSF) file and in code of the view.

p:dataExporter NOT working

I am trying to write a simple pdf export functionality using primefaces p:dataExporter. My Code is as below
my development environment is JSF-2.0, Primefaces-3.4.2, Eclips- JUNO, GlassFish
xhtml page
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
>
<h:head>
<title>Pdf Export</title>
</h:head>
<h:body>
<h:form id="myForm" >
<p:dataTable id="tableId" var="car" value="#{tableBean.carsSmall}">
<p:column headerText="Model">
<h:outputText value="#{car.model}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
</p:dataTable>
<h:commandLink ajax="false" >
<p:graphicImage library="images" name="pdf.png" width="40" height="40" />
<p:dataExporter target="tableId" type="pdf" fileName="car"></p:dataExporter>
</h:commandLink>
</h:form>
</h:body>
</html>
my dataTable is populated correctly there is no issue there but when I click for Export nothing happens. Console also doesn't give any message. I have kept iTextpdf-5.4.0.jar and poi-3.2-FINAL.jar in my webapp library. Do I need to do anything else here? Please give me some idea what I am missing?
EDIT-1
I tried using iTextpdd-2.1.7 as suggested in the comment below but still the same problem exist and I am not able to export to pdf.
When I click export the console gives me warning message as below. Is this warning message creating any problem in the export
WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context
/{project name}, because request parameters have already been read, or
ServletRequest.getReader() has already been called
EDIT-2
Today I tried the same code in RAD-Wehsphere/iText 2.1.7 and Export is working fine in that environment. I am able to export dataTable in the pdf file. There must be something that is missing in the Eclips- JUNO, GlassFish environment.
TIA

Primefaces lightBox closes at click on commandLink

It's just a simple Primefaces lightBox I want to use commandLinks in. Unfortunately it simply closes, when I click a commandLink. Is there a way to keep the lightBox open?
Here an example of what my code looks like:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" template="template.xhtml">
<ui:define name="content">
<p:lightBox>
<h:outputLink value="#">
<h:outputText value="open lightbox" />
</h:outputLink>
<f:facet name="inline">
<h:form>
<h:commandLink>
commandLink
</h:commandLink>
</h:form>
</f:facet>
</p:lightBox>
</ui:define>
</ui:composition>
Use an ajax (asynchronous) request instead of a synchronous request:
<h:commandLink ...>
<f:ajax ... />
</h:commandLink>
or as you're using PrimeFaces already, just use <p:commandLink> instead (it uses by default already ajax):
<p:commandLink ... />
With ajax, by default no fresh page replacement with the response is performed (which basically "resets" anything to defaults). You can in case of <f:ajax> tell by render attribute which parts of the component tree should be updated in the client side and in <p:commandLink> by the update attribute. E.g. if you want to render/update the parent form only, use #form. E.g.
<p:commandLink ... update="#form" />

JSF2: Tag Library supports namespace: http://java.sun.com/jsf/composite/components/customer, but no tag was defined for name: list

I created a composite component for a list of customers. I can use this component in a view:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:customer="http://java.sun.com/jsf/composite/components/customer">
<ui:composition template="/WEB-INF/templates/template.xhtml">
<ui:define name="caption">
<h:outputText value="#{msg.customerListHeading}" />
</ui:define>
<ui:define name="content">
<ui:decorate template="/WEB-INF/templates/sidebox.xhtml">
<ui:param name="title" value="#{msg.customerListHeading}" />
<p:outputPanel>
<h:form id="customerList">
<customer:list list="#{customerControllerBean.list}">
<f:facet name="headerButton">
<h:button outcome="customerdetail.jsf"
value="#{msg.newButtonLabel}" />
</f:facet>
<f:facet name="rowButton">
<h:commandButton value="#{msg.deleteButtonLabel}"
action="#{customerControllerBean.delete(customer)}" />
<h:button outcome="customerdetail.jsf?id=#{customer.id}"
value="#{msg.editButtonLabel}" />
</f:facet>
</customer:list>
</h:form>
</p:outputPanel>
</ui:decorate>
</ui:define>
</ui:composition>
</html>
But when i use the component in a very similar view i get the following error:
<customer:list> Tag Library supports namespace: http://java.sun.com/jsf/composite/components/customer, but no tag was defined for name: list
The problematic view looks as follows:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:customer="http://java.sun.com/jsf/composite/components/customer">
<ui:composition template="/WEB-INF/templates/template.xhtml">
<ui:define name="caption">
<h:outputText value="#{msg.customerListHeading}" />
</ui:define>
<ui:define name="content">
<ui:decorate template="/WEB-INF/templates/sidebox.xhtml">
<ui:param name="title" value="#{msg.customerListHeading}" />
<p:outputPanel>
<h:form id="customerList">
<customer:list list="#{customerControllerBean.list}">
<f:facet name="rowButton">
<h:commandButton value="#{msg.applyButtonLabel}"
action="#{orderControllerBean.setCustomer(customer)}" />
</f:facet>
</customer:list>
</h:form>
</p:outputPanel>
</ui:decorate>
</ui:define>
</ui:composition>
</html>
As u can see the two view differs only by the facets i use to add buttons to the customer list table as i use the list in two different contexts. But why does the second view not work?
I found that there is/was an issue with Mojarra, but i use the so called stable revision regarding this problem:
2012-09-16 19:09:41,512 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-4) Mojarra 2.1.7-jbossorg-1 (20120227-1401)
i found a workaround for this problem on Mojarra Jira:
http://java.net/jira/browse/JAVASERVERFACES-2437
i placed the xmlns:customer="http://java.sun.com/jsf/composite/components/customer" in the ui:composition tag and the view rendered sucessfully:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:customer="http://java.sun.com/jsf/composite/components/customer">
<ui:composition template="/WEB-INF/templates/template.xhtml" xmlns:customer="http://java.sun.com/jsf/composite/components/customer">
<ui:define name="caption">
<h:outputText value="#{msg.customerListHeading}" />
</ui:define>
<ui:define name="content">
...
According to that Jira the problem is fixed in Mojarra 2.1.10, so i hope JBoss updates AS 7.1 soon... :)
Incorrect folder path (components) is viewed by eclipse
Remove src/main/resource from build path -- Build Path==> Remove from Build Path.
And add again in build path

Resources