pmblatino wrote:but i wanna be able to manipulate them dynamically from the bean im working from not the template
any ideas would be apreciated, in the mean time im using the solution i made in the first post
Thanks again!
Below is how I'm manipulating layout panel options 'per' JSF view. Below, is my layoutController bean. I would love to save the state of the layout 'pane' everytime enduser opens/closes layout panes, but the code below does not do that 'yet'.
Code: Select all
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pf;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import org.primefaces.extensions.component.layout.LayoutPane;
import org.primefaces.extensions.event.ResizeEvent;
import org.primefaces.extensions.model.layout.LayoutOptions;
/**
*
* @author Administrator
*/
@ManagedBean(name = "layoutController")
@SessionScoped
public class LayoutController implements Serializable {
private LayoutOptions layoutOptions;
@ManagedProperty("#{pageNavigationController}")
private PageNavigationController pageNavigationController;
private static Boolean debug;
private static List<String> pagesWithLayoutPane;
public LayoutController() {
debug = false;
pagesWithLayoutPane = new ArrayList<>();
pagesWithLayoutPane.add("/orders/pf_Add.xhtml");
pagesWithLayoutPane.add("/orders/pf_Edit.xhtml");
pagesWithLayoutPane.add("/orders/pf_BrowseAuditTrail.xhtml");
pagesWithLayoutPane.add("/orders/pf_BrowsePayroll.xhtml");
pagesWithLayoutPane.add("/orders/pf_BrowseDriverMoney.xhtml");
pagesWithLayoutPane.add("/orders/pf_InvoiceForOrders.xhtml");
pagesWithLayoutPane.add("/orders/pf_BrowseCalendar.xhtml");
pagesWithLayoutPane.add("/orders/pf_BrowseCalendarEditable.xhtml");
}
@PostConstruct
protected void initialize() {
if (debug) {
System.out.println("LayoutController.initialize() BEGIN");
}
String page = pageNavigationController.getPage();
if (debug) {
System.out.println("LayoutController.initialize() BEFORE initializeForPage(" + page + ")");
}
initializeForPage(page);
if (debug) {
System.out.println("LayoutController.initialize() END");
}
}
public void initializeForPage(String page) {
if (debug) {
System.out.println("LayoutController.initializeForPage(" + page + ") BEGIN");
}
Boolean pageWithLayoutPane = isPageWithLayoutPane(page);
if (debug) {
System.out.println("LayoutController.initializeForPage() pageWithLayoutPane = " + pageWithLayoutPane + ")");
}
Integer pageWithLayoutPaneNorthSize = 0;
if (pageWithLayoutPane) {
if (page.equals("/orders/pf_Add.xhtml")) {
pageWithLayoutPaneNorthSize = 50;
}
else if (page.equals("/orders/pf_Edit.xhtml")) {
pageWithLayoutPaneNorthSize = 200;
}
else if (page.equals("/orders/pf_BrowseAuditTrail.xhtml")) {
pageWithLayoutPaneNorthSize = 160;
}
else if (page.equals("/orders/pf_BrowsePayroll.xhtml")) {
pageWithLayoutPaneNorthSize = 125;
}
else if (page.equals("/orders/pf_BrowseDriverMoney.xhtml")) {
pageWithLayoutPaneNorthSize = 160;
}
else if (page.equals("/orders/pf_InvoiceForOrders.xhtml")) {
pageWithLayoutPaneNorthSize = 170;
}
else if (page.startsWith("/orders/pf_BrowseCalendar")) {
pageWithLayoutPaneNorthSize = 150;
}
}
if (debug) {
System.out.println("LayoutController.initializeForPage() pageWithLayoutPaneNorthSize = " + pageWithLayoutPaneNorthSize + ")");
}
layoutOptions = new LayoutOptions();
// options for all panes
LayoutOptions panes = new LayoutOptions();
panes.addOption("slidable", false);
panes.addOption("spacing", 6);
panes.addOption("resizeWhileDragging", false);
layoutOptions.setPanesOptions(panes);
LayoutOptions north = new LayoutOptions();
north.addOption("resizable", false);
north.addOption("size", 100);
layoutOptions.setNorthOptions(north);
// options for center pane
LayoutOptions center = new LayoutOptions();
if (pageWithLayoutPane) {
center.addOption("closable", false);
center.addOption("resizable", false);
center.addOption("minWidth", 200);
center.addOption("minHeight", pageWithLayoutPaneNorthSize);
}
else {
}
layoutOptions.setCenterOptions(center);
if (pageWithLayoutPane) {
// options for nested center layout
LayoutOptions childCenterOptions = new LayoutOptions();
center.setChildOptions(childCenterOptions);
// options for center-north pane
LayoutOptions centerNorth = new LayoutOptions();
centerNorth.addOption("resizable", false);
centerNorth.addOption("size", pageWithLayoutPaneNorthSize);
childCenterOptions.setNorthOptions(centerNorth);
// options for center-center pane
LayoutOptions centerCenter = new LayoutOptions();
centerCenter.addOption("minHeight", pageWithLayoutPaneNorthSize);
childCenterOptions.setCenterOptions(centerCenter);
}
if (debug) {
System.out.println("LayoutController.initializeForPage(" + page + ") END");
}
}
public Boolean isPageWithLayoutPane(String page) {
Boolean returnValue = false;
for (String pageWithLayoutPane : pagesWithLayoutPane) {
if (page.equals(pageWithLayoutPane)) {
returnValue = true;
break;
}
}
return returnValue;
}
public LayoutOptions getLayoutOptions() {
return layoutOptions;
}
public void setPageNavigationController(PageNavigationController pageNavigationController) {
this.pageNavigationController = pageNavigationController;
}
}
Also, every time other controller beans change the value of pageNavigationController.page, I re-initialize the layout panel options. Below, is code that does this. This code is in pageNavigationController. Look at how I call getLayoutController().initializeForPage(page).
Code: Select all
public void setPage (String page) {
if (page == null || page.length() <= 0)
setToBlankPage();
else if (this.page != page) {
this.previousPage = this.page;
this.page = page;
if (previousPage.startsWith("/orders") && !page.startsWith("/orders"))
clearOrdersBrowseScheduleOption();
getLayoutController().initializeForPage(page);
}
}
And by the way, my xhtml is as follows:
Code: Select all
<pe:layout id="fullPageLayout" options="#{layoutController.layoutOptions}"
widgetVar="layoutWidget">
<pe:layoutPane position="north">
<ui:include src="#{pageNavigationController.pageMenu}"/>
</pe:layoutPane>
<pe:layoutPane position="center">
<ui:include src="/loadingImage.xhtml"/>
<p:outputPanel id="pageContentPanel" layout="block"
styleClass="#{layoutController.isPageWithLayoutPane(pageNavigationController.page) ? 'ui-layout-content' : null}"
style="width: 100%; height: 100%">
<ui:include src="#{pageNavigationController.page}"/>
</p:outputPanel>
<h:form id="pollNotificationsForm">
<p:growl id="notifications" widgetVar="growl"
life="60000" showDetail="true" showSummary="true" escape="false"/>
<p:poll listener="#{pf_usersController.checkNotifications()}"
update="notifications" interval="20" global="false"/>
</h:form>
</pe:layoutPane>
</pe:layout>