I am working on my first web project and using PrimeFaces component suite for it.
I want fire a resize event when i resize the center layout unit. I have tried the code but the method in the bean class is never get called.
What am I doing wrong here? please correct me if I am wrong?
<p:layout fullPage="true" resizeListner="#{resizeBean.handleResize}">
<p:layoutUnit id="top" position="north" resizable="true" size="20%">
<ui:insert name="header">
<ui:include src="Header.xhtml" />
</ui:insert>
</p:layoutUnit>
<p:layoutUnit id="bottom" styleClass="class-bottom" position="south"
resizable="true" size="25%">
<ui:insert name="footer">
<ui:include src="Footer.xhtml" />
</ui:insert>
</p:layoutUnit>
<p:layoutUnit id="left" styleClass="class-left" position="west"
resizable="true" size="24%">
<ui:insert name="tree">
<ui:include src="Tree.xhtml" />
</ui:insert>
</p:layoutUnit>
<p:layoutUnit id="addDlg" position="center">
<ui:insert>
<ui:include src="AddDevice.xhtml" />
</ui:insert>
</p:layoutUnit>
<p:layoutUnit id="center" position="center">
<ui:insert name="centerPage">
<ui:include src="Center.xhtml" />
</ui:insert>
</p:layoutUnit>
</p:layout>
Here is the code for the bean class
#ManagedBean(name = "resize")
public class ResizeBean implements Serializable {
private long width;
private long height;
public void handleResize(ResizeEvent event) {
width = event.getWidth();
height = event.getWidth();
System.out.println("in resize");
}
public long getWidth() {
return this.width;
}
public long getHeight() {
return this.height;
}
}
Well, I don't know witch version of PrimeFaces you're using, but the attribute resizeListener is not found in de PrimeFaces manual. Also you gave your bean a name with the name attribute:
#ManagedBean(name = "resize")
So if you want to use this in your view, then refer to your given name like this:
#{resize.handleResize}
If you don't use the name attribute then you can refer to resizeBean. More info can be found here: http://docs.oracle.com/javaee/6/api/javax/faces/bean/ManagedBean.html
To get the resize event add a <p:ajax> tag in your view something like this:
<p:ajax event="resize" listener="#{resize.handleResize}" />
And now add the <h:form> tag around your layout and everything should work.
Complete view:
<h:form>
<p:layout fullPage="true">
<p:ajax event="resize" listener="#{resize.handleResize}" />
<p:layoutUnit id="top" position="north" resizable="true" size="20%">
<ui:insert name="header">
<ui:include src="Header.xhtml" />
</ui:insert>
</p:layoutUnit>
<p:layoutUnit id="bottom" styleClass="class-bottom" position="south"
resizable="true" size="25%">
<ui:insert name="footer">
<ui:include src="Footer.xhtml" />
</ui:insert>
</p:layoutUnit>
<p:layoutUnit id="left" styleClass="class-left" position="west"
resizable="true" size="24%">
<ui:insert name="tree">
<ui:include src="Tree.xhtml" />
</ui:insert>
</p:layoutUnit>
<p:layoutUnit id="addDlg" position="center">
<ui:insert>
<ui:include src="AddDevice.xhtml" />
</ui:insert>
</p:layoutUnit>
<p:layoutUnit id="center" position="center">
<ui:insert name="centerPage">
<ui:include src="Center.xhtml" />
</ui:insert>
</p:layoutUnit>
</p:layout>
<h:/form>
Related
I use a menubar from primefaces
<p:toolbar style="margin:20px 0px">
<f:facet name="left">
<p:outputLabel value="#{loginBean.fullname}" />
</f:facet>
<f:facet name="right">
<p:inputText style="margin-right:10px" placeholder="Search" disabled="true"/>
<p:themeSwitcher effectSpeed="normal" effect="fade" style="width:165px; margin-right:10px;" id="defaultSwitcher" value="#{themeSwitcherBean.theme}">
<f:selectItem itemLabel="Choose Theme" itemValue="" />
<f:selectItems value="#{themeSwitcherBean.themes}" />
<p:ajax global="false" listener="#{themeSwitcherBean.saveTheme}" />
</p:themeSwitcher>
<p:commandButton action="#{loginBean.logout}" title="Log Out" style="width:36px; height:20px" icon="ui-icon-power" value="" ajax="false"></p:commandButton>
</f:facet>
</p:toolbar>
which renders to the right side
It disturb my eye that the alignment fro mthe search-box and the drop-down-box are not at the same height.
You know how i can align them correctly?
You need to fix the drop-down-box appearance using with CSS. Try to add "margin-top" or "padding-top" property to the p:themeSwitcher style arrtibute.
I want to design a Layout and the footer should alway been display on the bottom on the page how can I set this with CSS. Here is the application now http://default-environment-wvg8irfup6.elasticbeanstalk.com/public/register.xhtml.
I use jsf 2.2 and primefaces 4.0
Here is the code
<f:view>
<f:metadata>
<ui:insert name="metadata" />
</f:metadata>
<h:outputStylesheet library="css" name="template.css" />
<p:layout fullPage="true">
<p:layoutUnit styleClass="ui-widget-header" position="north" size="110">
<p:layout height="140">
<p:layoutUnit position="west" width="180" height="140">
<p:graphicImage library="images" name="Logo_0.3.png" height="90" width="170" />
</p:layoutUnit>
<p:layoutUnit position="center">
<ui:insert name="header">
<ui:include src="/META-INF/templates/templateMenubar.xhtml" />
</ui:insert>
</p:layoutUnit>
</p:layout>
</p:layoutUnit>
<p:layoutUnit styleClass="content" position="center">
<h1>
<ui:insert name="title">
<h:outputText value="Default Title" />
</ui:insert>
</h1>
<ui:insert name="content">
<ui:include src="/META-INF/templates/templateContent.xhtml" />
</ui:insert>
</p:layoutUnit>
<p:layoutUnit styleClass="ui-widget-header" position="south" size="60">
<p:layout styleClass="footerpic" height="100">
<p:layoutUnit position="center">
</p:layoutUnit>
<p:layoutUnit styleClass="footerpic" position="east" width="300" height="80">
<h:graphicImage styleClass="footerpic" library="images" name="MFMNeu.png" height="25"
width="25" />
</p:layoutUnit>
</p:layout>
</p:layoutUnit>
</p:layout>
</f:view>
Add CSS properties
position:absolute;
bottom:0px;
to your footer.
In my case, I also had to add to the body section height: 100%
My css looks like:
html {
height: 100%
}
body {
height: 100%
}
.my_footer {
position: absolute;
bottom: 0 px;
}
I have a xhtml page with two tables that are set css style:
<o:dataTable id="productTable" value="#{produkty.produkty}" var="p"
rowKey="#{p.product.id}" pageSize="10" styleClass="dataTable"
style="line-height: 15px; font-size: 12px; table-layout: fixed;">
<o:columnResizing resizeHandleWidth="10px" minColWidth="50px" />
<o:multipleRowSelection rowDatas="#{produkty.SProdukty}"
style="background: #a4aec5; color: white;" mouseSupport="false"
keyboardSupport="false" />
<!-- OPIS -->
<o:column header="Opis" id="opisCol1"
sortingExpression="#{p.product.opis}"
style="text-align: left; padding-right: 5px; padding-left: 5px; ">
<f:facet name="subHeader">
<o:inputTextFilter />
</f:facet>
<!-- <h:outputText value="#{p.product.opis}" /> -->
<o:hintLabel value="#{p.product.opis}" hintTimeout="0"
style="width: 350px; margin-right: 10px; color: black; border-color: red;" />
</o:column>
</o:dataTable>
the style used in <o:hintLabel> and <o:dataTable> tags set only when I press a button:
addBean method looks like this:
public void addBean() {
add();
produktyP.chainReaction(this);
}
which has nothing in common with the table, but it's reloading page, why onle when i press this button css styles set? In addition, I will say that the site is in tag. I use OpenFaces lib.
index.xhtml source:
<?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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:o="http://openfaces.org/">
<h:head>
<title>PIR Kreator Ofert</title>
<script src="/WEB-INF/resources/script.js" type="text/javascript"></script>
<link rel="stylesheet" href="resources/style.css" type="text/css"/>
</h:head>
<h:body>
<h:form id="form">
<h:panelGrid columns="2">
<h:outputLink value="index.xhtml"><h:graphicImage id="logo" alt="pir logo" url="/images/logo.png"/></h:outputLink>
<h1>Kreator Ofert</h1>
</h:panelGrid>
<o:tabbedPane>
<o:subPanel caption="Nagłówek">
<ui:include src="index_core/naglowek.xhtml" />
</o:subPanel>
<o:subPanel caption="Produkty">
<ui:include src="index_core/produkty.xhtml" />
</o:subPanel>
</o:tabbedPane>
<h:panelGrid columns="2">
Sortowanie Elementów:
<o:selectBooleanCheckbox value="#{pdf.sortContent}" />
</h:panelGrid>
<h:panelGrid columns="5">
Nazwa pliku:
<o:inputText value="#{pdf.fileName}" />
<o:commandButton id="printButton" value="Drukuj"
actionListener="#{pdf.printt}" />
<o:commandButton id="initializePDFButton" value="Reset"
action="#{pdf.initPDF}" />
<o:commandLink value="Download PDF" action="#{pdf.downloadPDF}"
target="_blank" />
</h:panelGrid>
<!-- AJAX -->
<ui:include src="ajax_core/ajax.xhtml" />
</h:form>
</h:body>
</html>
produkty.xhtml source:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition 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:o="http://openfaces.org/">
<h:panelGrid columns="2">
<h:panelGroup layout="block" id="produktMenu">
<o:dataTable id="productTable" value="#{produkty.produkty}" var="p"
rowKey="#{p.product.id}" pageSize="10" styleClass="dataTable"
>
<o:columnResizing resizeHandleWidth="10px" minColWidth="50px" />
<o:multipleRowSelection rowDatas="#{produkty.SProdukty}"
style="background: #a4aec5; color: white;" mouseSupport="false"
keyboardSupport="false" />
<o:columnReordering />
<f:facet name="columnMenu">
<o:columnMenu />
</f:facet>
<f:facet name="header">
<h:outputText value="Tabela Produktów" />
</f:facet>
<!-- SELECTION -->
<o:selectionColumn sortable="true" header="Selection"
style="width: 5%;" onclick="O$('form:addProduct').run()">
<f:facet name="header">
<o:selectAllCheckbox style="width: 10px;" />
</f:facet>
</o:selectionColumn>
<!-- KATEGORIA -->
<o:column header="Kategoria"
sortingExpression="#{p.product.kategoria}">
<f:facet name="subHeader">
<o:dropDownFieldFilter maxlength="4" customValueAllowed="false"
style="width: 40px;" />
</f:facet>
<h:outputText value="#{p.product.kategoria}" />
</o:column>
<!-- ILOSC -->
<o:column header="Ilość">
<o:spinner id="ilosc" value="#{p.ilosc}" minValue="1"
maxValue="100" onclick="O$('form:addProduct').run()"/>
</o:column>
<!-- SYMBOL -->
<o:column header="Symbol" id="symbolCol1"
sortingExpression="#{p.product.symbol}" style="width: 100px">
<f:facet name="subHeader">
<o:inputTextFilter />
</f:facet>
<h:outputText value="#{p.product.symbol}" />
</o:column>
<!-- OPIS -->
<o:column header="Opis" id="opisCol1"
sortingExpression="#{p.product.opis}"
style="text-align: left; padding-right: 5px; padding-left: 5px; ">
<f:facet name="subHeader">
<o:inputTextFilter />
</f:facet>
<!-- <h:outputText value="#{p.product.opis}" /> -->
<o:hintLabel value="#{p.product.opis}" hintTimeout="0"
style="width: 350px; margin-right: 10px; color: black; border-color: red;" />
</o:column>
<!-- CENA -->
<o:column header="Cena" id="cenaCol1"
sortingExpression="#{p.product.cena}" style="width: 55px;">
<h:outputText value="#{p.product.cena}€" />
</o:column>
<!-- PAGINATOR -->
<f:facet name="below">
<o:dataTablePaginator id="paginator" firstText="Pierwsza"
lastText="Ostatnia" nextText="Następna" previousText="Poprzednia"
pageNumberPrefix="Strona" pageCountPreposition="z" />
</f:facet>
<f:facet name="footer">
<o:commandButton value="Odśwież" type="button"
onclick="O$('form:addProduct').run()" />
</f:facet>
</o:dataTable>
</h:panelGroup>
</h:panelGrid>
</ui:composition>
I use DOCTYPE on both pages, because when only index.xhtml has it, Tomcat gives me:
HTTP Status 500 - /index.xhtml #28,51 <ui:include src="index_core/produkty.xhtml"> Invalid path : index_core/produkty.xhtml
another thing, when I want to add css file by <h:outputStylesheet library="css" name="style.css" /> or <link rel="stylesheet" href="resources/style.css" type="text/css"/> tomcat gives me java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config exception, I add jstl.jar lib to Tomcat/lib and nothing helps.
It works on IE olny, why?
Is it possible to remove all the margins of <p:layoutUnit> on all the four sides in my below mentioned code?
<p:layout style="max-width: 80%;height: 700px" fullPage="false">
<p:layoutUnit position="north" size="100" style="border: 0px">
<div align="right">
<p:selectOneMenu id="city">
<f:selectItem itemLabel="Select City" itemValue="" /> />
</p:selectOneMenu>
</div>
<h:graphicImage alt="DiscountBox.in" value="/images/discountbox_logo.jpg" />
</p:layoutUnit>
<p:layoutUnit position="west" size="20%" style="border: 0px">
<p:panel header="Categories">
<p:menu style="border: 0px">
<p:submenu>
<p:menuitem value="Demo" url="http://www.primefaces.org/showcase-labs/ui/home.jsf" />
<p:separator />
<p:menuitem value="Documentation" url="http://www.primefaces.org/documentation.html" />
<p:separator />
<p:menuitem value="Forum" url="http://forum.primefaces.org/" />
<p:separator />
<p:menuitem value="Themes" url="http://www.primefaces.org/themes.html" />
</p:submenu>
</p:menu>
</p:panel>
</p:layoutUnit>
<p:layoutUnit position="center" style="border: 0px">
<p:panel header="Search">
</p:panel>
<p:panel header="Search">
</p:panel>
</p:layoutUnit>
<p:layoutUnit position="south" size="100" style="border: 0px">
Footer
</p:layoutUnit>
</p:layout>
put on your page this:
<head>
<style type="text/css">
.ui-layout, .ui-layout-doc, .ui-layout-unit, .ui-layout-wrap, .ui-layout-bd, .ui-layout-hd{
border: none;
}
</style>
</head>
There is a property in the p:layoutunit called gutter
<p:layoutUnit position="north" size="80" gutter="0">
In my dataTable when a row is clicked it gets marked with some color. But then this mark disappears because submit occurs. But i re-render only some other part of the page and not the table, so why does it occur? How can i fix this?
The code:
<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:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:p="http://primefaces.prime.com.tr/ui"
template="/templates/mainLayout.xhtml">
<ui:define name="header">
<h1>Persons List</h1>
</ui:define>
<ui:define name="content">
<h:form id="mainForm">
<h:outputStylesheet name="tableStyle.css" library="css" target="body"/>
<h:panelGroup id="personPanel">
<h:outputText value="#{msgs.fName}"/>
<h:inputText value="#{personController.person.firstName}" maxlength="20"/>
<h:outputText value="#{msgs.lName}"/>
<h:inputText value="#{personController.person.lastName}" maxlength="20"/>
<h:outputText value="#{msgs.phone}"/>
<h:inputText value="#{personController.person.phone}" maxlength="20"/>
</h:panelGroup>
<h:commandButton value="#{msgs.save}" >
<f:ajax execute="#form" render="personsTable personPanel" listener="#{personController.savePerson}"/>
</h:commandButton>
<h:dataTable id="personsTable" value="#{personController.persons}" var="bean"
styleClass="order-table" headerClass="order-table-header" rowClasses="order-table-odd-row,order-table-even-row" rules="none" >
<h:column>
<f:facet name="header">
<h:outputText value="First Name" />
</f:facet>
<h:commandLink value="#{bean.firstName}" >
<f:ajax execute="#this" render="personPanel" >
<f:setPropertyActionListener target="#{personController.person}" value="#{bean}" />
</f:ajax>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Last Name" />
</f:facet>
<h:commandLink value="#{bean.lastName}" >
<f:ajax execute="#this" render="personPanel">
<f:setPropertyActionListener target="#{personController.person}" value="#{bean}" />
</f:ajax>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Phone" />
</f:facet>
<h:commandLink value="#{bean.phone}" >
<!-- f:ajax execute="#this" render="personPanel">
<f:setPropertyActionListener target="#{personController.person}" value="#{bean}" />
</f:ajax-->
</h:commandLink>
</h:column>
</h:dataTable>
</h:form>
</ui:define>
<ui:define name="footer">
<script type="text/javascript">
$(document).ready(function(){
$(".order-table tr").mouseover(function(){
$(this).addClass("over");
});
$(".order-table tr").mouseout(function(){
$(this).removeClass("over");
});
$(".order-table tr").click(function(){
$(".order-table tr").removeClass("choose");
$(this).addClass("choose");
});
});
</script>
</ui:define>
</ui:composition>
You can use firefox and "firebug" plugin to inspect the element in real time to find out what's going on. It could be that something about your update is breaking the inheritance of the style...