How to right align h:panelGrid? - jsf

Im design a navigation bar for a webpage in jsf.
I want some links to be on the right of the bar and some on the left. It doesnt seem to work.
Any ideas?
<h:panelGrid columnus="2">
<h:panelGroup styleClass="alignmentLeft">
<h:panelGrid columns = "2" columnsClasses = "alignmentLeft">
<h:outputLink>... </h:outputLink>
<h:outputText/>
<h:outputLink>... </h:outputLink>
<h:outputText/>
</h:panelGrid>
</h:panelGroup>
<h:panelGroup styleClass="alignmentRight">
<h:panelGrid columns = "2" columnsClasses = "alignmentRight">
<h:outputLink>... </h:outputLink>
<h:outputText/>
<h:outputLink>... </h:outputLink>
<h:outputText/>
</h:panelGrid>
</h:panelGroup>
</h:panelGrid>
.alignmentRight {
text-align : right;
}

Try this out, there was a typing mistake in your coding as well, its the first h:panelGrid 's column you have typed "columnus"
Inside <h:head> the style sheet must be declared.
<h:head>
<h:outputStylesheet name="styles.css"
library="css" />
</h:head>
then in <h:body>
<h:body>
<h:panelGrid columns="2" width="600">
<h:panelGroup>
<h:panelGrid columns="2" columnClasses="alignmentLeft" width="200">
<h:outputLink>...1 </h:outputLink>
<h:outputLink>...2 </h:outputLink>
</h:panelGrid>
</h:panelGroup>
<h:panelGroup>
<h:panelGrid columns="2" columnClasses="alignmentRight" width="200">
<h:outputLink>...3 </h:outputLink>
<h:outputLink>...4 </h:outputLink>
</h:panelGrid>
</h:panelGroup>
</h:panelGrid>
</h:body>
In style sheet (styles.css) the styles are,
.alignmentLeft {
text-align : left;
border: 1px solid black;
background-color: orange;
}
.alignmentRight {
text-align : right;
border: 1px solid black;
background-color: lime;
}

Related

StreamedContent not getting populated beyond RENDER_RESPONSE [duplicate]

