Refresh component in parent from inner iframe - jsf

I have this xhtml (primefaces) simple page:
....
<div id="header">
<h:outputText value="#{userBean.name}"/>
</div>
<div id="content">
<p:tabView value="#{appTabbedView.tabs}" var="tab" dynamic="true"
cache="false">
<p:tab title="#{tab.title}">
<iframe frameborder="0" src="#{tab.page}" />
</p:tab>
</p:tabView>
</div>
.....
Inside the iframe, I load a p:tab which loads a page named "Profile.xhtml" which allows edit (change) the user's name.
How can I refresh the header to show the new user's name (im inside an iframe!)?
I cant find a solution, I tried everything.

This is my solution. It works!
....
<div id="header">
<h:form id="formHeader">
<p:commandLink id="hiddenLink" update="user" value="hiddenLink" style="display:none" />
<h:outputText value="#{userBean.name}" id="user"/>
</h:form>
</div>
<div id="content">
<p:tabView value="#{appTabbedView.tabs}" var="tab" dynamic="true" cache="false">
<p:tab title="#{tab.title}">
<iframe frameborder="0" src="#{tab.page}" />
</p:tab>
</p:tabView>
</div>
.....
script.js:
function refreshHeader() {
window.parent.document.getElementById('formHeader:hiddenLink').click();
}
inside Profile.xhtml:
....
<p:commandButton id="accept" ... oncomplete="refreshHeader()" />
....

Related

Primefaces PanelMenu Target on iframe

I use PanelMenu to build menu and the target is an iframe.
What I want to get, when I click menuItem in panelMenu, the result should display in iframe.
What I get, the result display in same windows, like "_self".
I tried use an other menu component, like slideMenu and tieredMenu, it display in target iframe, like what I want.
Is this a bug in panelMenu or may be I use in wrong way?
panelMenu code:
<h:form id="menuForm">
<p:panelMenu id="appSlideMenu" autoDisplay="false" toggleEvent="click" style="width:250px">
<p:submenu label="Homepage">
<p:menuitem value="Primefaces" url="http://www.primefaces.org" target="dcontainer" />
</p:submenu>
</p:panelMenu>
</h:form>
slideMenu code:
<h:form id="menuForm">
<p:slideMenu id="appSlideMenu" autoDisplay="false" toggleEvent="click" style="width:250px">
<p:submenu label="Homepage">
<p:menuitem value="Primefaces" url="http://www.primefaces.org" target="dcontainer" />
</p:submenu>
</p:slideMenu>
</h:form>
iframe code:
<h:body>
<div class="row-container">
<div class="first-row">
<div class="start-button">
<p:commandButton icon="fa fa-arrow-right" value="Start"
oncomplete="PF('nsidebar').show()" />
</div>
<div class="bottom">
<ui:include src="bottom.xhtml" />
</div>
</div>
<div class="second-row">
<iframe id="dcontainer" name="dcontainer"> </iframe>
</div>
</div>
<p:sidebar widgetVar="nsidebar" style="width:300px;">
<ui:include src="menu.xhtml" />
</p:sidebar>
</h:body>
Please help... Thank you...
Primeface 7.0 Community
Tomcat 9.0.6

Multiple forms in jsf page

