Maximize gmap in dialog primefaces - google-maps

I want to display a dialog which has a gmap as element, it works fine when I set height and width, but what I need is show it as maximized full screen map. The Dialog is shown in fullscreen, but map is empty, only when I back to default size it is shown.
My code is
<p:commandLink id="id" value="Modal" onclick="PF('dlg').show(); PF('dlg').toggleMaximize();"/>
<p:dialog appendTo="#(body)" id="dlg" widgetVar="dlg" maximizable="true" width="1920" height="1080">
<p:gmap id="gmap" center="41.381542, 2.122893" zoom="15" type="HYBRID" style="width:100%;height:100%;">
</p:gmap>
</p:dialog>
How can I solve my problem?

You can add following JavaScript on your page
<script>
function resizeElement(elementId,width,height){
console.log("Resizing element " + elementId + " W/H="+ width + "/" + height);
var element = document.getElementById(elementId);
element.style.width=width+"px";
element.style.height=height+"px"
}
function resizePfGmapInsideWrapperElement(wrapperElementId){
var wrapperElement=document.getElementById(wrapperElementId);
var width=wrapperElement.clientWidth-40;
var height=wrapperElement.clientHeight-60;
resizeElement("gmap",width,height);
}
function resizePfGmapInsideDialog(){
resizePfGmapInsideWrapperElement("dlg");
}
</script>
and then add resizePfGmapInsideDialog() into p:commandLink onclick
<p:commandLink id="id"
value="Modal"
onclick="PF('dlg').show(); PF('dlg').toggleMaximize(); resizePfGmapInsideDialog();"/>
Actually whenever you call PF('dlg').toggleMaximize(); also call resizePfGmapInsideDialog() right after and p:gmap will automatically resize inside dialog's content area.

Related

Primefaces: hide tooltip after scrolling on mobile devices

I have following implementation of tooltip in my xhtml
<p:column id="application-column--state" width="8%" style="min-width:auto"
headerText="#{msg['page.employee-applications.table.col.state']}">
<ui:repeat value="#{applicationEntry.statesList}" var="stateEntry">
<h:outputText id="confiurationDocumentForProgramTooltip" escape="false"
styleClass="#{stateEntry.styleClass} -margin-right-5 -inline-flex"/>
<p:tooltip id="confiurationDocumentForProgramTooltipText" escape="false"
for="confiurationDocumentForProgramTooltip" showDelay="0"
value="#{msg[stateEntry.key]}" trackMouse="false"/>
</ui:repeat>
</p:column>
And i have problem with hiding this tooltip on mobile devices during scrolling.
This situation can be observed on tooltip showcase https://www.primefaces.org/showcase/ui/overlay/tooltip/tooltipOptions.xhtml?jfwid=984b1 on mobile view in developers tools on Chrome.
I tried to avoid this situation with js:
$(document).ready(function (){
hideTooltipAfterScroll()
});
function hideTooltipAfterScroll() {
$("#scrollbar_container").add(window).scroll(function () {
$( ".ui-tooltip:visible" ).css({
"z-index" : "",
"display" : "none"
});
})
}
now tooltip is gone after 'touch' scroll, but I cannot reopen closed tooltip.
Do You have any ideas how to achieve closing on scrolling with posibility to reopen closed tooltip?
I would not try to hack the tooltips to be hidden, instead use their JavaScript widget to hide them.
You can hide each tooltip widget on the page like:
PrimeFaces.getWidgetsByType(PrimeFaces.widget.Tooltip).forEach(
function(tooltip){
tooltip.hide();
}
);
See the widget documentation: https://primefaces.github.io/primefaces/jsdocs/classes/src_PrimeFaces.PrimeFaces.widget.Tooltip-1.html

Making p:editor in a p:dialog fit the dialogs size