This question already has answers here:
Display dynamic image from database or remote source with p:graphicImage and StreamedContent
(4 answers)
Backing beans (#ManagedBean) or CDI Beans (#Named)?
(5 answers)
Closed 2 years ago.
I'm relatively new to JSF and Primefaces.
I'm trying to build a document viewer that would display tiff, jpeg and pdf.
My UI has a left and a right layout.
Left layout contains a vertical grid of thumbnails of the docs.
User clicks on a thumbnail, and the right layout displays the doc (either via a p:graphicImage or via a p:documentViewer, depending on the thumbnail clicked).
For tiffs, I'm converting the image into PNG and then displaying (both, for the thumbnail and the main display).
For multi-page tiff files, I show only the first page as the left side thumbnail...and for the main display, I give Next and Previous buttons to navigate through the pages. The UI is something like this:
The problem:
When I click on the thumbnails, the backing method gets invoked twice as expected (the second call returning the StreamedContent with the actual data).
However, when I click the Prev and Next buttons, the same backing method is getting called only once -- just for phaseid=RENDER_RESPONSE.
(eventually, this causes the bean method to return only an empty StreamedContent and not one carrying the actual image data...so I don't get to see the other pages of the tiff)
The form:
<h:form id="mainform">
<p:layout fullPage="true" style="width:100%;height:100%">
<p:layoutUnit position="west" style="width:15%;overflow:scroll;" resizable="true">
<p:panelGrid header="Thumbnails" columns="1" class="thumbcell" >
<p:repeat value="#{viewerController.docIds}" var="docId">
<p:panelGrid style="padding:0px !important;" columns="1" rendered="#{docId.contains('img')}" >
<p:commandLink update=":mainform:renderpanel" action="#{viewerController.setSelectedDocId(docId)}">
<p:graphicImage value="#{viewerController.imageDocumentStream}" style="height: 100px; width: 90px; border: none !important; padding:0px;background: lightgrey;"
alt="#{viewerController.getDocumentName(docId)}">
<f:param name="id" value="#{docId}" />
</p:graphicImage>
</p:commandLink>
<p:outputLabel value="#{viewerController.getDocumentName(docId)}"/>
</p:panelGrid>
<p:panelGrid style="padding:0px !important;" columns="1" rendered="#{docId.contains('tif')}">
<p:commandLink update=":mainform:renderpanel" action="#{viewerController.setSelectedDocId(docId)}">
<p:graphicImage value="#{viewerController.tifDocumentStream}" style="height: 100px; width: 90px; border: none !important; padding:0px;background: lightgrey;"
alt="#{viewerController.getDocumentName(docId)}">
<f:param name="id" value="#{docId}" />
<f:param name="forThumbnail" value="true" />
</p:graphicImage>
</p:commandLink>
<p:outputLabel value="#{viewerController.getDocumentName(docId)}"/>
</p:panelGrid>
<p:panelGrid style="padding:0px !important;" columns="1" rendered="#{docId.contains('pdf')}">
<p:commandLink update=":mainform:renderpanel" action="#{viewerController.setSelectedDocId(docId)}">
<p:graphicImage value="#{viewerController.pdfFirstPageDocumentStream}" style="height: 100px; width: 90px; border: none !important; padding:0px;background: lightgrey;"
alt="#{viewerController.getDocumentName(docId)}">
<f:param name="id" value="#{docId}" />
</p:graphicImage>
</p:commandLink>
<p:outputLabel value="#{viewerController.getDocumentName(docId)}"/>
</p:panelGrid>
</p:repeat>
</p:panelGrid>
</p:layoutUnit>
<p:layoutUnit position="center" style="width:85%;">
<p:panel id="renderpanel">
<p:panelGrid style="padding:0px !important;" columns="1" rendered="#{viewerController.currentDocId.contains('tif')}">
<p:outputLabel value="#{viewerController.getDocumentName(viewerController.currentDocId)}"/>
<p:panelGrid style="padding:0px !important;" columns="3" id="tifPanelGrid">
<p:commandButton update=":mainform:renderpanel" action="#{viewerController.navigateTif('prev', viewerController.currentDocId)}"
id="prevButton" value="Prev" title="Previous page" disabled="#{viewerController.prevButtonDisable}"/>
<p:graphicImage rendered="#{viewerController.render}" id="tifPanel" value="#{viewerController.tifDocumentStream}" style="height: 600px; width: 800px; border: none !important; padding:0px;background: lightgrey;"
alt="#{viewerController.getDocumentName(viewerController.currentDocId)}">
<f:param name="id" value="#{viewerController.currentDocId}" />
<f:param name="forThumbnail" value="false" />
</p:graphicImage>
<p:commandButton update=":mainform:renderpanel" action="#{viewerController.navigateTif('next', viewerController.currentDocId)}"
id="nextButton" value="Next" title="Next page" disabled="#{viewerController.nextButtonDisable}"/>
</p:panelGrid>
</p:panelGrid>
<p:panelGrid style="padding:0px !important;" columns="1" rendered="#{viewerController.currentDocId.contains('img')}">
<p:outputLabel value="#{viewerController.getDocumentName(viewerController.currentDocId)}"/>
<p:graphicImage value="#{viewerController.imageDocumentStream}" style="height: 600px; width: 800px; border: none !important; padding:0px;background: lightgrey;"
alt="#{viewerController.getDocumentName(viewerController.currentDocId)}">
<f:param name="id" value="#{viewerController.currentDocId}" />
</p:graphicImage>
</p:panelGrid>
<p:panelGrid style="padding:0px !important;" columns="1" rendered="#{viewerController.currentDocId.contains('pdf')}">
<p:outputLabel value="#{viewerController.getDocumentName(viewerController.currentDocId)}"/>
<pe:documentViewer height="600" width="800" value="#{viewerController.pdfDocumentStream}" >
<f:param name="id" value="#{viewerController.currentDocId}" />
</pe:documentViewer>
</p:panelGrid>
</p:panel>
</p:layoutUnit>
</p:layout>
</h:form>
The controller class is annotated with these two:
javax.annotation.ManagedBean
javax.enterprise.context.SessionScoped
The backing method in the controller class, that is not getting invoked twice:
public StreamedContent getTifDocumentStream() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE ) {
return new DefaultStreamedContent();
} else {
String id = context.getExternalContext().getRequestParameterMap().get("id");
String forThumbnail = context.getExternalContext().getRequestParameterMap().get("forThumbnail");
Doc doc = tifDocMap.get(id);
InputStream is = this.convertTiffToPng(doc, forThumbnail);
return new DefaultStreamedContent(is);
}
}
I'm on this combination: SpringBoot + JoinFaces + PF 6.2
Can any body please advise what I'm doing wrong?
An alternate way I'm considering, to achieve the purpose:
May be, turn the pages of the tiff to individual PNGs beforehand, and then use galleria ...but it would be nice if I could get galleria to work with StreamedContent of each page dynamically.

