Header doesn't appear in PrimeFaces p:column, when in composite component - primefaces

I try to make a composite component as a Primefaces p:column: /resources/ezcomp/columnBd_1.xhtml:
<?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:cc="http://java.sun.com/jsf/composite"
xmlns:p= "http://primefaces.org/ui">
<!-- INTERFACE -->
<cc:interface componentType="org.primefaces.component.Column" preferred="true" shortDescription="Extended Datatable">
<cc:attribute name="header"/>
<cc:attribute name="value"/>
</cc:interface>
<!-- IMPLEMENTATION -->
<cc:implementation>
<cc:actionSource name="#{component}">
<p:column headerText="#{cc.attrs.header}">
<h:outputText value="#{cc.attrs.value}"/>
</p:column>
</cc:actionSource>
</cc:implementation>
</html>
When I use it inside p:dataTable:
<ez:columnBd_1 header="#{msg.colPriceCloseBid}" value="#{row.closeBid}"/>
I have a column filled with values but there is no header text.
Any advice except using tag file?

Try instead declaring the header facet with an outputText component.
<p:column>
<f:facet name="header">
<h:outputText value="#{cc.attrs.header}" />
</f:facet>
</p:column>

Related

Why do I get "Prefix h for element h:head is not bound" error? [duplicate]

This question already has answers here:
javax.faces.view.facelets.FaceletException: Error Parsing /my.xhtml: Error Traced[line: 42] The prefix "f" for element "f:facet" is not bound
(3 answers)
Closed 6 years ago.
Here's my xhtml file:
<html>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252"/>
</h:head>
<h:body>
<view>
<h:form>
<br/>
<br/>
<center>
<h:panelGrid columns="2">
<f:facet name="header">
<h:outputText value="Login"/>
</f:facet>
<h:outputText value="Benutzername:"/>
<h:inputText value="#{benutzer.benutzerName}" size="18"/>
<h:outputText value="Passwort: "/>
<h:inputSecret value="#{benutzer.passwort}" size="18"/>
<f:facet name="footer">
<h:commandButton value="Login" action ="#{benutzer.doLogin}"/>
</f:facet>
</h:panelGrid >
</center>
</h:form>
</view>
</h:body>
Every time I try to run it I get the error "prefix h for element h:head is not bound."
It's driving me crazy. Why do I get this error?
You need the h namespace
<!DOCTYPE HTML>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
...
</h:head>
<h:body>
...
</h:body>
</html>

Datatable of primefaces not editable inside of a form

Hy,
When I have a datatable of primefaces with paginator and its only readable and not editable, its not needed to be inside of a form, right? although I have seen it many times inside of it
Thanks
You understand correctly. JSF forms use the "post-back" technique to submit form data back to the page that contains the form. If you do not want to do that, you do not have h:form.
The example show below.
xhtml
<?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:p="http://primefaces.org/ui">
<h:head>
<title>Setting Default selectOneMenu</title>
</h:head>
<h:body>
<p:dataTable var="car"
value="#{dtBasicView.cars}"
rows="5"
paginator="true"
paginatorTemplate="{CurrentPageReport}
{FirstPageLink} {PreviousPageLink}
{PageLinks}
{NextPageLink}
{LastPageLink}
{RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
</p:dataTable>
</h:body>
</html>
managedbean
#ManagedBean(name="dtBasicView")
#ViewScoped
public class BasicView implements Serializable {
private List<Car> cars;
#ManagedProperty("#{carService}")
private CarService service;
#PostConstruct
public void init() {
cars = service.createCars(10);
}
public List<Car> getCars() {
return cars;
}
public void setService(CarService service) {
this.service = service;
}
}

Primefaces p:commandLink not working in p:datatTable

i just don't get it...
Why p:commandLink not working? The page is refreshing but with the same amount of data in table. I'm supposing that controller is okay. Take a look.\
View:
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<body>
<ui:composition template="./Template.xhtml">
<ui:define name="content" >
<f:view>
<h:form style="padding: 5px">
<p:dataTable id="dataTable2" var="item" value="#{warningsController.warns}">
<p:column rendered="#{loginController.admin}">
<f:facet name="header">
<h:outputText value="Administracja" />
</f:facet>
<h:form>
<p:commandLink id="Remove" value="Remove" action="#{warningsController.remove(item.id)}" ajax="false" />
</h:form>
</p:column>
</p:dataTable>
</h:form>
</f:view>
</ui:define>
</ui:composition>
</body>
</html>
and controller:
public String remove(long a){
//System.out.println(a);
pf.remove(pf.find(a));
return "Listsev.xhtml";
}
You have multiple h:forms cascaded/nested, that's invalid html. Unknown/wanted side effects can/may occur, maybe like you are experiencing right now. Get right if that inner h:form and try again.
In your remove method, pf is the list which you return by calling #{warningsController.warns}?

JSF Primefaces Tree Node Beginner

I tried using the example of showcase tuts from primefaces.org. I copied exactly the same text in my xhtml file as well as TreeBean.java
But The tree structure never appears in the browser(m using IE9). An empty block appears instead of the tree. Is there anything I need to keep in mind when using tree nodes?
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>PrimeFaces</title>
</f:facet>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100" resizable="true" closable="true" collapsible="true">
Header
</p:layoutUnit>
<p:layoutUnit position="south" size="100" closable="true" collapsible="true">
Footer
</p:layoutUnit>
<p:layoutUnit position="west" size="175" header="Left" collapsible="true">
<h:form id="form">
<p:tree value="#{treeBean.root}" var="node" id="tree">
<p:treeNode id="treeNode">
<h:outputText value="#{node}" id="lblNode"/>
</p:treeNode>
</p:tree>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
Welcome to PrimeFaces
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
You have to create and copy a TreeBean class too. It is avaible for every example on primefaces showcase site, next to xhtml's source code. To make it visible for EL you have to additionally annotate it #Named or #ManagedBean, and give it some reasonable lifecycle scope.
//EDIT:
#Named
#javax.enterprise.context.SessionScoped
public class TreeBean { ... }

Primefaces Slider does not call setter

I have a primefaces (version 3.4.2) slider and an inputText for output value of the slider value.
The problem is that a change of the slider update the displayed value of the inputText, but the setter bind to the inputText is not called.
Here is my slider:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:a4j="http://richfaces.org/a4j">
<h:head>
<title>Zinsrechner</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="1" style="margin-bottom:10px">
<p:inputText id="x" value="#{zinsrechner.monatlicherBeitrag}" />
<p:slider minValue="0" maxValue="150" for="x" />
</h:panelGrid>
</h:form>
</h:body>
</html>
And this is my Setter, which is NOT called:
public void setMonatlicherBeitrag( Double beitrag ) {
monatlicherBeitrag = beitrag;
}
The Getter IS called:
public Double getMonatlicherBeitrag() {
return GuiParameter.getSpareinlageProMonat();
}
Adding a <p:ajax> inside your Slider will to the trick.
Example:
<p:slider minValue="0" maxValue="150" for="x">
<p:ajax event="slideEnd" process="x" />
</p:slider>
I was facing the same problem, but in my case the thing was that I was setting the <p:inputNumber .../> label as read only. I removed that attribute and everything worked.