Here is my view
<h:body>
<div id="header"></div>
<div id="upload">
<h:form id="frmMain" enctype="multipart/form-data">
<p:inputTextarea id="text" style="width: 99%" value="#{uploadfile.content}" placeholder="What are you thinking?"></p:inputTextarea>
<p:fileUpload auto="true" oncomplete="input()" id="fileIdPhoto" previewWidth="200" style="width: 100%" messageTemplate="{name}" fileUploadListener="#{uploadfile.upload}" mode="advanced" dragDropSupport="true"
multiple="true" update="messages" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
<p:messages id="messages" autoUpdate="true" closable="true" />
<p:menubar autoDisplay="false">
<p:menuitem />
<f:facet name="options">
<p:commandButton value="Publish" update="fileIdPhoto" icon="ui-icon-extlink" actionListener="#{uploadfile.uploadPhoto}">
</p:commandButton>
</f:facet>
</p:menubar>
</h:form>
</div>
<div id="body">
<div id="post_container">
<ul>
<ui:repeat value="#{image.allpost}" var="value">
<h:form id="form">
<li>
<div id="post">
<p:commandButton rendered="false" id="dynaButton" process="#this,form" value="Show" type="button" icon="ui-icon-extlink"/> cant not trigger it so I set render false
<p:menu overlay="true" trigger="dynaButton" my="left top" at="left bottom">
<p:submenu label="Ajax">
<p:menuitem value="Delete" icon="ui-icon-disk"/>
<p:menuitem value="Update" icon="ui-icon-arrowrefresh-1-w"/>
</p:submenu>
</p:menu>
<b>#{value.content}</b> <br/>
#{value.createtime} <br/>
<br />
<p:galleria value="#{image.getImgByID(value.id)}" rendered="#{not empty image.getImgByID(value.id)}" var="a" panelWidth="720" panelHeight="400" showCaption="true">
<h:graphicImage value="data:image/jpeg;base64,#{a.imgUrl}" style="width:100%;height:100% " alt="Image Description for #{a.imgName}" title="#{a.imgName}"/>
</p:galleria>
<p:rating value="#{value.rating}" stars="10" cancel="false"/>cant change those stars by clicking on it
</div>
<div id="post_ceperator"/>
</li>
</h:form>
</ui:repeat>
</ul>
</div>
</div>
</h:body>
What I am trying to do is change the value of p:rating tag and p:menu to trigger but its seem like my page is only submitting the first form. Also how can I submit a post and div that contains my post will automatically update?
In my opinion the problem is that your components inside of the ui:repeat have all the time the same id's for each iteration.
The way i used to define ids in loops like that was to add some sort of unique prefix or suffix to them based on some field of the data over which i am iterating:
<ui:repeat value="#{image.allpost}" var="value">
<h:form id="form_#{value.id}">
<li>
<div id="post_#{value.id}">
Now each of your components, including the form, which is highly likely to be the cause of your problem, will have its unique id for each of the loop repetition.

JSF/PrimeFaces Extensions - page forward causing issues with bootsfaces burger menu