How can I move a panel's position to the top in my JSF application?

I have a panelGrid with two columns - each one of them with a panel. Both panels have dataTables and are side by side.
<h:panelGrid id="png31" columns="2">
<p:panel id="pnlCab" header="Cabecera">
<p:commandButton value="Nueva actividad" type="button" id="actiNue" onclick="PF('wdlgAgregar').show()"/>
<br /> <br />
<p:dataTable id="dataCabecera" value="#{cargaHorariaController.listaActivDoc}">
<!-- Elements -->
</p:dataTable>
</p:panel>
<p:panel id="pnlDet" header="Detalle">
<p:commandButton value="Nueva subactividad" type="button" id="subactiNue" onclick="PF('wdlgAgregarS').show()">
<p:ajax update="cmbSubNue" listener="#{cargaHorariaController.cargarSubactividades()}" />
</p:commandButton>
<br /> <br />
<p:dataTable id="dataDetalle" value="#{cargaHorariaController.listaSubactividad}">
<!-- Elements -->
</p:dataTable>
</p:panel>
When the datatables are empty, both panels are at the top, but when one of them displays records, the panel with the empty dataTable aligns vertically to the middle of the panel with the filled dataTable.
What can I do so both panels are always at the top, even with filled dataTables?
Try:
<style type="text/css">
.my-style td{
vertical-align: text-top !important;
}
</style>
<h:panelGrid id="png31" columns="2" columnClasses="width: 40%, width: 60%"
styleClass="my-style" >
<p:panel>
........
</p:panel>
.......
.......
.......
</h:panelGrid>
Add CSS classes:
.col1 {
width: 40%;
vertical-align: top;
}
.col2 {
width: 60%;
vertical-align: top;
}
and change
<h:panelGrid id="png31" columns="2" columnClasses="col1, col2">

primefaces datatable filter selectCheckboxMenu with bootsfaces

