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.
Related
I have the following menu where all menuItem are starting different views that use FlowScope.
In my home page ex: "http://localhost:8080/abc" I can Start any flow from the MenuItem. But when I get into one flow, I get the error: Could not resolve NavigationCase for outcome: view-all
If I change from outcome to action in the menuItem, I can get into the view, but if I try to start another follow I cant.
Here is my menu :
<h:body>
<div id="page">
<div id="header">
<ui:insert name="header">
<h:form>
<p:menubar id="menu">
<p:menuitem>
<h:link>
<h:graphicImage name="fme.png" height="50" />
</h:link>
</p:menuitem>
<p:submenu label="Colaborador" icon="ui-icon-document">
<p:menuitem value="Criar Colaborador" action="create-colaborator" />
<p:menuitem value="Editar Colaborador" action="create-colaborator" />
<p:menuitem value="Listar Todos" action="view-all" />
</p:submenu>
<p:submenu label="Relatorio" icon="ui-icon-document">
<p:menuitem value="Relatorio" action="exportar-relatorio" />
</p:submenu>
<p:menuitem style="margin-right:600px">
<h:link>
<h:graphicImage name="swiss.png" height="40" />
</h:link>
</p:menuitem>
</p:menubar>
</h:form>
</ui:insert>
</div>
<div id="contentWrap" class="ui-fluid">
<div id="content">
<ui:insert name="content"></ui:insert>
</div>
</div>
<div id="footer">
<ui:insert name="footer">
Um produto de FME em parceria com a SwissContact.
</ui:insert>
</div>
</div>
</h:body>
I have a weird problem with jsf components (h:inputFile & h:selectBooleanCheckbox).
Both components receive focus, even when my mouse is somewhere else on the page. Here is the code:
<h:form id="logoUpload" enctype="multipart/form-data">
<div>
<h:outputLabel rendered="true">
<h:inputFile id="companyLogo" label="file" value="#{fileHandlerBean.part}" >
<f:validator validatorId="FileUploadValidator" />
</h:inputFile>
</h:outputLabel>
</div>
<div class="clear" />
<h:outputLabel rendered="true">
<div>
<div style="width: 5%">
<h:selectBooleanCheckbox id="acceptToULogo" value="#{companyEditController.confirmToU}">
<p:ajax event="change" update="buttonLogo" />
</h:selectBooleanCheckbox>
</div>
<div style="width: 95%">
<h:outputText value="Some Text " />
</div>
<br />
<h:commandButton id="buttonLogo" styleClass="formbutton" value="Upload"
action="#{companyEditController.companyLogoUpload()}"
actionListener="#{fileHandlerBean.uploadCompanyLogo()}"
disabled="#{!companyEditController.confirmToU}"/>
</div>
</h:outputLabel>
</h:form>
If I move the mouse over the h:outputText the checkbox receives focus.
I had the same problem with the h:inputFile tag. I solved it by surrounding it with a h:outputLabel tag, but unfortunately it doesn´t workd with the selectBooleanCheckbox.
Did somebody have the same problem in the past and knows a solution?
This is because everything is wrapped in the h:outputLabel tag. This outputLable is rendered as a plain label html element.
You can see form the W3C specification that anything inside the label will toggle the control
The element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the element, it toggles the control
To fix this, you need to replace the h:output label tag using a h:panelGroup layout="block" which renders a <div>:
<h:panelGroup layout="block" rendered="true">
<div>
<div style="width: 5%">
<h:selectBooleanCheckbox id="acceptToULogo" >
<p:ajax event="change" update="buttonLogo" />
</h:selectBooleanCheckbox>
</div>
<div style="width: 95%">
<h:outputText value="Some Text " />
</div>
<br />
<h:commandButton id="buttonLogo" styleClass="formbutton" value="Upload"/>
</div>
</h:panelGroup>
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..
I've comments that are displayed from an <ui:repeat> tag. An user can reply to to all comments with input fields that are displayed individually for each comment. However I can't manage to pass the value of the comment to the bean that deals with it. I thought about passing the UIInput value as described in the first answer [by balusC here][1]. The problem is that the content is empty because the action button is bound to every UIInput ( I believe so). I should sort of have a personal bound between each button and my UIInput. I think the code is gonna be more self-explanatory hopefully. :
<ui:repeat var="post" value="#{watchThread.listeFirstPosts}">
<h:outputText value="#{post.user.username}"/>
<div class="postContent">
<h:outputText value="#{watchThread.sanitize(post.content)}" />
</div>
<div class="replyAction">
<h:form>
<div class="inputAreaPostFast">
<p:inputTextarea id="reply2" value="#{watchThread.replyContent}" binding="#{inputReply}"/>
<div class="replyBtn">
---------- Here the third param is the issue --------------
<p:commandButton action="#{watchThread.sendReply(userNav.user, post, inputReply.value)}"/>
</div>
</div>
</h:form>
</div>
</ui:repeat>
Edit: This is the code that worked for me. (I think) I had a form that had no business of being in my ui:repeat tag. Also to bind the input see the answer/comment of balusC below. However I had to let the form tags inside and not outside as suggested.
<ui:repeat var="post" value="#{watchThread.listeFirstPosts}">
<div class="replyBlock">
<h:panelGroup id="username" style="cursor:pointer;">
<div class="profileimgForum">
<h:graphicImage styleClass="profilepicForum" value="/images/#{post.user.profilePic}" rendered="#{!empty post.user.profilePic}"></h:graphicImage>
<h:graphicImage styleClass="profilepicForum" library="images" name="profilepic1.jpg" rendered="#{empty post.user.profilePic}"></h:graphicImage>
</div>
<span class="posterTitle">
<h:outputText value="#{post.user.username}"></h:outputText> </span>
<h:outputText value=" #{watchThread.formatTimeReply(post.datePost)}"/>
</h:panelGroup>
<div class="replyContent">
<h:outputText value="#{watchThread.sanitize(post.content)}" style="pointer:cursor;"/>
</div>
<div class="replyAction">
<p:inplace id="facet" effect="none">
<f:facet name="output">
#{strings.Reply}
</f:facet>
<f:facet name="input">
<h:form>
<div class="inputAreaPostFast">
<p:inputTextarea id="reply2" cols="70" rows="7" value="#{watchThread.replyContent}" binding="#{inputReply}" maxlength="500"/>
<div class="replyBtn">
<p:commandButton update="growl" style=" margin-right: 2em;" value="#{strings.Reply}" action="#{watchThread.sendReply(userNav.user, post, inputReply)}"/>
</div>
</div>
</h:form>
</f:facet>
</p:inplace>
</div>
<ui:repeat var="areply" value="#{post.posts}">
#{areply.content} ----
</ui:repeat>
</div>
<!-- ####### Dialog username ######## -->
<p:overlayPanel for="username" id="usernamePanel" dynamic="true" showCloseIcon="true" appendToBody="1" dismissable="false">
<div class="dlgTopBlock">
<div class="dlgPicBlock">
<h:graphicImage styleClass="profilePicDialog" value="/images/#{post.user.profilePic}" rendered="#{!empty post.user.profilePic}"/>
<h:graphicImage styleClass="profilePicDialog" library="images" name="profilepic1.jpg" rendered="#{empty post.user.profilePic}"/>
</div>
<div class="dlgTopSubBlock"><div class="dlgTopTitle">
<h:graphicImage styleClass="flag" library="images/flags"
name="#{post.user.countryBean.iso2}.png"
rendered="#{! empty post.user.countryBean.iso2}"/>
<h:link value="#{post.user.username}" outcome="/user.xhtml">
<f:param name="username" value="#{post.user.username}"></f:param>
</h:link>
</div>
<div class="dlgRep">
<h:outputText value="#{post.user.reputation} #{strings.repPoints} "></h:outputText>
</div>
<div class="dlgTopStatus">
<h:outputText value="#{post.user.status}"/></div>
</div>
</div>
<div class="btnDlg">
<h:panelGroup rendered="#{userNav.isUserConnected and userNav.username != post.user.username}">
<p:commandButton value="#{usernavmsg.SendPM}" icon="ui-icon-mail-closed" onclick="PF('sendMsgDlg').show();"></p:commandButton>
<p:commandButton id="addFriend" value="#{friendBean.btnText}" action="#{friendBean.addFriend()}" update="growl addFriend" icon="#{friendBean.icon}"
rendered="#{friendBean.rendered}"/>
</h:panelGroup>
</div>
<p:dialog header="#{usernavmsg.SendingTo}: #{post.user.username}"
dynamic="true" modal="false" widgetVar="sendMsgDlg" minHeight="40">
<h:form>
<p:inputTextarea value="#{pMbean.title}" rows="1" cols="110" id="title" >
<f:passThroughAttribute name="placeholder" value="#{usernavmsg.Title}"/>
</p:inputTextarea><br/><br/>
<p:inputTextarea value="#{pMbean.message}" id="msg" rows="10" cols="110" autoResize="true">
<f:passThroughAttribute name="placeholder" value="#{usernavmsg.YourMsg}"/>
</p:inputTextarea><br/>
<p:commandButton style="float:right;" value="#{usernavmsg.Send}" action="#{pMbean.send(post.user)}"
onclick="PF('sendMsgDlg').hide();" icon="ui-icon-mail-closed" update="growl"></p:commandButton>
</h:form>
</p:dialog>
</p:overlayPanel>
<!-- ######### End of dialog user ######## -->
</ui:repeat>
The only visible mistake is the below:
<ui:repeat value="#{watchThread.listeFirstPosts}" var="post" ...>
<p:inputTextarea ... value="#{watchThread.replyContent}">
You're basically binding the value of the input field of every iteration to one and same backing bean property. So, every iteration round will override the value of the previous iteration round. This is not right. The value of the input field must be bound to the current iteration round. I.e. it should basically have been as below:
<ui:repeat value="#{watchThread.listeFirstPosts}" var="post" ...>
<p:inputTextarea ... value="#{post.replyContent}">
But, in this construct you actually don't need it. Just get rid of the value attribute altogether and rely on binding as you initially wanted to use.
Then, there's another mistake as pointed out in the comments: nesting forms. This is illegal in HTML. Don't write JSF code in such way that it produces illegal HTML. There would be another potential cause in form of a bug in Mojarra which only exposes in case you're using <f:ajax> in a nested <ui:repeat>. The solution to that would be using a fullworthy UIData component, such as <h:dataTable> or one of PrimeFaces grids.
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