jsf - Dynamic rendering of page using p:layout -
i trying dynamically load page based on selected action in p:layout - action driven managed bean - using code below see managed bean getting called , correct page gets passed not rendered. wondering missing, hoping can point out.
thanks
layout page
<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"> <f:view contenttype="text/html" locale="en"> <h:head title="title"> <ui:insert name="head" /> </h:head> <h:body> <p:layout fullpage="true"> <p:layoutunit position="north" size="100" header="top" resizable="true" closable="true" collapsible="true"> </p:layoutunit> <p:layoutunit position="south" size="100" header="bottom" resizable="true" closable="true" collapsible="true"> </p:layoutunit> <p:layoutunit position="west" size="200" style="width:200px" header="menu" resizable="true" closable="true" collapsible="true"> <h:form id="formmainmenu"> <p:panelmenu style="width:400px"> <p:submenu label="sub menu 1"> <p:submenu label="sub menu 2" icon="ui-icon-extlink"> <p:menuitem value="option1" actionlistener="#{menucontroller.setpage('../../public/pages/abouttest.xhtml')}" update=":alllayoutform:alllayout" /> </p:submenu> </p:submenu> </p:panelmenu> </h:form> </p:layoutunit> <p:layoutunit position="east" size="200" header="right" resizable="true" closable="true" collapsible="true" effect="fade"> </p:layoutunit> <h:form id="alllayoutform"> <p:layoutunit position="center" id="alllayout"> <ui:insert name="content">src="#{menucontroller.page}"</ui:insert> </p:layoutunit> </h:form> </p:layout> </h:body> </f:view> </html>
menu controller
@suppresswarnings("unused") @managedbean @viewscoped public class menucontroller { private string page; public string getpage() { system.out.println(" "+page); return page; } public void setpage(string page) { system.out.println(page); this.page = page; } }
if need have static part of html page used everywhere in application should take jsf template (example here).
maintemplate.xhtml:
<?xml version="1.0" encoding="iso-8859-1"?> <html xmlns="http://www.w3c.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <title><ui:insert name="title">default title</ui:insert></title> </h:head> <h:body> <h:form id="menuform"> <p:menubar model="#{bean.menumodel}" /> </h:form> <ui:insert name="content" /> </h:body> </html>
and page going :
<ui:composition xmlns="http://www.w3c.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:cc="http://java.sun.com/jsf/composite" template="/templates/maintemplate.xhtml"> <ui:define name="title">title page</ui:define> <ui:define name="content"> /* jsf code */ </ui:define> </ui:composition>
with example change content , title of pages easily.
Comments
Post a Comment