The dynamic interface includes in the Interfaces dialog box

I am working on a school project and ran into the problem of dynamic ui insertion. I am currently working in JSF2.0 / Primefaces 3 M1. The main problem is that I want to have a Primefaces dialog with dynamic content that changes using the menu bar.

The dialog component contains the ui: include tag with src set to the bean managed property. Menu items are associated with bean methods that modify this property.

The main problem is that the variable does not change at all, I am currently using warnings to display this variable. I am currently working with remoteCommand, but I have already tried working with action / actionlistener in the menuitem component. Any help would be appreciated.

This is the main page with a menu and dialogue.

<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-transitional.dtd"> <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.prime.com.tr/ui" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <title>KunstInHuis: Main</title> </h:head> <h:body style="font-size: 12px;"> <h:form id="mainForm"> <f:metadata> <f:event type="preRenderView" listener="#{login.verifyAccess}"/> </f:metadata> <p:remoteCommand name="lazyANew" actionListener="#{main.goToAboNew}" onsuccess="alert('test')"/> <p:remoteCommand name="lazyAList" actionListener="#{main.goToAboList}" onsuccess="alert('test')" /> <p:remoteCommand name="lazyASearch" actionListener="#{main.goToAboSearch}" onsuccess="alert('test')" /> <p:menubar autoSubmenuDisplay="true"> <p:submenu label="Abonnementen"> <p:menuitem value="Nieuw" onclick="lazyANew()" onsuccess="alert('#{main.goToPage}')"/> <p:menuitem value="Lijst" onclick="lazyAList()" onsuccess="alert('#{main.goToPage}')" /> <p:menuitem value="Zoek" onclick="lazyASearch()" onsuccess="alert('#{main.goToPage}')"/> </p:submenu> <p:submenu label="Klanten"> <p:menuitem value="Nieuw" url="#" /> <p:menuitem value="Lijst" url="#"/> </p:submenu> <p:submenu label="Kunstwerken"> <p:menuitem value="Nieuw" url="#" /> <p:menuitem value="Lijst" url="#"/> </p:submenu> </p:menubar> </h:form> <p:dialog id="mainDialog" header="Abonnement aanmaken" widgetVar="dlg0" minHeight="300" minWidth="450" resizable="true" modal="false" > <ui:include src="#{main.goToPage}" /> </p:dialog> </h:body> 

And this is my bean support.

 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.page.beans; import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import javax.faces.event.ActionEvent; /** * * @author wezlee */ @ManagedBean(name = "main") @ViewScoped public class mainMenuBean implements Serializable { private boolean panelRender=false; private String goToPage = "./includes/forms/abboCreate.xhtml"; /** Creates a new instance of mainMenuBean */ public mainMenuBean() { } public void goToAboNew(ActionEvent e){ goToPage="./includes/forms/abboCreate.xhtml"; } public void goToAboNew(){ goToPage="./includes/forms/abboCreate.xhtml"; } public void goToAboList(ActionEvent e){ goToPage="./includes/forms/abboList.xhtml"; } public void goToAboList(){ goToPage="./includes/forms/abboList.xhtml"; } public void goToAboSearch(ActionEvent e){ goToPage="./includes/forms/abboSearch.xhtml"; } public void goToAboSearch(){ goToPage="./includes/forms/abboSearch.xhtml"; } /** * @return the goToPage */ public String getGoToPage() { return goToPage; } public void setGoToPage(String src){ this.goToPage=src; } } 
+6
source share
1 answer

In fact, I think the support value updating methods look like they are working fine. Probably the problem is how you are trying to display it. When the page is initially displayed, the value for goToPage is evaluated and placed in the contents of the page returned to the user's browser. When this value is set on the user side, it will not be re-synchronized with the backup bean until this part of the page is re-displayed.

I believe that the grand face of remoteCommand allows you to do this using AJAX, using update = "client side id". Of course, I'm not a first-person guy, so I put together this little test. First change your remote commands:

 <p:remoteCommand name="lazyANew" actionListener="#{main.goToAboNew}" update="testOutput" /> <p:remoteCommand name="lazyAList" actionListener="#{main.goToAboList}" update="testOutput" /> <p:remoteCommand name="lazyASearch" actionListener="#{main.goToAboSearch}" update="testOutput" /> 

Then add a simple text box to the contents of your page with the corresponding Id:

 Page target: <h:outputText value="#{main.goToPage}" id="testOutput" /> 

Your output text should begin to sync. While this works, you can simply redirect the update from testOutput to mainDialog, and you should be in business.

+1
source

Source: https://habr.com/ru/post/889120/


All Articles