Primefaces dynamic dialog with ui:include not working after PF upgrade from 4.0 to 5.1 [duplicate] - dynamic

This question already has answers here:
How to include another XHTML in XHTML using JSF 2.0 Facelets?
(2 answers)
Closed 8 years ago.
I've recently upgraded Primefaces from 4.0 to 5.1 and after that dialogs are not being shown after clicking the commandButton. It works with dynamic="false" but I need it to be lazy loaded. ExampleBean is sessionScoped and i'm using JSF 2.2. Can someone help me solve this?
<ui:composition template="/template/common/pagelayout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:ez="http://xmlns.jcp.org/jsf/composite">
<ui:define name="content">
<h:form id="form">
<p:commandButton type="button" value="Log" onclick="PF('dlgLog').show();" icon="botaoLog" />
</h:form>
<p:dialog header="HEADER" widgetVar="dlgLog" resizable="false" modal="true" height="500" width="1000" dynamic="true">
<ui:include src="logPage.xhtml"/>
</p:dialog>
</ui:define>
</ui:composition>
logPage.xhtml
<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:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form id="formlog">
<p:dataTable var="log" value="#{exampleBean.logs}" emptyMessage="Empty">
<p:column headerText="Header1" width="10%">
<h:outputText value="#{log.date}">
<f:convertDateTime pattern="dd/MM/yyyy - HH:mm"/>
</h:outputText>
</p:column>
<p:column headerText="Header2" width="10%">
<h:outputText value="#{log.op}" />
</p:column>
<p:column headerText="Header3">
<p:outputLabel value="#{log.name}"/>
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>

More specifically, you removed the h:head tag (and I found out ;-). Between the versions you used, PF created it's own h:head renderer which differs from the default implementions in code jsf libraries hence the difference in behaviour (assuming your jsf impl stayed the same).

Finally figured what the problem was. Just removed the <h:head> tag from logPage.xhtml and it worked! Not sure I know the reason though, probably has something to do with <ui:include> expecting a composition which shouldn't have a <h:head> tag.

Related

how change name of vue.js application

When I want to share a URL on Facebook (in red on picture), the name is not the one mentioned in the "application-name" meta tag but the one in package.json
Is there a way to fix this?
!share a URL on Facebook]1
For Facebook and Linkedin when you want to share URL, you have to add the open graph tags to have the right texts and visuals.
<meta property="og:title" content="YOUR SITEWEB NAME" />
<meta property="og:description" content="bla-bla." />
<meta property="og:image" content="<%= require('./imagesBlogs/og_image_200x200.png') %>" />

dataExporter cannot be rendered because of form needing