I have a page 'report1.xhtml'and 'report2.xhtml'both of which is using the same template 'template.xhtml'.
Here's 'template.xhtml':
<pe:layout fullPage="true" id="collapsibleLayoutPanel" stateCookie="false" widgetVar="templateLayoutWidget" style="100%;">
<pe:layoutPane id="topPanel" styleClassContent="topPanel unhideMenus" position="north" resizable="false"
closable="false" spacingClosed="0" spacingOpen="0">
<p:outputPanel id="dg">
<p:outputPanel id="dMHeader" styleClass="A_class Amarks_top">
#{tController.classificationMarking}
</p:outputPanel>
</p:outputPanel>
<div id="Ar" class="Aer" role="banner">
<div id="my_apps" style="display:none;">
<h:outputLink rendered="#{primaryMenuController.renderReturnToMyApps}"
value="#{primaryMenuController.myAppsUrl}">
<img id="my_apps_img" src="#{request.contextPath}/resources/img/my_apps.png" alt="My Apps"
title="My Apps"/>
</h:outputLink>
</div>
<b:navBar brandImg="#{request.contextPath}/resources/img/X_logo.png"
brandHref="#{request.contextPath}/view/landingPage.jsf">
<b:navbarLinks>
<div class="ui-grid-col-6">
<ui:include src="prnu.xhtml"/>
</div>
<div class="ui-grid-col-6">
<div id="A_logout">
<h:form id="helpLogoutForm">
<p:menubar styleClass="Aout_menu" autoDisplay="false">
<p:submenu
label="#{pController.name} (#{pController.accountType})"
icon="primnav-user-acct">
<p:menuitem id="myDashboardLink" value="My Dashboard"
action="landingPage" a:allowRead="true"
icon="primnav-dashboard"/>
<p:menuitem id="myMessagesLink" value="My Messages"
action="userMessageList" a:allowRead="true"
icon="primnav-inbox"/>
<p:menuitem id="myPrefLink" value="My Preferences"
oncomplete="PF('upDialog_widget').show();"
a:allowRead="true" icon="primnav-preferences"/>
<p:separator/>
<p:menuitem id="logoutLink" value="Logout"
action="#{primaryMenuController.logout}"
a:allowRead="true" onclick="X.logoutHandler();"
icon="primnav-logout" ajax="false"/>
</p:submenu>
<p:submenu icon="primnav-help">
<p:menuitem value="Help"
onclick="window.open('#{request.contextPath}/help/default.htm', 'Help', 'height=600,width=850,resizable=yes'); return false;"
icon="primnav-help_menu_child" a:allowReadHelp="true"/>
<p:menuitem value="About"
action="#{aController.updateMemoryValues()}"
oncomplete="PF('aboutDialog_widget').show();"
a:allowRead="true" icon="primnav-help_menu_child"
update=":aboutDialog"/>
</p:submenu>
</p:menubar>
</h:form>
</div>
</div>
</b:navbarLinks>
</b:navBar>
</div>
<ui:insert name="tertiaryNavMenu"/>
</pe:layoutPane>
<!-- Main content -->
<pe:layoutPane id="centerPanel" styleClassContent="centerPanel" position="center" spacingClosed="0"
spacingOpen="0">
<pe:layoutPane position="north" id="nestedTopPanel" size="45" resizable="false" closable="false"
styleClassContent="unhideMenus"
spacingClosed="0" spacingOpen="0" rendered="#{not hideTitleActionBar}">
<div id="A_content" class="AE_content" role="main">
<div class="ui-grid ui-grid-responsive">
<div class="ui-grid-row template-header">
<div class="ui-grid-col-3 template-title">
<div id="A_content_pagetitle" class="AE_content_pagetitle">
<h1 class="pagetitle_h1"><ui:insert name="contentHeader"></ui:insert></h1>
</div>
</div>
<div class="ui-grid-col-9 template-actions">
<div class="action_buttons">
<ui:insert name="actionMenu"></ui:insert>
</div>
</div>
</div>
</div>
</div>
</pe:layoutPane>
<pe:layoutPane position="center" id="nestedCenterPanel" spacingClosed="0" spacingOpen="0">
<div id="A_content_body" class="A_content_body" style="padding:0 12px;">
<p:growl id="siteMessages" globalOnly="true" showDetail="true" life="4000" autoUpdate="false"
widgetVar="siteMessages_widget"
sticky="#{not empty facesContext.maximumSeverity and facesContext.maximumSeverity.ordinal gt 1}"/>
<ui:insert name="content"></ui:insert>
</div>
</pe:layoutPane>
</pe:layoutPane>
<!-- Bottom markings -->
<pe:layoutPane id="bottomPanel" styleClassContent="bottomPanel" position="south" resizable="false"
closable="false" spacingClosed="0" spacingOpen="0">
<!-- TODO: Determine classification marks to display -->
<!-- BEGIN FOOTER -->
<p:outputPanel styleClass="A_classmarking AE_body_classmarks_bottom" id="documentMarkingFooter">
#{tController.classificationMarking}
</p:outputPanel>
<!-- END FOOTER -->
</pe:layoutPane>
</pe:layout>
When I load report1.xhtml and resize window to iPhone size(640x960) everything works as expected and the burger menu onclick is showing the previously hidden menu options. However after the onchange event that causes page forward to report2.xhtml, the burger menu onclick is no longer working.. It's still clickable but nothing happens after clicking it.. If I make the navigation redirect instead of page forward, everything works just fine, so my conclusion is this has something to do with page forward...
After debugging on the devtools console I've got this error showing up after page load(for page forward only):
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
The source js is http://localhost:8080/javax.faces.resource/jquery/jquery.js.jsf?ln=primefaces&v=5.2.7
Then on resize I've got this error from source https://raw.githubusercontent.com/primefaces-extensions/core/master/src/sourcemap/3.2.0/layout.source.js:
Uncaught TypeError: Cannot read property 'state' of undefined
Again, note that those errors only occur when navigation is page forward and goes away when doing a redirect. I don't want to do a redirect because I want the URL to stay the same..

JSF setpropertyactionlistener not being called