I have an p:editor inside a p:dialog. The dialog is dragable and I want the editor to fill all the available space of the dialog. I don't know if this is purely a HTML/CSS problem or if this has something to do with the JSF components I am using. Regarding width, this works fine when I set width: 100% in my child container. When I try the same with height: 100%, it has no effect. Here is my code:
<h:form id="frmNote">
<p:dialog id="dlgNote" widgetVar="dlgNote"
header="Note"
position="right"
style="height: 500px; width: 500px;"
dynamic="false" modal="false"
fitViewport="false" resizable="true"
closable="true" closeOnEscape="true"
onHide="$('#frmNote\\:quit').click();">
<p:hotkey bind="esc" handler="PF('dlgNote').hide();" />
<p:editor id="noteEditor" widgetVar="noteEditor"
value="#{backenbean.text}"
style="vertical-align: top; width: 100%; height: 100%"
controls="bold italic underline strikethrough font size color highlight bullets numbering undo redo">
</p:editor>
</p:dialog>
</h:form>
Basically, the issue is that the resource dependency "editor.js" from primefaces library, has a default height of 250px:
#ResourceDependencies({
#ResourceDependency(library = "primefaces", name = "editor/editor.css"),
#ResourceDependency(library = "primefaces", name = "jquery/jquery.js"),
#ResourceDependency(library = "primefaces", name = "jquery/jquery-plugins.js"),
#ResourceDependency(library = "primefaces", name = "core.js"),
#ResourceDependency(library = "primefaces", name = "components.js"),
#ResourceDependency(library = "primefaces", name = "editor/editor.js")
})
public class Editor extends EditorBase {
public static final String COMPONENT_TYPE = "org.primefaces.component.Editor";
}
editor.js =>
(function(F){F.cleditor={defaultOptions:{width:"auto",height:250, ...
To use the height of the parent dialog, I included the style:"height: inherit" in the Editor primefaces component as follows:
<p:editor id="noteEditor" widgetVar="noteEditor" style="height: inherit"
value="#{exampleBean.text}"
controls="bold italic underline strikethrough font size color highlight bullets numbering undo redo">
</p:editor>
and included a Javascript function to modify the height from 250px to inherit in the div generated by primefaces (based on your code) when the dialog is showed:
<p:dialog id="dlgNote" widgetVar="dlgNote"
header="Note"
position="right"
minWidth="500" onShow="document.getElementById('noteEditor').getElementsByClassName('ui-editor ui-widget-content')[0].setAttribute('style', 'width: auto; height: inherit');"
minHeight="500"
dynamic="false" modal="false"
fitViewport="false" resizable="true"
closable="true" closeOnEscape="true"
onHide="$('#frmNote\\:quit').click();">
<p:hotkey bind="esc" handler="PF('dlgNote').hide();" />
<p:editor id="noteEditor" widgetVar="noteEditor" style="height: inherit"
value="#{exampleBean.text}"
controls="bold italic underline strikethrough font size color highlight bullets numbering undo redo">
</p:editor>
</p:dialog>
and the result:

How to display HEIGHT variable FIX header panel using JSF and Primefaces?

I use Primefaces 6.2 <p:layout> to display a FIX header (that is always displayed on top of page).
But the header sometimes is to high and I need reduce it DYNAMICALLY.
I decide to replace Header panel with a toggleable panel like this
<p:layout id="PageLayout" fullPage="true">
<p:layoutUnit position="north">
<p:panel id="TitlePanel" toggleable="true" header="Title">
<p:ajax event="toggle" update=":PageLayout"/>
</panel>
... others panels with context, status, date, time, etc ...
</p:layoutUnit>
<p:layoutUnit id="ContentBloc" position="center">
... web page with specific data
</p:layoutUnit>
</p:layout>
This work well except that the position of the ContentBloc is never updated.
When I click on toggle Button, the content of header's panel is hidden but the vertical position of the ContentBloc is never changed !
I used update attribute in <p:ajax> element but this has no effect.
Question: How can I do to UPDATE ContentBloc position ?
Remark: On Chrome, if after having clicked on Toggle button, I load Developer Console, the display is immediately correct !
Remark: if in maximize my Chrome Windows the display is also correct !
After searching a lot, I have found the following tricky solution
<div id="PageHeader" style="position:absolute; left:0; top:0; width:100%;">
<p:panel id="TitlePanel" toggleable="true">
<p:ajax event="toggle" oncomplete="toggleTitlePanel()"/>
<f:facet name="header">
<p:outputLabel value="#{pageTitle}" escape="false" style="font-size:200%;"/>
</f:facet>
... others panels with context, status, date, time, etc ...
</p:panel>
</div>
<div id="ContentPanel" style="position:fixed;
left:0;
overflow-x:auto;
overflow-y:auto;
">
... web page with specific data
</div>
For this code to work, I have
added "toggle" event to position ContentPanel.
added some JQuery event when page is loaded
The javascript code linked to toggle event is the following
function fixHeaderHeight()
{
var iHeight = document.getElementById("PageHeader").offsetHeight;
document.getElementById("ContentPanel").style.top = iHeight + "px";
}
function toggleTitlePanel()
{
setTimeout(function(){ fixHeaderHeight(); }, 500);
}
The fixHeaderHeight() function CANNOT be called direclty because size parameter has not been changed when toggleTitlePanel() is called. So active function is call indirectly using setTimeout() function.
To position correctly ContentPanel the first time it is displayed and when screen size is changed, mimized, maximized, I have already added some javascript code.
<script>
function setContentTopPosition(div)
{
var iHeight = document.getElementById("PageHeader").style.height;
div.style.top = iHeight;
}
function onLoadPage()
{
fixHeaderHeight();
}
function onResizeWindow()
{
fixHeaderHeight();
}
</script>
The JQuery events are initialized just before </body> element in .ready() function.
<script type="text/javascript">
jQuery(document).ready(function()
{
onLoadPage();
jQuery("#PageHeader").resize(function()
{
onResizeWindow();
});
});
jQuery(window).resize(function()
{
onResizeWindow();
});
</script>
Now, Header and Content panels are correctly displayed
when I display this page for the first time
when I change windows size
when I click on MINUS button to collapse Header panel
List item when I click pn PLUS button to expand Header panel
I hope only that this solution will be helpfull for others.

Adding label to dialog prevents VoiceOver from being able to access dynamic contents in Safari

I've created an overlay that loads content dynamically after it opens, but am having issues with VoiceOver in Safari when trying to add ARIA attributes.
After only adding role='dialog' to the overlay container, it is announced as a dialog, but reads the text contents first ("close loading... dialog close button").
When adding a label to the dialog with either aria-label and aria-labelledby the real problem occurs. The overlay is announced nicely ("Overlay dialog close button"), but then the rest of the dialog's contents are inaccessible after being loaded, and it just appears that the close button is the last (and only) item available.
HTML:
<div id="page">
<a id="opendialog" href="#" role="button">Open</a>
</div>
JavaScript:
jQuery(function ($) {
$('#opendialog').click(function (event) {
event.preventDefault();
// Attach the dialog container to the page with a loading placeholder.
$dialog = $('<div id="dialog" role="dialog" aria-labelledby="dialog-label">' +
'<span id="dialog-label">Overlay</span>' +
'close' +
'<div class="content"><span class="loading">Loading...</span></div>' +
'</div>')
.insertAfter('#page');
$dialog.find('.close').focus();
// Hide the other page contents to trap the user in the dialog.
$('#page').hide();
$dialog.find('.close').click(function (event) {
event.preventDefault();
$dialog.remove();
$('#page').show();
$('#opendialog').focus();
});
// Simulate an asynchronous request for the dialog contents.
setTimeout(function () {
$dialog.find('.content .loading')
.replaceWith('<div>Dialog Content</div>');
}, 250);
});
});
http://codepen.io/gapple/pen/FGhzl
Chrome also seems to have some weird issues with the codepen when in an iframe, but loading the iframe url directly seems to work correctly.
VoiceOver is quite persnickety when it comes to dynamic content and focus. This (if run on a page of any size) will not work at all on iOS because the .focus() on dynamic content does not work unless executed in a timeout of at least 500 ms (look here http://unobfuscated.blogspot.com/2013/08/messed-up-ios-focus-management-with.html).
However, for OS X, you can fix your problem by focussing on the dialog itself rather than the close button. Here is the snippet of code modified so it works. Once the focus is on the dialog, hit CTRL-OPTION DOWN to interact with the dialog content
$dialog = $('<div id="dialog" role="dialog" aria-labelledby="dialog-label" tabindex="-1">' +
'<span id="dialog-label">Overlay</span>' +
'close' +
'<div class="content"><span class="loading">Loading...</span></div>' +
'</div>')
.insertAfter('#page')
.focus();

How to set Target = _blank

I want to set target =_blank to the following code, so that the Test.aspx page open in new window.
Response.Redirect("Test.aspx?D1=" + TextBox1.Text + "&D2=" + TextBox2.Text);
How can I do that?
try to add this to your object:
OnClientClick="aspnetForm.target ='_blank';"
or put it in ASP.NET like here:
<asp:LinkButton ID="myButton" runat="server" Text="Click Me!"
OnClick="myButton_Click"
OnClientClick="aspnetForm.target ='_blank';"/>
like in here
The other part you need to add is to fix the form's target otherwise every link will open in a new window. To do so add the following in the header of your POPUP window.
<script type="text/javascript">
function fixform() {
if (opener.document.getElementById("aspnetForm").target != "_blank") return;
opener.document.getElementById("aspnetForm").target = "";
opener.document.getElementById("aspnetForm").action = opener.location.href;
}
</script>
and then add:
<body onload="fixform()">