I am trying to write some JSF code that centers an image in a panel grid. The simple approach would appear to be:
<h:panelGrid columns="1" style="text-align:center">
<h:graphicImage value="/path/to/image.png" />
</h:panelGrid>
but this approach does not seem to work.
Use div with align=center
Or use CSS:
JSF
<h:panelGrid styleClass="centered">
...
</h:panelGrid>
CSS
.centered {
margin: 0px auto;
}
Related
For example, I am trying to update total price in a panelgrid once am clicking on another panelgrid.
<c:forEach items="#{coinsBean.selectedCountryVo.selectedGameVo.operatorGamePackageVos}" var="operatorGamePackageVo" >
<h:panelGrid id="pack_#{operatorGamePackageVo.id}"
styleClass="bord"
style="border:solid #cbcbcb; margin: 4vmin; min-width: -webkit-fill-available;text-align: center;border-radius: 2vmin;"
onclick="selectUcs(this.id);"
>
<p:commandLink style="border-radius: 2vmin; padding: 2vw;background-size: 4vmin;text-align: center;font-family: 'Cairo', sans-serif "
update="totalSelected" action="#{coinsBean.selectOperatorGamePackageVo(operatorGamePackageVo)}"
value="#{operatorGamePackageVo.packageName}"
/>
</h:panelGrid>
</c:forEach>
<h:panelGrid columns="1" id="totalSelected" style="background-color: white;
padding-left: 5vh;border-radius: 0 0 1vh 1vh;margin-bottom: 2vh;width:95%;margin:auto;text-align: left ;">
<h:panelGrid>
<p id="total" style="color: #FE6D2C;font-size: 3.5vmin;font-family: 'Cairo', sans-serif;text-align: center;font-weight: bold;margin: auto;" dir="rtl">
price
</p>
<p id="total1" style="color: black;font-size: 3vw;font-family: 'Cairo', sans-serif;text-align: center;font-weight: bold;margin: auto" dir="rtl">
#{coinsBean.selectedCountryVo.selectedGameVo.selectedOperatorGamePackageVo.price}
</p>
</h:panelGrid>
</h:panelGrid>
once I click on the above one!
Solution
It isn't possible to add ajax to a h:panelGrid (see Explanation to see why).
Probably the best way to this would be using the h:commandScript (since JSF 2.3).
Just add this somewhere to your page:
<h:form>
<h:commandScript name="someFunction" render="totalSelected" />
</h:form>
Now when you want to update the panelGrid just execute someFunction().
In your case add this to your panelGrid that should update the other one:
<h:panelGrid ... onclick="someFunction();">
...
</h:panelGrid>
One could also use css (a bad hack) to stretch a h:commandLink to fit the whole panelGrid (I can add this on request).
Explanation
Basically every component (h:panelGrid, h:commandLink, etc.) you can use is a java class. But not every one can/should do the same things. If you want to use ajax behaviours with a component that specific component has to implement the ClientBehaviourHolder interface. This is reserved for action components like h:commandButton, h:inputText, h:commandScript, etc. . The h:panelGrid does not implement this interface.
I am currently developing an app with Primefaces and recently started using a Tree component. It exactly provide the functionality that I need but I have some problems while using it inside of a dialog. When there are many records I had to surround this tree with <p:outputPanel> in order to have scroll. Everything was fine until I added filtering to that tree component. Because of surrounded panel this filter input text appears right above the tree, inside of this panel and when I scroll this down, this filter input is left above on top.
Is there a possibility that I add manually a filter input above the whole panel and connect it to the tree like it is done for example in DataTable components of PrimeFaces? Tried that way yet it is not working. Below is .xhtml of my dialog. Any help would be appreciated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<ui:composition 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" xmlns:f="http://xmlns.jcp.org/jsf/core">
<p:dialog id="manageKnownDeviceDlg" header="#{msg['ip.usb.manageKnownDlg.Title']}" height="700"
showEffect="explode" resizable="true" modal="true" appendTo="#(body)"
width="700" widgetVar="manageKnownDeviceDlg" style="text-align: right;">
<h:form id="manageKnownDialogForm" >
<p:outputPanel style="width: 100%; max-height: 600px; min-height: 600px;height: 88%;overflow: auto;display: block; border: solid 1px;">
<p:tree id="manageKnownDevicesTree" var="knownDevice" value="#{baseModel.usbDeviceDictTreeRoot}"
widgetVar="usbDeviceDictTree"
selectionMode="checkbox" selection="#{baseModel.usbDeviceDictSelected}"
filterBy="#{knownDevice}" filterMatchMode="contains" emptyMessage="#{msg['global.noData']}"
style="text-align: left; width: 98%;">
<p:treeNode>
<h:outputText value="#{knownDevice.toString()}"/>
</p:treeNode>
</p:tree>
</p:outputPanel>
<br/>
<h:panelGrid columns="1" style="position: absolute; right: 5px;">
<h:panelGrid columns="5" style="margin-top: 10px;">
<p:commandButton value="#{msg['ip.usb.manageKnownDlg.Disable']}" update="manageKnownDevicesTree"
actionListener="#{knownDevicesDlgController.unselectKnownDeviceClasses}" styleClass="vs-button"
process="manageKnownDeviceDlg"/>
<p:commandButton value="#{msg['ip.usb.manageKnownDlg.YesToAll']}" update="manageKnownDevicesTree"
actionListener="#{knownDevicesDlgController.selectAllDevices}" styleClass="vs-button"
process="manageKnownDeviceDlg"/>
<p:commandButton value="#{msg['ip.usb.manageKnownDlg.NoToAll']}" update="manageKnownDevicesTree"
actionListener="#{knownDevicesDlgController.unselectAllDevices}" styleClass="vs-button"
process="manageKnownDeviceDlg"/>
<p:commandButton value="#{msg['global.ok']}" update="usbForm:usbDeviceTable,manageKnownDialogForm"
onclick="PF('manageKnownDeviceDlg').hide();" process="manageKnownDeviceDlg" styleClass="vs-button"
actionListener="#{knownDevicesDlgController.addKnownDevice}" style="text-align: right"/>
<p:commandButton value="#{msg['global.cancel']}" update="manageKnownDeviceDlg" styleClass="vs-button"
onclick="PF('manageKnownDeviceDlg').hide();"/>
</h:panelGrid>
</h:panelGrid>
</h:form>
</p:dialog>
</ui:composition>
Setting a max-height on the ui-tree-container solves the problem. Using this in the showcase
.ui-tree-container {
max-height: 70px;
}
Results in
You might want to add an explicit class to the tree and use that in the selector so it does not apply to all trees.
I am developing a project using primefaces.
In that, I used one p:panel(in user.xhtml page) inside the p:dialog and I set showHeader="false" to the p:dialog.
For that, I need to drag the p:dialog when I click and drag on the p:panel, which is included inside the p:dialog.
Sample Code:
<p:dialog showHeader="false">
<ui:include src="${model.dynamicPage}"/>
</p:dialog>
user.xhtml
<h:form id="userForm">
<p:panel header="UserPanel">
.......
</p:panel>
</h:form>
Any Idea?
Use the draggable component on a panel instead of a dialog
<p:panel id="pnl" header="UserPanel">
<ui:include src="${model.dynamicPage}"/>
</p:panel>
<p:draggable for="pnl" />
and define the panel dimensions with some css:
.ui-panel {
margin: 15px;
height: 200px;
width: 300px;
}
Edit: if there are several components in your model.dynamicPage facelet but you want the panel to be the only allowed to handle the dragging of the whole container, add a css class to it and restrict the draggable component handling with this class:
eg.
<p:panel id="pnl" showHeader="false">
<ui:include src="${model.dynamicPage}"/>
</p:panel>
<p:draggable for="pnl" handle=".my-handle-classname" />
and
<h:form id="userForm">
<p:panel header="UserPanel" styleClass="my-handle-classname">
.......
</p:panel>
</h:form>
I have the following code in a xhtml page using PrimeFaces:
<h:panelGroup id="dropZoneId" layout="block"
style="height:500px;width:1210px;text-align:center;">
<h:outputLabel value="Drop here" style= "color: azure;" />
</h:panelGroup>
I would like to have the <h:outputLabel> "drop here" in the middle of the <h:panelGroup> but so far I can only put it at the center at the top of the <h:panelGroup> with no css.
Can someone please help ? Thank you
Maybe this will suffice:
<h:panelGroup id="dropZoneId" layout="block" style="height: 500px; text-align: center">
<h:outputText value="Drop here" style="color: azure; position: absolute; top: 240px" />
</h:panelGroup>
.myLabel {
float: center;
}
Official Resource #Primefaces: https://forum.primefaces.org/viewtopic.php?t=14611
I have a dialog that contain
<p:dialog id="sqlDialog"
widgetVar="sqlWidgetVar"
header="SQL"
width="800"
position="center"
minimizable="true"
maximizable="true"
appendToBody="true"
dynamic="true">
<h:outputText id="sql"
escape="false"
value="#{bean.sql}"
style="color: green"/>
</p:dialog>
Since the text is very long I need to add a scroll option
How can I do it ?
Thanks
Use CSS to make it a block element with fixed dimensions and an overflow.
<h:outputText ... styleClass="sqlDialogText" />
with
.sqlDialogText {
display: block;
width: 600px; /* Optional, depends otherwise on parent. */
height: 300px;
overflow: auto;
color: green;
}
Alternatively, just give the dialog a fixed height.
<p:dialog ... height="300">
Note that this has nothing to do with JSF. It's just a HTML/CSS/JS code generator. The <h:outputText> generates a HTML <span> element. You just have to alter the CSS accordingly for the look'n'feel.