I am using the primefaces datatable with bootsfaces, and there is a CSS conflict that I would like to work around.
Implementing the filter example from the primefaces showcase:
http://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml
gives me this result:
datatable filter example good
However, adding a bootsfaces component to the page, eg (the only change is to add an empty <b:inputtext> element):
<?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://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:b="http://bootsfaces.net/ui"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<b:inputText></b:inputText>
<p:dataTable var="car" value="#{dtFilterView.cars}" widgetVar="carsTable"
emptyMessage="No cars found with given criteria" filteredValue="#{dtFilterView.filteredCars}">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter" onkeyup="PF('carsTable').filter()" style="width:150px" placeholder="Enter keyword"/>
</p:outputPanel>
</f:facet>
<p:column filterBy="#{car.id}" headerText="Id" footerText="contains" filterMatchMode="contains">
<h:outputText value="#{car.id}" />
</p:column>
<p:column filterBy="#{car.year}" headerText="Year" footerText="lte" filterMatchMode="lte">
<f:facet name="filter">
<p:spinner onchange="PF('carsTable').filter()" styleClass="year-spinner">
<f:converter converterId="javax.faces.Integer" />
</p:spinner>
</f:facet>
<h:outputText value="#{car.year}" />
</p:column>
<p:column filterBy="#{car.brand}" headerText="Brand" footerText="exact" filterMatchMode="exact" filterStyle="width: 100px">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('carsTable').filter()" >
<f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{dtFilterView.brands}" />
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{car.brand}" />
</p:column>
<p:column filterBy="#{car.color}" headerText="Color" footerText="in" filterMatchMode="in" filterStyle="margin-bottom 0px">
<f:facet name="filter">
<p:selectCheckboxMenu label="Colors" onchange="PF('carsTable').filter()" panelStyle="width:125px" scrollHeight="150">
<f:selectItems value="#{dtFilterView.colors}" />
</p:selectCheckboxMenu>
</f:facet>
<h:outputText value="#{car.color}" />
</p:column>
<p:column filterBy="#{car.sold}" headerText="Status" footerText="equals" filterMatchMode="equals">
<f:facet name="filter">
<p:selectOneButton onchange="PF('carsTable').filter()">
<f:converter converterId="javax.faces.Boolean" />
<f:selectItem itemLabel="All" itemValue="" />
<f:selectItem itemLabel="Sold" itemValue="true" />
<f:selectItem itemLabel="Sale" itemValue="false" />
</p:selectOneButton>
</f:facet>
<h:outputText value="#{car.sold ? 'Sold': 'Sale'}" />
</p:column>
<p:column filterBy="#{car.price}" headerText="Price" footerText="custom (min)" filterFunction="#{dtFilterView.filterByPrice}">
<h:outputText value="#{car.price}">
<f:convertNumber currencySymbol="$" type="currency"/>
</h:outputText>
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
gives this result:
primefaces datatable filter style error
The dropdown box for the filters has its margin changed, causing the down arrow to not be in the correct position. The text is also reduced to 0.85.
Is there a way that I can combine bootsfaces with primefaces datatable and maintain the primefaces drop-down menu formatting?
Thanks Stephan - great work on bootsfaces btw, it's a lot of fun to program with.
Your changes didn't quite match the primefaces example on my system, but they were an improvement, and gave me a good insight into how to make my own changes.
Using these style overrides worked better on my system:
<style>
.ui-widget {
font-size: 16px !important;
}
.ui-selectcheckboxmenu-label {
margin-bottom: 0px;
}
.ui-selectcheckboxmenu-trigger {
width: auto !important;
}
.ui-selectonemenu-trigger {
width: auto !important;
}
.ui-selectcheckboxmenu-label {
font-weight: normal !important;
}
label{
font-weight: normal !important;
}
body {
line-height: 18px !important;
}
</style>
It's not perfect yet, but adding these few lines of CSS code make the BootsFaces version look almost perfectly like the original, PrimeFaces-only version:
<h:head>
<title>Facelet Title</title>
<style>
.ui-widget {
font-size: 17.6px !important;
}
* {
-webkit-box-sizing: content-box !important;
-moz-box-sizing: content-box !important;
box-sizing: content-box !important;
}
*:before, *:after {
-webkit-box-sizing: content-box !important;
-moz-box-sizing: content-box !important;
box-sizing: content-box !important;
}
body {
margin: 8px !important;
}
</style>
</h:head>
However, most of these settings might affect the BootsFaces components. Setting the font size to 0.85 is almost certainly a bug in BootsFaces, which we're going to solve, but the other settings look like different approaches to resetting the CSS default settings of the browser. In other words: fixing the look and feel of complex PrimeFaces component might ruin the look and feel of BootsFaces components.