I am trying to add dataExporter component to my table.
First I had {Exporters} beside pagination facet , then after a lot of tries I got this error in the console
HTML nesting warning on closing changes: element update not explicitly closed
I solved it also but now there is nothing appears in the Exporter facet. I googled it and found that I need a form in my page because of this commandlink submit a form , so it needs a form.
My Question here is how to apply this example in my project.
Here is my code.
<ui:composition template="/template.xhtml">
<ui:define name="title">
<h:outputText value="#{bundle.ViewLfmTitle}"></h:outputText>
</ui:define>
<ui:define name="body">
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green"
layout="table" />
</h:panelGroup>
<p:dialog header="Add Task" widgetVar="dlg" position="center center"
onShow="PF('dlg').initPosition()" modal="true" closeOnEscape="true"
resizable="false">
<h:form>
<h:panelGrid columns="2">
<p:outputLabel value="#{bundle.CreateTaskLabel_name}" for="name" />
<p:inputText id="name"
value="#{ViewLfmJpaController.newTaskDTO.name}"
title="#{bundle.CreateTaskTitle_name}" />
<p:outputLabel value="#{bundle.CreateTaskLabel_durationPerMonth}"
for="durationPerMonth" />
<p:inputText id="durationPerMonth"
value="#{ViewLfmJpaController.newTaskDTO.duration}"
title="#{bundle.CreateTaskTitle_durationPerMonth}" />
<p:outputLabel value="#{bundle.CreateTaskLabel_startDate}"
for="startDate" />
<p:calendar id="startDate"
value="#{ViewLfmJpaController.newTaskDTO.startDate}"
title="#{bundle.CreateTaskTitle_startDate}" pattern="d MMM yyyy"
effect="fold">
<f:convertDateTime pattern="d MMM yyyy" />
</p:calendar>
<p:outputLabel value="#{bundle.CreateTaskLabel_endDate}"
for="endDate" />
<p:calendar id="endDate"
value="#{ViewLfmJpaController.newTaskDTO.endDate}"
title="#{bundle.CreateTaskTitle_endDate}" pattern="d MMM yyyy"
effect="fold">
<f:convertDateTime pattern="d MMM yyyy" />
</p:calendar>
<f:facet name="footer">
<p:commandButton value="Add"
actionListener="#{ViewLfmJpaController.addTask}" update="Matrix"
oncomplete="PF('dlg').hide()" />
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
<p:dataTable id="Matrix" resizableColumns="true" scrollable="true"
scrollHeight="80%"
value="#{ViewLfmJpaController.selected.tasksDtoCollection}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
var="item" resizeMode="expand" paginator="true" rows="10"
style="margin-bottom:20px">
<f:facet name="header">
Logical Framewrok Matrix
</f:facet>
<f:facet name="{Exporters}">
<p:commandLink>
<p:graphicImage name="../resources/images/pdf.jpg" width="24" />
<p:dataExporter type="pdf" target="Matrix" fileName="lfm" />
</p:commandLink>
</f:facet>
<p:column headerText="Index" colspan="1">
<c:forEach var="i" begin="1" end="#{ViewLfmJpaController.listSize}">
<p:outputLabel value="#{i}"></p:outputLabel>
</c:forEach>
</p:column>
<p:column headerText="Task Title">
<p:outputLabel value="#{item.name}"></p:outputLabel>
</p:column>
<p:column headerText="Start Date" colspan="3">
<p:outputLabel value="#{item.formatedStartDate}"></p:outputLabel>
</p:column>
<p:column headerText="End Date" colspan="3">
<p:outputLabel value="#{item.formatedEndDate}"></p:outputLabel>
</p:column>
<c:forEach var="i" begin="1"
end="#{ViewLfmJpaController.numberOfMonths}">
<p:column headerText="m ${i}" colspan="1"></p:column>
</c:forEach>
<p:column headerText="Exptected Outcomes" colspan="4">
<ui:repeat value="#{item.tasksExpectedOutcomesCollection}" var="teo">
<li><h:outputText value="#{teo.expectation}">
</h:outputText></li>
</ui:repeat>
</p:column>
</p:dataTable>
<p:commandButton value="Add Task" oncomplete="PF('dlg').show()"></p:commandButton>
</ui:define>
</ui:composition>
I FOUND THE SOLUTION BY MYSELF.
First : You have to know that you cannot make nested forms in your page.
Second : you have to know that to submit <p:dialog> </p:dialog> or to use <h:commandLink> </h:commandLink> you need to use form.
So I had removed the form in the dialog component and add a general component contains dialog and dataTable together

Htmlunit access to a frame inside a frameset which is inside a frameset