I have a f:setPropertyActionListener within a data table and clicking on a command button the setpropertyaction listener is not being called. Any one see where I am going wrong?
thanks
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:form id="userDetailsForm" style="padding:5px">
<p:growl id="messages" showDetail="true" autoUpdate="true" life="2000"/>
<p:spacer height="15"></p:spacer>
<div class="row">
<div class="col-lg-4">
<div class="input-group">
<p:inputText type="text" styleClass="form-control" value="#{emailArticleBean.searchText}" />
<span class="input-group-btn" style="margin:3px;">
<p:commandButton actionListener="#{emailArticleBean.search}" value="Go!" update=":userDetailsForm:emailArticleTable" />
</span>
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<p:spacer height="15"></p:spacer>
<h:messages/>
<div class="row">
<div class="col-lg-1">
</div>
<div class="col-lg-11">
<p:dataTable var="email" value="#{emailArticleBean.emailArticles}" scrollRows="20"
scrollable="true" liveScroll="true" scrollHeight="750" id="emailArticleTable"
>
<p:column>
<p:accordionPanel multiple="true" activeIndex="-1" id="panel#{email.id}">
<p:tab title="#{email.headline}" titleStyleClass="email-header">
<div style="clear:both;margin-bottom:10px;">
<h6 style="font-weight:bold;">Summary</h6>
<h:outputText
value="#{email.summary}" />
</div>
<div style="clear:both;margin-bottom:10px;">
<h6 style="font-weight:bold;">Implication</h6>
<h:outputText
value="#{email.implication}" />
</div>
<div style="float:left;clear:both">
<p:commandButton value="View Existing Actions"
oncomplete="PF('dlg2').show();" update=":userDetailsForm:emailActionDialog">
<f:setPropertyActionListener value="#{email}" target="#{emailArticleBean.selectedEmail}" />
</p:commandButton>
</div>
<br/>
<br/>
<div style="margin-top:10px;">
<h:inputTextarea id="accordian1" value="#{email.tempAction}" cols="90" rows="3" />
</div>
<h6 style="font-weight:bold;">Due Date</h6>
<p:calendar value="#{email.tempDate}" id="popupCal" pattern="dd MMM, yyyy"/>
<p:commandButton actionListener="#{emailArticleBean.updateAction}" value="Add Action"
style="margin-left:5px;">
<f:setPropertyActionListener value="#{email}" target="#{emailArticleBean.selectedEmail}" />
</p:commandButton>
</p:tab>
</p:accordionPanel>
</p:column>
</p:dataTable>
</div>
</div>
<p:dialog id="emailActionDialog" header="Email Actions" widgetVar="dlg2" modal="true" height="100">
<h3>Email Actions</h3>
<p:dataList value="#{emailArticleBean.selectedEmail.actions}" var="action" itemType="disc">
#{action.action} --- #{action.username}
</p:dataList>
</p:dialog>
</h:form>
</html>
In my bean I have the following getter/setter
public EmailArticle getSelectedEmail() {
return selectedEmail;
}
public void setSelectedEmail(EmailArticle selectedEmail) {
this.selectedEmail = selectedEmail;
}
public void updateAction(ActionEvent ae) {
selectedEmail.getActions().add(new EmailActions(emailAction, "testUser", actionDueDate));
selectedEmail.merge();
}
The main problem here is the order of the invocation, first your actionListener is called then
f:setPropertyActionListener.
To solve this, change your actionListener to action, and update your action method to return a String.
Button
<p:commandButton action="#{emailArticleBean.updateAction}"
value="Add Action" style="margin-left:5px;">
<f:setPropertyActionListener value="#{email}"
target="# {emailArticleBean.selectedEmail}" />
</p:commandButton>
updateAction
public String updateAction() {
selectedEmail.getActions().add(new EmailActions(emailAction, "testUser", actionDueDate));
selectedEmail.merge();
return null;
}
OR
you can keep using your actionListener and pass the selectedEmail to it (without using f:setPropertyActionListener).
Button
<p:commandButton actionListener="#{emailArticleBean.updateAction(email)}"
value="Add Action" style="margin-left:5px;">
</p:commandButton>
updateAction
public void updateAction(EmailArticle selectedEmail) {
selectedEmail.getActions().add(new EmailActions(emailAction, "testUser", actionDueDate));
selectedEmail.merge();
}
To understand more the order of the invocation
See:
Differences between action and actionListener

Update component on template.xhtml from test.xhtml

