I'm using the primefaces layout component and have a center and a right layoutUnit. I would like to have a link/button in the center layout that expands the right layoutUnit as I default the right layout to collapsed state when I first load the page. I'm using a boolean expression on the right layoutUnit and I update it from my link. Everything works except that the right layoutUnit doesn't get ajaxed updated from my link. If I refresh the page the right layoutUnit is expanded.
page:
<h:form prependId="false">
<p:layout fullPage="true">
<p:layoutUnit id="right" position="right" width="350" header="Marker Details" resizable="true" closable="true" collapsible="true" collapsed="#{mapBean.rightCollapsed}">
<h:outputText value="#{mapBean.text}" />
</p:layoutUnit>
<p:layoutUnit position="center">
<p:commandLink actionListener="#{mapBean.showDetail}" update="right" value="Expand Right Layout"/>
</p:layoutUnit>
</p:layout>
</h:form>
Bean:
public class MapBean implements Serializable {
private boolean rightCollapsed=true;
public void showDetail(ActionEvent e){
rightCollapsed=false;
}
//getter/setter for rightCollapsed
See the following forum post about using the <p:layout> component with the fullPage=true attribute.
http://primefaces.prime.com.tr/forum/viewtopic.php?f=3&t=4766
You cannot wrap the layout component in a form like this, each <p:layoutUnit> needs its own nested form. You can still update the components of the other forms by setting the form id and referring to component ids correctly as another answer had suggested. Try something like this:
<p:layout fullPage="true">
<p:layoutUnit id="right" position="right" width="350" header="Marker Details" resizable="true" closable="true" collapsible="true" collapsed="#{mapBean.rightCollapsed}">
<h:form id="rightForm" prependId="false">
<h:outputText id="mapBeanTextOutputText" value="#{mapBean.text}" />
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
<h:form id="centerForm" prependId="false">
<p:commandLink actionListener="#{mapBean.showDetail}" update="mapBeanTextOutputText" value="Expand Right Layout"/>
</h:form>
</p:layoutUnit>
</p:layout>
The problem is maybe that you have not update the layout. You can give the h:form a id ,and use this id replace the commandbutton's update id name ,like this:
<h:form id="layoutForm" prependId="false">
<p:layout fullPage="true">
<p:layoutUnit id="right" position="right" width="350" header="Marker Details" resizable="true" closable="true" collapsible="true" collapsed="#{mapBean.rightCollapsed}">
<h:outputText value="#{mapBean.text}" />
</p:layoutUnit>
<p:layoutUnit position="center">
<p:commandLink actionListener="#{mapBean.showDetail}" update="layoutForm" value="Expand Right Layout"/>
</p:layoutUnit>
</p:layout>
</form>
Related
I currently have an .xhtml that shows a pop up depending on some events in JAVA, now i need that if the pop up shows put the focus on a expecific textfield.
JAVA
public void validate(){
if(List.size()>0){
String [] codes = {"1","97","119","606","695","700","738","730"};
List<String> codesList = Arrays.asList(codes);
String coomentsString ="THIS IS A STRING";
if(codesList.contains(List.get(0).getCode())){
MessageUtil.addInfoMessage(LabelKeys.DOCBR_INFO,coomentsString);
PrimefacesUtil.showMessage();
}
}
}
XHTML
<p:commandButton id="loadPage" action="#CLASS.validate}"/>
<p:inputText id="comments"/>
<script type="text/javascript">
$( document ).ready(function() {
var name= document.getElementById('containerForm:loadPage');
name.click();
});
</script>
XHTML POP UP
<p:dialog id="growl" widgetVar="messagePopupWidget" resizable="false"
modal="true" width="270px" styleClass="messagedialog">
<p:ajax event="close" update="growl"
listener="#{messageDialog.handleCloseDialogMessageEvent}" />
<p:panelGrid style="width:100%;">
<p:row>
<p:column style="text-align:left;">
<p:messages showSummary="true" showDetail="true"
autoUpdate="false" escape="false"/>
</p:column>
</p:row>
<p:row>
<p:column style="text-align:center;">
<p:commandButton id="messageDialogButtonId" value="#{label['messageDialog.btn.ok']}" onclick="messagePopupWidget.hide();" update="growl" type="button"/>
</p:column>
</p:row>
</p:panelGrid>
</p:dialog>
now, i need that after loadPage makes the click on javascript and shows the pop up from validate(), put the cursor on "comments"
Two ways to achieve this with primefaces:
1. Include this in your dialog to set explicit focus
<p:focus for="commentsID"/>
There is an onShow attribute on the dialog, you can use that to set the focus manually
<p:dialog id="loadPage"
onShow="document.getElementById("commentsID").focus();"/>
I use this code:
<p:panel header="Advanced User Data" toggleable="true" toggleOrientation="horizontal" collapsed="true">
some other stuff...
</p:panel>
Is there an attribute with which I can set the title when th panel is closed like this:
example
There is no attribute like this AFAIK. You could bind the value of collapsed attribute to a managed bean and add an AJAX listener on toggle event:
<p:panel header="Advanced User Data" toggleable="true"
toggleOrientation="horizontal" collapsed="#{myBean.booleanVal}" style="display: inline-block;">
<p:ajax event="toggle" process="#this" update="pnlAlternativeTitle" />
</p:panel>
<h:panelGroup id="pnlAlternativeTitle">
<h:outputText rendered="#{myBean.booleanVal}"
value="Alternative title" />
</h:panelGroup>
I have a problem with tabView. The 1st tab should always display the same content (called search template which is identified with #{not curSearch.isClosable()}. All other tabs are search instances (identified with #{curSearch.isClosable()}
Here is the code:
<p:tabView id="searchTabViewId" var="curSearch" value="#{searchBL.searchInstances}"
activeIndex="#{searchBL.activeTabIndex}" styleClass="searchTabView">
<!-- search template tab -->
<ui:include src="/icarchive/sections/search/firstSearchTab.xhtml">
<ui:param name="curSearch" value="#{curSearch}" />
</ui:include>
<!-- search instances tabs -->
<ui:include src="/icarchive/sections/search/searchInstanceTab.xhtml">
<ui:param name="curSearch" value="#{curSearch}" />
</ui:include>
</p:tabView>
Unfortunately there are methods on the 1st tabs curSearch object called which are used on 2nd and following tabs only. If I do not use the ui:insert it does not change anything.
Anybody knows where is my fault?
Regards
Oliver
This works:
<p:tabView id="searchTabViewId" styleClass="searchTabView" activeIndex="#{searchBL.activeTabIndex}">
<!-- do the iteration over the search instances NOT in the tabView because this will not work with ui:include -->
<c:forEach items="#{searchBL.searchInstances}" var="curSearch">
<p:tab closable="#{curSearch.isCloseable()}">
<f:facet name="title">
<p:graphicImage library="images" name="search_tab.png" height="16" styleClass="tabImage"
rendered="#{not curSearch.isCloseable()}" />
<h:outputText value="#{curSearch.title}" />
</f:facet>
<!-- do not use 2 ui:includes here, the dynamic must be in the src attribute to get it work -->
<ui:include
src="#{curSearch.closeable ? '/sections/search/searchInstanceTab.xhtml' : '/sections/search/firstSearchTab.xhtml'}">
<ui:param name="curSearch" value="#{curSearch}" />
</ui:include>
</p:tab>
</c:forEach>
I had the same problem, only solution i found is wrap include in other component and clamp with render which one is displayed. For initial load if you have ids depending on content you will need to set id prefix so that it does not allow empty id fields:
<p:tabView id="tabsView" dynamic="true" cache="true"
value="#{TabViewController.tabView.openedTabs}" var="tabDefinition" activeIndex="#{TabViewController.tabView.activeIndex}">
<p:ajax event="tabClose" listener="#{TabViewController.onCloseTab}" update="tabsView"/>
<p:ajax event="tabChange" update="tabsView"/>
<p:tab id="tab#{tabDefinition.id}" title="#{tabDefinition.title}" closable="true" action="">
<f:facet name="title">
<h:outputText value="#{tabDefinition.title}"/>
</f:facet>
<p:outputPanel style="display:block" rendered="#{'dataTable'.equals(tabDefinition.type)}">
<ui:include src="dataTable.xhtml">
<ui:param name="dataTableName" value="#{tabDefinition.contentName}"/>
</ui:include>
</p:outputPanel>
<p:outputPanel style="display:block" rendered="#{'form'.equals(tabDefinition.type)}">
<ui:include src="form.xhtml">
<ui:param name="formId" value="#{tabDefinition.id}"/>
<ui:param name="formName" value="#{tabDefinition.contentName}"/>
</ui:include>
</p:outputPanel>
</p:tab>
</p:tabView>
Commandbutton with id("myButtonId2") works fine. I mean it updates "myOutputPanel"
but commandbutton(myButtonId) which is inside datatable doesn't update outputPanel. I found the suggestions and tried with the following,
update=":myForm:myOutputPanel"
update="#myForm"
update=":myOutputPanel"
But none of them worked...
Here is the snippet...
<h:form id="myForm" prependId="false">
<p:panel id="myPanel">
<p:dataTable id="myDatatable">
<p:column style="width:4%">
<p:commandButton id="myButtonId" actionListener="#{bean.showPanel}" update="myOutputPanel"/>
</p:column>
</p:dataTable>
<p:commandButton id="myButtonId2" update="myOutputPanel"/>
</p:panel>
<p:outputPanel id="myOutputPanel" rendered="#{bean.show}">
//some stuff
</p:outputPanel>
Try to put your <p:outputPanel /> inside a <p:panel />
and add a "widgetVar" attribute
For example : <p:panel widgetVar="var" [..]>
and just update the panel directly with update="#widgetVar(var)"
I have this piece of code:
<h:body>
<h:form id="form1">
<p:menuButton value="#{msgs.settingsMenuButton}">
<p:menuitem value="#{msgs.accountsMenuItem}" url="#" update=":dlgEdit" oncomplete="_dlgEdit.show()"/>
</p:menuButton>
<p:commandButton value="Accounts" icon="ui-icon-gear"
update=":dlgEdit"
oncomplete="_dlgEdit.show()"/>
</h:form>
<p:dialog id="dlgEdit" widgetVar="_dlgEdit" modal="true" closable="true" header="Accounts">
<h:form id="frmEdit" >
<p:panelGrid id="pnlEdit" columns="2">
<p:outputLabel id="lblName" for="eName" value="Name"/>
<p:inputText id="eName" value="#{tasksBean.selectedLocation}"/>
</p:panelGrid>
</h:form>
</p:dialog>
</h:body>
The dialog is not displayed when the menuItem is selected but it works when the commandButton is pressed.
The behaviors for both are the same...
Can you support me please?
Thanks,
Andrei
Try:
oncomplete="PF('_dlgEdit').show();"