p:commandButton actionListener method is called multiple times

Action listener method is called multiple times after clicking <p:commandButton>.
Bean declaration and code of called method
#Named(value = "planovaniBean")
#SessionScoped
public class PlanovaniBean implements Serializable{
public void naplanuj(ActionEvent e){
//some local var def
//retrieving data from db
uzavriDB();
Slouzici seznamSlouzicich = nactiSlouzici();
poradiSD = dejPoradiSluzbodnu(seznamSlouzicich);
//searching result
while(vysledek == null){
vysledek = naplanuj(mezPresMiru<2?2:25,mezPresMiru, mezPaSoNe, mezSv,seznamSlouzicich, poradiSD,true);
//changing mez...
}
//searching for better result
mezPresMiru=vysledek.getMaxsluzebpresmiru();
float minulaPresMiru = mezPresMiru;
while(true){
boolean ukonci = true;
SluzboDen pom = naplanuj(25,mezPresMiru, mezPaSoNe, mezSv, seznamSlouzicich, poradiSD,true);
if (pom != null){
vysledek = pom;
ukonci = false;
}
if(ukonci) break;
minulaPresMiru = mezPresMiru;
mezPresMiru = vysledek.getMaxsluzebpresmiru();
}
//searching for better result using differ algo
mezPresMiru = minulaPresMiru+(float)0.01;
while(true){
boolean ukonci = true;
SluzboDen pom = naplanuj(25,mezPresMiru, mezPaSoNe, mezSv, seznamSlouzicich, poradiSD,false);
if (pom != null){
vysledek = pom;
ukonci = false;
}
if(ukonci) break;
mezPresMiru = vysledek.getMaxsluzebpresmiru();
}
vypisKolik(vysledek,seznamSlouzicich);//just printing some output
navrhSluzeb = vysledek;
naplanovano = true;
vPlanovani = false;
}
callled from:
<ui:composition template="/common/index.xhtml">
<ui:define name="title">
<h:outputText value="#{bundle.ListPozadavkyTitle}"></h:outputText>
</ui:define>
<ui:define name="body">
<h:form id="PozadavkyListForm" style="font-size: 92% !important;">
<p:remoteCommand name="rc_mousedown" actionListener="#{pozadavkyBean.vyberZacatek()}"/>
<p:remoteCommand name="rc_mouseup" actionListener="#{pozadavkyBean.vyberKonec()}"/>
<p:dataTable id="datalist" value="#{pozadavkyBean.pozadavkyNaMesic}" var="item"
rowKey="#{item[0]}"
rowIndexVar="rowIndex"
>
<f:facet name="header">
<p:outputLabel style="font-weight: bold; font-size: 110% !important;" id="headerMesic" value="#{pozadavkyBean.proMesic()} - Úprava požadavků"/>
</f:facet>
<p:columns id="sloupce" value="#{pozadavkyBean.columns}" var="column" columnIndexVar="colIndex"
width="#{pozadavkyBean.sirkaSloupce(colIndex)}"
style=" background-color: #{pozadavkyBean.cellColor(colIndex)}; padding-bottom: 0 !important; padding-top: 0 !important;">
<f:facet name="header">
<h:outputText value="#{colIndex == 0? 'X':column.header}" style="color: #{colIndex == 0? '#dfeffc':'#2e6e9e'}; font-size: #{colIndex == 0? '150%':'%92'} !important"/>
</f:facet>
<p:outputLabel value="#{item[colIndex]}" style="width:100%; color: #000000; " rendered="#{pozadavkyBean.renderedCellvII(colIndex, item[colIndex], 1)}" onmousedown="rc_mousedown([{name:'jmeno',value:#{rowIndex}},{name:'den',value:#{colIndex}}])" onmouseup="rc_mouseup([{name:'jmeno',value:#{rowIndex}},{name:'den',value:#{colIndex}}])"/>
<p:outputLabel value="#{item[colIndex]}" style="width:100%; color: #000000" rendered="#{pozadavkyBean.renderedCellvII(colIndex, item[colIndex], 3)}"/>
<p:outputLabel value="______" style="width:100%; margin-left: -10px; font-size: 150% !important; color: #{pozadavkyBean.cellColor(colIndex)}" rendered="#{pozadavkyBean.renderedCellvII(colIndex, item[colIndex], 2)}" onmousedown="rc_mousedown([{name:'jmeno',value:#{rowIndex}},{name:'den',value:#{colIndex}}])" onmouseup="rc_mouseup([{name:'jmeno',value:#{rowIndex}},{name:'den',value:#{colIndex}}])"/>
<p:outputLabel value="X" style="font-size: 150% !important; color: #{pozadavkyBean.cellColor(colIndex)}" rendered="#{colIndex == 0? 'True':'False'}"/>
<f:facet name="footer">
<h:outputText value="#{colIndex == 0? 'X':column.header}" style="color: #{colIndex == 0? '#dfeffc':'#2e6e9e'}; font-size: #{colIndex == 0? '150%':'%92'} !important"/>
</f:facet>
</p:columns>
</p:dataTable>
<p:contextMenu id="cmenu" for="PozadavkyListForm">
<p:menuitem value="X" actionListener="#{pozadavkyBean.ulozPozadavky('X')}" update="datalist"/>
<p:menuitem value="ŘD" actionListener="#{pozadavkyBean.ulozPozadavky('ŘD')}" update="datalist"/>
<p:menuitem value="SC" actionListener="#{pozadavkyBean.ulozPozadavky('SC')}" update="datalist"/>
<p:menuitem value="SV" actionListener="#{pozadavkyBean.ulozPozadavky('SV')}" update="datalist"/>
<p:menuitem value="LK" actionListener="#{pozadavkyBean.ulozPozadavky('LK')}" update="datalist"/>
<p:menuitem value="LD" actionListener="#{pozadavkyBean.ulozPozadavky('LD')}" update="datalist"/>
<p:menuitem value="SK" actionListener="#{pozadavkyBean.ulozPozadavky('SK')}" update="datalist"/>
<p:menuitem value="SD" actionListener="#{pozadavkyBean.ulozPozadavky('SD')}" update="datalist"/>
<p:menuitem value="Vynulovat" actionListener="#{pozadavkyBean.ulozPozadavky('')}" update="datalist"/>
</p:contextMenu>
</h:form>
<br/>
<br/>
<h:form id="PozadavkyListFormCalendar" style="font-size: 92% !important;">
<p:remoteCommand name="rc_mousedownII" actionListener="#{planovaniBean.vyberZacatek()}"/>
<p:remoteCommand name="rc_mouseupII" actionListener="#{planovaniBean.vyberKonec()}"/>
<p:dataTable id="dnySvozu" value="#{planovaniBean.dnySvozu}" var="item"
rowKey="#{item[0]}"
rowIndexVar="rowIndex"
>
<f:facet name="header">
<p:outputLabel style="font-weight: bold; font-size: 110% !important;" id="headerMesic" value="#{pozadavkyBean.proMesic()} - svoz do Líní"/>
</f:facet>
<p:columns id="sloupce" value="#{planovaniBean.columns}" var="column" columnIndexVar="colIndex"
width="#{pozadavkyBean.sirkaSloupce(colIndex)}"
style=" background-color: #{pozadavkyBean.cellColor(colIndex)}; padding-bottom: 0 !important; padding-top: 0 !important;">
<f:facet name="header">
<h:outputText value="#{colIndex == 0? 'X':column.header}" style="color: #{colIndex == 0? '#dfeffc':'#2e6e9e'}; font-size: #{colIndex == 0? '150%':'%92'} !important"/>
</f:facet>
<p:outputLabel value="#{item[colIndex]?'✔':'_____'}"
style="width:100%; #{item[colIndex]?'':'margin-left: -10px; font-size: 150% !important'};color: #{item[colIndex]?'#000000':pozadavkyBean.cellColor(colIndex)}"
onmousedown="rc_mousedownII([{name:'jmeno',value:#{rowIndex}},{name:'den',value:#{colIndex}}])"
onmouseup="rc_mouseupII([{name:'jmeno',value:#{rowIndex}},{name:'den',value:#{colIndex}}])"
rendered="#{colIndex == 0?'false':'true'}"
/>
<p:outputLabel value="CHRA"
rendered="#{colIndex == 0?'true':'false'}"
style="width:100%; color: #{pozadavkyBean.cellColor(colIndex)}"
/>
</p:columns>
</p:dataTable>
<p:contextMenu id="cmenuII" for="PozadavkyListFormCalendar">
<p:menuitem value="Jede" actionListener="#{planovaniBean.nastavSvoz(true)}" update="dnySvozu"/>
<p:menuitem value="Vynulovat" actionListener="#{planovaniBean.nastavSvoz(false)}" update="dnySvozu"/>
</p:contextMenu>
</h:form>
<br/>
<h:form id="planovani">
<p:commandButton value="Naplánuj" actionListener="#{planovaniBean.naplanuj}" id="btNaplanuj"
onclick="PF('dlg').show()"/>
</h:form>
</ui:define>
</ui:composition>
template:
<h:body>
#{loggedBean.prechodNeprihlasen()}
<p:growl id="growl" life="3000" />
<p:dialog position="center" widgetVar="dlg"
header="Plánuji..."
resizable="false"
closable="false"
draggable="false"
modal="true">
<h:form>
<p:inputTextarea id="txt_area" rows="25" cols="70" disabled="true" value="#{planovaniBean.text}"
style=" background-color: #ffffff; color: #000000" autoResize="false"/>
<br/>
<p:button id="tlacitko" disabled="#{planovaniBean.naplanovano?'False':'True'}" value="Kontrola"
onclick="PF('dlg').hide()" outcome="/scheduler/pozadavky/kontrola"/>
<p:commandButton id="tlacitko1" disabled="#{planovaniBean.nenaplanovano?'False':'True'}" value="OK"
onclick="PF('dlg').hide()"/>
<p:poll interval="1" update="txt_area tlacitko tlacitko1" async="True"/>
</h:form>
</p:dialog>
<p:layout fullPage="true">
<p:layoutUnit position="west" size="210" header="" collapsible="true">
<h:form>
<p:menu>
<p:submenu label="Administrace" rendered="#{loggedBean.loggedAsAdmin}">
<p:menuitem value="Uživatelé" />
<p:menuitem value="Odstranění uživatele"/>
<p:menuitem value="Změna uživatele"/>
</p:submenu>
<p:submenu label="Plánování" rendered="#{loggedBean.logged}">
<p:menuitem value="Administrace sloužících" rendered="#{loggedBean.loggedAsScheduler}" />
<p:menuitem value="Požadavky" rendered="#{loggedBean.loggedAsBFU}" outcome="/users/pozadavky/List"/>
<p:menuitem value="Naplánuj" rendered="#{loggedBean.loggedAsScheduler}" outcome="/scheduler/pozadavky/prechodPlan"/>
<p:menuitem value="Změna služby" rendered="#{loggedBean.loggedAsScheduler}"/>
</p:submenu>
<p:submenu label="Přehledy" rendered="#{loggedBean.logged}">
<p:menuitem value="Služby" />
<p:menuitem value="Statistiky"/>
<p:menuitem value="Rozkazy" />
</p:submenu>
<p:submenu label="Osobní" rendered="#{loggedBean.logged}">
<p:menuitem value="Osobní údaje" />
<p:menuitem value="Změna hesla" outcome="/common/zmenahesla"/>
<p:menuitem value="Odhlásit" action="#{logoutBean.logout()}" />
</p:submenu>
</p:menu>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center" id="centerPanel">
<ui:insert name="body"/>
</p:layoutUnit>
</p:layout>
</h:body>
I don't know what to add to describe the problem better. have allready read almost all articles about multible calling getters but don't think this is my problem.
It's extremely confusing reading code in your language, can you please post the relevant parts in english? I have no clue what your methods or variables do or mean.
Upon further inspection I see that you are calling your action method multiple times within your action method. That is why it is being called multiple times.
EDIT: Forget what I said, another user pointed out that it's not the same method, which is true ofcourse.

jsf dynamically loaded content is not working

I'm trying to offer some content dynamically, that is without dedicated pages, with the help of buttons. The aforementioned content is correctly loaded, but it's not working.
The layout is like this:
<p:outputPanel style="width: 100%; height: 100%; overflow: auto;" id="contentPanel">
<c:choose>
<c:when test="#{empty requestComposition}">
<ui:insert name="body">Content</ui:insert>
</c:when>
<c:otherwise>
<ui:include src="#{requestComposition}" />
</c:otherwise>
</c:choose>
</p:outputPanel>
The button to load content is like this (inside another outputPanel):
<p:commandButton value="Load Dynamic" update=":contentPanel" actionListener="#{applicationController.processActionButton('/dynamic')}" />
The action listener is like this:
public void processActionButton(String target){
if(target == null || target.isEmpty()){
return;
}
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest req = (HttpServletRequest)context.getExternalContext().getRequest();
req.setAttribute("requestComposition", "/WEB-INF/templates" + target + ".xhtml");
}
The dynamic.xhtml is like this:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions">
<p:outputPanel style="width: 100%; padding-top: 20px;">
<p:outputPanel style="width: 60%; margin: 0 auto;">
<p:outputPanel style="text-align: center; color: gold; font-weight: bold;">Dynamic</p:outputPanel>
<p:messages id="messages" />
<h:form>
<p:panelGrid columns="2" style="width: 100%;">
<p:outputLabel value="Item" for="idItem" />
<p:outputPanel style="display: block; padding-right: 10px;" layout="inline">
<p:inputText value="#{bean.item}" id="idItem" style="width: 100%;" required="true" />
</p:outputPanel>
</p:panelGrid>
<p:outputPanel style="text-align: center;">
<p:commandButton value="Process" style="margin: 5px;" update=":growl" onclick="PrimeFaces.widgets.widget_#{fn:replace(component.clientId, ':', '_')}.disable()" oncomplete="PrimeFaces.widgets.widget_#{fn:replace(component.clientId, ':', '_')}.enable()" actionListener="#{applicationController.dummyAction}" />
<p:commandButton value="Dummy" style="margin: 5px;" update=":growl" actionListener="#{applicationController.dummyAction}" process="#this" />
</p:outputPanel>
</h:form>
</p:outputPanel>
</p:outputPanel>
</ui:composition>
When any of the buttons is clicked the form apparently submits, but the action listener is not executed.
When dynamic.xhtml is loaded as page content the form submits, but the action listener is triggered only for the second button (labelled Dummy), because of process #this, in which case the form is no longer submitted. I can workaround the form not submitting with process#this by adding onchange to input elements, but I failed to understand why is not working when it is loaded dynamically.
Thank you
I have to apologize to BalusC, since the answer he suggested was actually correct. I was tricked by the #PostConstruct which performed an unnecessary initialization for me, but the key is to use a #ViewScoped bean. That however raises another question, since it is stated in the documentation that by default there will be maximum 20 such objects stored in the server, which can be configured to a different value, but if I understood correctly that would mean that the 21st connection to the server will result in reusing the first one, so the new connection will access data not meant for it, or in discarding it and creating a new one, which means the first will lose its data?

Resources