I have a menutab on my template that i am using on every page. I would like to update a component from the template from another paged which is based on the template.
Its working like just any other emailpage, as soon as i read an email, it should update the number of the unread emails. The number is shown in the menutab in the template.xhtml and the emails are on my test.xhtml. As soon as I read an email it should update the number of the unread emails in the menutab in template.xhtml.
this is my template.xhtml
<ui:define name="navi">
<h:form id="navForm">
<div id="MMeineVersicherungen" class="hauptmenu">
<h:commandLink action="#{navigationController.switchView('1')}">#{messages['menu.1']}</h:commandLink>
</div>
<div id="MPolizzen" class="menuitem">
<h:commandLink action="#{navigationController.switchView('1.1')}"
styleClass="#{navigationController.isAktPageId('1.1') or navigationController.isAktPageId('1') ? 'activelink' : ''}">- #{messages['menu.1.1']}</h:commandLink>
</div>
<div id="MSchaeden" class="menuitem">
<h:commandLink action="#{navigationController.switchView('1.2')}"
styleClass="#{navigationController.isAktPageId('1.2') ? 'activelink' : ''}">- #{messages['menu.1.2']}</h:commandLink>
</div>
<div id="MTopKunden" class="menuitem">
<h:commandLink action="#{navigationController.switchView('1.3')}"
styleClass="#{navigationController.isAktPageId('1.3') ? 'activelink' : ''}">- #{messages['menu.1.3']}</h:commandLink>
</div>
<div id="MMeineDaten" class="hauptmenu">
<h:commandLink action="#{navigationController.switchView('2')}">#{messages['menu.2']}</h:commandLink>
</div>
<div id="MKundendaten" class="menuitem">
<h:commandLink action="#{navigationController.switchView('2.1')}"
styleClass="#{navigationController.isAktPageId('2.1') or navigationController.isAktPageId('2') ? 'activelink' : ''}">- #{messages['menu.2.1']}</h:commandLink>
</div>
<div id="MBenutzer" class="menuitem">
<h:commandLink action="#{navigationController.switchView('2.2')}"
styleClass="#{navigationController.isAktPageId('2.2') ? 'activelink' : ''}">- #{messages['menu.2.2']} </h:commandLink>
</div>
<div id="MPostfach" class="hauptmenu">
<h:commandLink action="#{navigationController.switchView('3')}"
styleClass="#{navigationController.isAktPageId('3') ? 'activelink' : ''}">(#{post.getAnzahlNeueNachrichten()}) #{messages['menu.3']} </h:commandLink>
</div>
<div id="MKommunikationsvereinb" class="hauptmenu">
<h:commandLink action="#{navigationController.switchView('4')}"
styleClass="#{navigationController.isAktPageId('4') ? 'activelink' : ''}">#{messages['menu.4']}</h:commandLink>
</div>
<div id="MAbmelden" class="hauptmenu" style="margin-top: 20px;">
<h:commandLink action="#{loginController.logout}"
value="#{messages['menu.5']}" />
</div>
</h:form>
</ui:define>
this is test.xhtml
<ui:define name="main">
<h:form id="postform">
<p:dialog id="msgdlg" dynamic="true" modal="true" widgetVar="msgdlg"
width="600" height="500">
<f:facet name="header">#{post.aktNachricht.subject}</f:facet>
<p:ajax event="close" listener="#{post.closeDlg}" />
<p:hotkey bind="esc" handler="msgdlg.hide(); " />
<ui:include src="#{post.view}" />
</p:dialog>
<p:tabView id="posttabview" activeIndex="0" cache="true">
<p:tab id="empftab" title="#{messages['post.empfangen']}"
titleStyleClass="thementab">
<p:dataTable value="#{post.empfangenList}" var="msg">
<p:column styleClass="coldatum">
<p:commandLink action="#{post.showNachricht(msg)}"
oncomplete="msgdlg.show();" update=":postform">
<h:outputText value="#{msg.datum}"
styleClass="#{msg.gelesen ? '' : 'unread'}">
<f:convertDateTime pattern="dd.MM.yyyy"
timeZone="Europe/Berlin" />
</h:outputText>
</p:commandLink>
</p:column>
<p:column>
<h:outputText value="#{msg.subject}"
styleClass="#{msg.gelesen ? '' : 'unread'}" />
</p:column>
</p:dataTable>
</p:tab>
<p:tab id="sendtab" title="#{messages['post.gesendet']}"
titleStyleClass="thementab">
</p:tab>
</p:tabView>
<br />
<p:commandButton value="#{messages['post.neu']}" action="#{post.neu}"
update="msgdlg" oncomplete="msgdlg.show();" />
</h:form>
</ui:define>

Resources