I have two p:ouputPanels which have the rendered attribute. They should be rendered when the value of the underlying getter/setter changes. However, the underlying values change in the right order. The first panel disappears, However the second panel does not show up. Even NOT in the HTML code!
My two panels:
<p:outputPanel id="PanelParent">
<h:form>
<p:outputPanel id="PanelForm" rendered="#{PageService.isVisibilityForm()}">
<h:commandButton value="Button"
action="#{PageService.persist}"
styleClass="btn btn-primary opal_btn submit_form_new" />
</h:form>
</p:outputPanel>
<p:outputPanel id="PanelMessage" rendered="#{PageService.isVisibilityMessage()}">
//Message
</p:outputPanel>
</p:outputPanel>
I appreciate your answer!!!
-UPDATE-
In the code, I reference to the persist method and in this method I change the getter and setter of the visibility for each section.
-UPDATE1-
OK here is in fact my code:
<p:outputPanel id="parentPanel">
<p:outputPanel id="PanelForm"
rendered="#{PageService.isVisibilityForm()}">
<div>
<div>
<h:form class="homepage_invitee_form" action="" method="POST">
<p:messages id="messages" showDetail="false" autoUpdate="true"
closable="true" />
<h:inputText required="true"
value="#{PageService.instance.name}"
name="name" placeholder="Last Name"
styleClass="lastname_new" id="lastname_new"
type="text placeholder" />
<h:commandButton value="Press"
action="#{PageService.persist()}"/>
<f:ajax render="" />
</h:commandButton>
</h:form>
</div>
</div>
</p:outputPanel>
<p:outputPanel id="PanelThank"
rendered="#{PageService.isVisibilityThank()}">
<div>
Message
</div>
</p:outputPanel>
</p:outputPanel>
I really do not see where it fails? ;(
It's like Xtreme Biker said <f:ajax> render attribute will render elements that are already present in the DOM. In your case, <p:outputPanel id="PanelThank"> render attribute was evaluating to false so it was not in the DOM. Therefore, <f:ajax> could not render it. You need to point to something that is always visible. Change
<f:ajax render="" />
to
<f:ajax render=":PanelThank" />
but more importantly change
<p:outputPanel id="PanelThank" rendered="#{PageService.isVisibilityThank()}">
<div>
Message
</div>
</p:outputPanel>
to
<p:outputPanel id="PanelThank">
<p:outputPanel rendered="#{PageService.isVisibilityThank()}">
<div>
Message
</div>
</p:outputPanel>
</p:outputPanel>
Consider refactoring your code also. For instance, action and method in <h:form> is not needed.
rendered attribute defines if JSF will render your component in the DOM tree. Your problem is you cannot update a component which is not in the tree because you simply don't have it:
<p:outputPanel id="PanelForm" rendered="#{PageService.isVisibilityForm()}">
//my Form
<p:outputPanel>
<!--Fails if not PageService.isVisibilityForm(), because you don't have the component itself in the tree! So can't find it-->
<p:ajax update="PanelForm"/>
Your best is to wrap your content in another container which is always rendered and update it instead of the other one:
<h:panelGroup id="updatablePanel">
<p:outputPanel rendered="#{PageService.isVisibilityForm()}">
//my Form
<p:outputPanel>
</h:panelGroup>
<p:ajax update="updatablePanel"/>
Related
This is the main view which contains the draggable items. In this view I have a ui:include for including a UI fragment that also has the drop area.
mainView.xhtml
<p:dataList id="outerList" var="varOuter" value="#{myVO.getOuterList()}">
<div>
<span>#{varOuter.someVal}</span>
</div>
<p:dataList id="innerList" var="innerVar" value="#{myVO.getInnerList()}">
<div class="crew-list">
<h:form>
<h:panelGroup id="draggableItem" layout="block">
<span>#{innerVar.someVal}</span>
</h:panelGroup>
<p:draggable for="draggableItem" opacity="0.5" scope="ab"
revert="true" helper="clone" appendTo="#(body)" zindex="4" >
</p:draggable>
</h:form>
</div>
</p:dataList>
</p:dataList>
...
<ui:include src="fragment.xhtml">
<ui:param name="param" value="#{paramVal}" />
</ui:include>
fragment.xhtml
<p:dataList id="list" var="pos" value="#{myVO.getPositions()}" rowIndexVar="rowIndex">
<ui:fragment rendered="#{!pos.isFilled()}">
<h:panelGroup layout="block" id="dropArea">
<span>Drop Here</span>
</h:panelGroup>
<p:droppable for="dropArea" hoverStyleClass="active"
scope="ab" datasource=":outerList:innerList">
<p:ajax listener="#{crewChangeVO.onDrop}" update="list" />
<f:attribute name="index" value="#{rowIndex}" />
</p:droppable>
</ui:fragment>
</p:dataList>
Now the problem that I run into is that, I am unable to map the datasource on the droparea correctly. Without datasource the drag-drop works but I don't get the data (dragged object) in my bean method and I need a way to know which object was dragged.
Would appriciate any input on how to achive this functionality.
Update
Using a single(non-nested) dataList as the source with a form outside it works. But the problem is that it doesn't work for a nested list. So, for now I am proceeding with design changes and removing the nested list.
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 am trying to put a p:commandButton inside a overlayPanel, to submit the information of a h:form and redirect to another view. So, I use the property action of the button to perform this operation. I have a managed bean associated with this view but the function used for this purpose is never reached. Can u help me?
Here is the code:
advancedSearch-form.xhtml
<h:form>
<h:panelGrid width="100%">
<h:column>
....
</h:column>
....
<p:commandButton value="Submit" action="#{searchForm.save}">
</p:commandButton>
</h:panelGrid>
In another xhtml:
<h:form>
<div>
...
<div class="menu-search">
<p:commandButton id="advancedSearch" icon="ui-icon-carat-1-s" styleClass="ui-search-button" type="button"/>
<p:overlayPanel id="advancedSearchPanel" styleClass="ui-advanced-search-overlay" for="advancedSearch" hideEffect="fade" my="right top" dynamic="true" dismissable="false">
<ui:include src="/search/advancedSearch-form.xhtml"/>
</p:overlayPanel>
</div>
...
</div>
After looking over the properties of overlay, I solved this question by removing the dynamic property of overlaypanel.
I am writing a composite component that is intended to wrap an input element, and augment it with an 'optional field' designation and h:message element below it.
Here is the component (in input.xhtml file):
<composite:interface/>
<composite:implementation>
<div>
#{component.children[1].setStyleClass(component.children[1].valid ? '' : 'inputError')}
<composite:insertChildren/>
</div>
<h:panelGroup styleClass="optional"
rendered="#{!component.parent.children[1].required}"
layout="block" >
#{msgs['common.optional.field']}
</h:panelGroup>
<h:message id="msgId"
for="#{component.parent.children[1].id}" errorClass="error"/>
</composite:implementation>
Again, the intended usage of the component is to wrap an h:input* element which is expected to be the first and immediate child of it in a using page.
In a using page I would then write:
<h:form id="f1">
<h:panelGrid border="0" columns="2" style="width: 80%">
<f:facet name="header">
<col width="40%" />
<col width="60%" />
</f:facet>
<h:outputLabel styleClass="sectionBody" for="i1"
value="Input 1"></h:outputLabel>
<my:input id="ii1">
<h:inputText id="i1" size="20" maxlength="20" tabindex="0"
required="true" label="Input 1">
</h:inputText>
</my:input>
<h:outputLabel styleClass="sectionBody" for="i2"
value="Input 2"></h:outputLabel>
<my:input id="ii2">
<h:inputText id="i2" size="20" maxlength="20" tabindex="0"
label="Input 2">
</h:inputText>
</my:input>
</h:panelGrid>
<br />
<h:commandButton value="Submit" tabindex="1">
<f:ajax listener="#{terminalImportBean.addTerminal}"
execute="#form" render="#form"/>
</h:commandButton>
</h:form>
This would work just fine using normal posts.
However if I add add f:ajax validation for "Input 1" (id="i1") and try to re-render the composite (ii1) using the following:
...
<h:outputLabel styleClass="sectionBody" for="i1"
value="Input 1"></h:outputLabel>
<my:input id="ii1">
<h:inputText id="i1" size="20" maxlength="20" tabindex="0"
required="true" label="Input 1">
<f:ajax listener="#{myBean.checkInput1}"
event="blur"
render="ii1"/>
</h:inputText>
</my:input>
...
I gen an error in the browser during ajax response processing:
malformedXML: During update: f1:ii1 not found
I tried using f1:ii1, :f1:ii1, but to no avail. When I use msgId or :f1:ii1:msgId it works. Does anybody know why?
I am using Mojarra 2.1.3
Thanks
That's because the composite component does by itself not render anything to the HTML. Only its children are been rendered to HTML. There does not exist any HTML element with ID f1:i11 in the generated HTML output. Open the page in browser, rightclick and View Source. Look in there yourself. There's no such element with that ID. JavaScript/Ajax is encountering exactly the same problem. It can't find the element in order to update it.
To solve this, you'd need to wrap the entire composite body in a HTML <div> or <span> and assign it an ID of #{cc.clientId} which basically prints UIComponent#getClientId().
<cc:implementation>
<div id="#{cc.clientId}">
...
</div>
</cc:implementation>
Then you can reference it as below:
<my:input id="foo" />
...
<f:ajax ... render="foo" />
You can even reference a specific composite component child.
<f:ajax ... render="foo:inputId" />
See also:
Is it possible to update non-JSF components (plain HTML) with JSF ajax?
How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
I have the following Facelet page:
<ui:define name="content">
<h:form id="selectReport">
<div>
<h:selectOneMenu value="#{reportsController.selectedReport}">
<f:selectItems value="#{reportsController.reportsList}"/>
</h:selectOneMenu>
</div>
<div>
<h:commandButton value="Ir al reporte"
action="#{reportsController.goToReport}"/>
</div>
</h:form>
<h:form id="dateRangeSetupForm"
rendered="#{reportsController.showDateRangeSetupForm}">
<div>
<h:outputLabel value="Desde:"/>
<h:inputText id="fromDate"
value="#{reportsController.fromDate}"/>
</div>
<div>
<h:outputLabel value="Hasta:"/>
<h:inputText id="toDate"
value="#{reportsController.toDate}"/>
</div>
</h:form>
<h:form id="billOfLadingSetupForm"
rendered="#{reportsController.showBillOfLadingSetupForm}">
<div>
<h:outputLabel value="# Factura:"/>
<h:inputText id="invoiceNumber"
value="#{reportsController.invoiceNumber}"/>
</div>
</h:form>
<h:form id="submitForm">
<h:commandButton id="processReport" value="Generar Reporte"
action="#{reportsController.processReport}"/>
<h:commandButton id="goBack" value="Regresar"
action="mainMenu"/>
</h:form>
</ui:define>
In which I let the user select a report, and render a form to setup parameters depending on the report. The problem is that when I render for example the billOfLadingSetupForm and fill the inputText, then click on the processReport button the invoiceNumber property of my bean is not updated, it is set to null.
I have noticed that if I type Return after filling the inputText and then click the processReport button the property does get updated. This is strange I haven't face this problem before. Do you have any idea why this happens?
Whenever a form get submitted, then only the data inside that form will be sent. The data of the other forms won't be sent. That's by HTML specification. You need to put all inputs and buttons which belongs to each other inside the same <h:form>. Replace all your splitted dateRangeSetupForm, billOfLadingSetupForm and submitForm forms by <h:panelGroup> and put them all inside one and same <h:form>.
Something like this:
<ui:define name="content">
<h:form>
<div>
<h:selectOneMenu value="#{reportsController.selectedReport}">
<f:selectItems value="#{reportsController.reportsList}"/>
</h:selectOneMenu>
</div>
<div>
<h:commandButton value="Ir al reporte" action="#{reportsController.goToReport}"/>
</div>
</h:form>
<h:form>
<h:panelGroup id="dateRangeSetupForm" rendered="#{reportsController.showDateRangeSetupForm}">
<div>
<h:outputLabel value="Desde:"/>
<h:inputText id="fromDate" value="#{reportsController.fromDate}"/>
</div>
<div>
<h:outputLabel value="Hasta:"/>
<h:inputText id="toDate" value="#{reportsController.toDate}"/>
</div>
</h:panelGroup>
<h:panelGroup id="billOfLadingSetupForm" rendered="#{reportsController.showBillOfLadingSetupForm}">
<div>
<h:outputLabel value="# Factura:"/>
<h:inputText id="invoiceNumber" value="#{reportsController.invoiceNumber}"/>
</div>
</h:panelGroup>
<h:commandButton id="processReport" value="Generar Reporte" action="#{reportsController.processReport}"/>
<h:commandButton id="goBack" value="Regresar" action="mainMenu"/>
</h:form>
</ui:define>
Make sure that the bean is put in the view scope. Otherwise the conditions for the rendered attribute won't be preserved. See also commandButton/commandLink/ajax action/listener method not invoked or input value not updated