I need to access to a form element which is in the frame "menu"
<html>
<head>
<script>.........
</script>
<title>The Main page</title>
</head>
<frameset onload="init();" rows="70,*" frameborder="0" border="false" framespacing="0">
<frameset cols="32000,0,0" frameborder="0" border="true" framespacing="0">
<frame scrolling="no" marginheight="0" marginwidth="0" target="logo" src="about:blank" name="logo"></frame>
<frame scrolling="no" noresize="" marginheight="0" marginwidth="0" target="temp" src="about:blank" name="temp"></frame><frame scrolling="no" noresize="" marginheight="0" marginwidth="0" target="system" src="about:blank" name="system"></frame>
</frameset>
<frameset cols="165,*" frameborder="0" border="false" framespacing="0">
<frame scrolling="no" noresize="" marginheight="0" marginwidth="3" target="menu" src="about:blank" name="menu"> </frame>
<frame scrolling="auto" noresize="" marginheight="0" marginwidth="3" target="work" src="about:blank" name="work"></frame>
</frameset>
</frameset>
</html>
I tried this:
menuPage = (HtmlPage)page.getFrameByName("menu").getEnclosedPage();
But what I get is
<?xml version="1.0" encoding="ISO-8859-1"?>
<html>
<head/>
<body/>
</html>
I tried different other odd thing but never succeed to get the content of the frame.....
If somebody have already done this I will be happy to get some clues..
Ok, I found it eventually. The javascript was loading. But besides and most important I was not accessing correctly the frame content. So By looking deeply in the dom with firstchild and sibbling I arrived to see what I was looking for. So the first code working is the following and need some tweaks:
HtmlElement frameset1 = page.getBody();
node = frameset1.getFirstChild().getNextSibling();
HtmlFrame fr1 = (HtmlFrame) node.getFirstChild();
FrameWindow fw1 = (FrameWindow) fr1.getEnclosedWindow();
HtmlPage p1 = (HtmlPage) fw1.getEnclosedPage();
Thanks for your time

show pdf file in a icefaces modalpopup

Is it possible to show a pdf file in modalpopup with icefaces. Tried this but does not seem to work. Am new to icefaces too.
<ice:panelPopup autoCentre="true" visible="#{popup.visible}" modal="true">
<f:facet name="header"/>
<f:facet name="body">
<OBJECT DATA="/ICEfacesDevelopersGuide.pdf" TYPE="application/pdf" WIDTH="100%" HEIGHT="100%" />
<ice:commandButton value="Close" action="#{popup.close}" />
</f:facet>
</ice:panelPopup>
I ended up doing it the old way opening it on a new window or tab using output link and target attribute.

Why potentially dangerous request error even ValidateRequest = false

Here is my Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %>
<html>
<head runat="server">
<title>xss demonstration</title>
</head>
<body>
<form id="form1" runat="server">
<div>
We are looking for your feedback.
<asp:TextBox ID="txtFeedback" runat="server" TextMode="MultiLine" />
<br />
<asp:Button ID="submit" runat="server" Text="Submit" onclick="submit_Click" />
<br />
Comment:
<br />
<asp:Literal ID="ltlFeedback" runat="server" />
</div>
</form>
</body>
</html>
And below is Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
protected void submit_Click(object sender, EventArgs e)
{
this.ltlFeedback.Text = this.txtFeedback.Text;
}
}
When I run the application and enter following in the text box.
<script>alert('Hello')</script>
I get following error.
A potentially dangerous Request.Form value was detected from the
client (txtFeedback="alert('Hello...").
My question is why I get this error even though ValidateRequest is set to false in the page?
In .net framework 4.0 you have to set <httpRuntime requestValidationMode="2.0"/> markup in web.config.
<system.web>
<compilation debug="false" targetFramework="4.0" />
<httpRuntime requestValidationMode="2.0"/>
</system.web>
Have a look at reference article - ASP.NET 4 Breaking Changes #1: requestValidationMode cause ValidateRequest=False to fail.
you just need to Add following code in your web config
<system.web>
<compilation debug="false" targetFramework="4.0" />
<httpRuntime requestValidationMode="2.0"/>
</system.web>
but take care by doing this you can be victim of cross site scripting attack
Disable ValidateRequest on any pages retrieved via Server.Execute
I recently ran into a rather esoteric version of this error. In order to include shared content across pages in different sites, I call Server.Execute on another ASPX page. By default, Server.Execute will forward the POST data along to the child request, so this page also needs ValidateRequest="false".
As long as <httpRuntime requestValidationMode="2.0"/> in web.config is set, the exception's stack trace will indicate which page class raised the error.