创建程序菜单(动态)PrimeFaces - 重定向子菜单中的错误

时间:2015-07-30 23:06:42

标签: java jsf-2 primefaces

我需要一些支持,我不知道可能是什么:

我正在使用JSF 2和 Primefaces ,开发一个我需要动态创建 MenuBar 的网站,我正在使用动态菜单的基本结构Primefaces(MenuModel):

DefaultMenuModel - > DefaultSubMenu - > DefaultMenuItem

对于我的页面,我正在创建一个会话bean,它负责创建我的菜单(如果有必要)并重新创建(如果有任何更改),一切正常,我的菜单创建了所有参数(结果)和其他方法(行动)。

我的问题是当我点击菜单中的各个子菜单时,我的菜单会一次又一次丢失,我的系统会抛出异常

更好的例子:

通过更好地解释:

我点击了一个子菜单,它将我重定向到另一个页面 这个另一个页面我再次点击另一个子菜单,它将我重定向到另一个页面, 等等....

我正在使用:

PrimeFaces 5.1

这是我的例外:

java.lang.ClassCastException: org.primefaces.model.menu.DefaultSubMenu
at org.primefaces.component.menu.BaseMenuRenderer.findMenuitem(BaseMenuRenderer.java:90)
at org.primefaces.component.menu.BaseMenuRenderer.decode(BaseMenuRenderer.java:61)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:787)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1181)
at javax.faces.component.UIForm.processDecodes(UIForm.java:225)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at org.primefaces.component.layout.Layout.processDecodes(Layout.java:226)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at org.primefaces.component.layout.Layout.processDecodes(Layout.java:226)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:933)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:352)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:75)
at com.ford.fc.adr.jpa.JPAFilter.doFilter(Unknown Source)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:75)
at com.ford.fc.atd.servlet.filter.AbstractFilter.invokeNextFilter(Unknown Source)
at com.ford.fc.atd.servlet.filter.AbstractFilter.doFilter(Unknown Source)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:75)
at com.ford.fc.atd.servlet.filter.AbstractFilter.invokeNextFilter(Unknown Source)
at com.ford.fc.atd.servlet.filter.AbstractFilter.doFilter(Unknown Source)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:75)
at com.ford.fc.atd.servlet.filter.AbstractFilter.invokeNextFilter(Unknown Source)
at com.ford.fc.atd.servlet.filter.AbstractFilter.doFilter(Unknown Source)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:75)
at com.ford.fc.atd.servlet.filter.XSSParameterEncodingFilter.doFilter(Unknown Source)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:75)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:105)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:75)
at com.ford.fc.atd.servlet.filter.AbstractFilter.invokeNextFilter(Unknown Source)
at com.ford.fc.atd.servlet.filter.AbstractFilter.doFilter(Unknown Source)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:75)
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:63)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:75)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:75)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3288)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3254)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2163)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2091)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1512)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

这是我的Bean代码:

//more imports

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

import org.primefaces.event.MenuActionEvent;
import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.model.menu.DefaultMenuModel;
import org.primefaces.model.menu.DefaultSubMenu;
import org.primefaces.model.menu.MenuItem;
import org.primefaces.model.menu.MenuModel;

//more imports

@ManagedBean
@SessionScoped
public class MenuBean extends BaseResourcePage {

    /**
     * Serial Id.
     */
    private static final long serialVersionUID = -3250501071227237715L;

    /**
     * 
     */
    private static final String LOG_FACILITY = MenuBean.class.getPackage().getName();


    @ManagedProperty(value="#{BEANAuth}")
    private BEANAuthBean BEANAuth;

    @Inject
    UserSession userSession;

    private MenuModel mainMenu;

    private MenuModel breadCrump;

    private CountryEntity selectedcountry = new CountryEntity();

    private static final String DOT_TITLE = ".title";

    private static final String MODIFY = "modify";

    private static final String VIEW = "view";

    public MenuModel getBreadCrumb() {
        if(this.userSession.getCountryUsed() != null && this.breadCrump == null) {
            Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "getBreadCrumb = CREATE A BREADCRUMB");
            createHomeElementBreadcrumb();
        }

        Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "getBreadCrumb = In here");
        if(this.breadCrump != null) {
            Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "getBreadCrumb = SIZE ELEMENTS " + this.breadCrump.getElements().size());
        }
        return this.breadCrump;
    }

    private void createHomeElementBreadcrumb() {

        DefaultMenuItem homeElement = new DefaultMenuItem();
        homeElement.setId("homeBreadcumb");
        homeElement.setValue("Home");
        homeElement.setTitle("Home");
        homeElement.setCommand("#{menuBean.doClearBreadCrumb}");
        homeElement.setParam("outcome", new String("homePage"));
        homeElement.setAjax(false); // TODO REMOVE AJAX TRANSACTION

        this.breadCrump = new DefaultMenuModel();
        this.breadCrump.addElement(homeElement);
    }

    public String doClearBreadCrumb(MenuActionEvent  event) {
        String outcome = event.getMenuItem().getParams().get("outcome").get(0);
        createHomeElementBreadcrumb();
        Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "doClearBreadCrumb(MenuActionEvent) = OutCome : " + outcome);
        return outcome;
    }

    public String doClearBreadCrumb() {
        createHomeElementBreadcrumb();
        Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "doClearBreadCrumb = OutCome : homePage");
        return "homePage";
    }

    public MenuModel getMenuModel() throws CloneNotSupportedException {
        if(userSession.getCountryUsed() != null 
                && !userSession.getCountryUsed().equals(this.selectedcountry)) {
            Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "getMenuModel = CREATE A MAIN MENU");
            this.selectedcountry = this.userSession.getCountryUsed().clone();
            createMenu();
        }
        Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "getMenuModel = In here");

        if(this.mainMenu != null) {
            Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "getMenuModel = SIZE ELEMENTS " + this.mainMenu.getElements().size());
        }

        return this.mainMenu;
    }

    private void createMenu() {
        this.mainMenu = new DefaultMenuModel();

        //TODO ACCESS MENU ????
        createDocumentAndAcceptsMenu();
        createJudicialAssignmentMenu();
        createAgreementMenu();
        createGeneralMenu();
        createReportsMenu();
        createPaymentFeesMenu();
        createPayLegalFeesMenu();
        createProcessesMenu();
        createRepossessionMenu();
        createRecordsMenu();
    }

    private void createDocumentAndAcceptsMenu() {
        Map<String, NavigationEnum> documentAndAcceptsItems = new HashMap<String, NavigationEnum>();
        documentAndAcceptsItems.put(new String("documentAndAccepts.acceptsProcess"), ACCEPTS_PROCESS);
        documentAndAcceptsItems.put(new String("documentAndAccepts.sendReceiveDocuments"), SEND_RECEIVE_DOCUMENTS);

        DefaultSubMenu documentAndAcceptsMenu = createMenuItems(documentAndAcceptsItems);
        documentAndAcceptsMenu.setLabel(getResourceAccessValue("menu.documentAndAccepts"));
        documentAndAcceptsMenu.setId(getResourceAccessValue("menu.documentAndAccepts") + "Id");


        this.mainMenu.addElement(documentAndAcceptsMenu);
    }

    private void createJudicialAssignmentMenu() {
        Map<String, NavigationEnum> judicialAssignmentItems = new HashMap<String, NavigationEnum>();
        judicialAssignmentItems.put(new String("judicialAssignment.lawyersAllocationByUser"), LAWYERS_ALLOCATION_BY_USER);
        judicialAssignmentItems.put(new String("judicialAssignment.judgmentLawyerAndDetermination"), JUDGMENT_LAWYER_AND_DETERMINATION);
        judicialAssignmentItems.put(new String("judicialAssignment.documentsRequestedList"), DOCUMENTS_REQUESTED_LIST);
        judicialAssignmentItems.put(new String("judicialAssignment.generalProcessAndFollowUps"), GENERAL_PROCESSAND_FOLLOW_UPS);
        judicialAssignmentItems.put(new String("judicialAssignment.preAssignmentFocus"), PRE_ASSIGNMENT_FOCUS);
        judicialAssignmentItems.put(new String("judicialAssignment.documentsRequestedBranch"), DOCUMENTS_REQUESTED_BRANCH);

        DefaultSubMenu judicialAssignmentMenu = createMenuItems(judicialAssignmentItems);
        judicialAssignmentMenu.setLabel(getResourceAccessValue("menu.judicialAssignment"));
        judicialAssignmentMenu.setId(getResourceAccessValue("menu.judicialAssignment") + "Id");
        this.mainMenu.addElement(judicialAssignmentMenu);
    }

    private void createAgreementMenu() {
        Map<String, NavigationEnum> agreementItems = new HashMap<String, NavigationEnum>();
        agreementItems.put(new String("agreement.followAgreement"), FOLLOW_AGREEMENT);
        agreementItems.put(new String("agreement.agreement"), AGREEMENT);
        agreementItems.put(new String("agreement.monthlyAgreement"), MONTHLY_AGREEMENT);

        DefaultSubMenu agreementMenu = createMenuItems(agreementItems);
        agreementMenu.setLabel(getResourceAccessValue("menu.agreement"));
        agreementMenu.setId(getResourceAccessValue("menu.agreement") + "Id");
        this.mainMenu.addElement(agreementMenu);
    }

    private void createGeneralMenu() {
        Map<String, NavigationEnum> generalItems = new HashMap<String, NavigationEnum>();
        generalItems.put(new String("general.branchRegion"), BRANCH_REGION);
        generalItems.put(new String("general.bucketsAging"), BUCKET_SAGING);
        generalItems.put(new String("general.filesSearch"), FILES_SEARCH);
        generalItems.put(new String("general.expenses"), EXPENSES);
        generalItems.put(new String("general.maintenanceControlFiles"), MAINTENANCE_CONTROL_FILES);
        generalItems.put(new String("general.keyTableMaintenance"), KEY_TABLE_MAINTENANCE);
        generalItems.put(new String("general.workdaysMaintenance"), WORKDAYS_MAINTENANCE);
        generalItems.put(new String("general.maintenanceMenu"), MAINTENANCE_MENU);
        generalItems.put(new String("general.parametersMaintenance"), PARAMETERS_MAINTENANCE);
        generalItems.put(new String("general.percentageFeesMaintenance"), PERCENTAGE_FEES_MAINTENANCE);
        generalItems.put(new String("general.tableSubkeyMaintenance"), TABLE_SUBKEY_MAINTENANCE);
        generalItems.put(new String("general.userTypeMaintenance"), USER_TYPE_MAINTENANCE);
        generalItems.put(new String("general.documentationTutorial"), DOCUMENTATION_TUTORIAL);

        DefaultSubMenu generalMenu = createMenuItems(generalItems);
        generalMenu.setLabel(getResourceAccessValue("menu.general"));
        generalMenu.setId(getResourceAccessValue("menu.general") + "Id");
        this.mainMenu.addElement(generalMenu);
    }

    private void createReportsMenu() {
        Map<String, NavigationEnum> reportsItems = new HashMap<String, NavigationEnum>();
        reportsItems.put(new String("reports.agingNoJudicialCollection"), AGING_NO_JUDICIAL_COLLECTION);
        reportsItems.put(new String("reports.agingLegalCollection"), AGING_LEGAL_COLLECTION);
        reportsItems.put(new String("reports.compass"), COMPASS);
        reportsItems.put(new String("reports.eventsOrCompass"), COMPASS_OR_NEWS);
        reportsItems.put(new String("reports.events"), EVENTS);
        reportsItems.put(new String("reports.legalExpenses"), LEGAL_EXPENSES);
        reportsItems.put(new String("reports.generalPayments"), GENERAL_PAYMENTS);
        reportsItems.put(new String("reports.harshDataReport"), HARSH_DATA_REPORT);
        reportsItems.put(new String("reports.assignmentsHistory"), ASSIGNMENTS_HISTORY);
        reportsItems.put(new String("reports.contractValuesHistory"), CONTRACT_VALUES_HISTORY);
        reportsItems.put(new String("reports.lawyerFees"), LAWYER_FEES);
        reportsItems.put(new String("reports.agenciesFees"), AGENCIES_FEES);
        reportsItems.put(new String("reports.listOfEmbargoedGoods"), LIST_OF_EMBARGOED_GOODS);
        reportsItems.put(new String("reports.reportOfSupervisor"), REPORT_OF_SUPERVISOR);
        reportsItems.put(new String("reports.paymentsByDate"), PAYMENTS_BY_DATE);
        reportsItems.put(new String("reports.reportBreakDownRecuperation"), REPORT_BREAK_DOWN_RECUPERATION);
        reportsItems.put(new String("reports.lawyerPaymentsSummary"), LAWYER_PAYMENTS_SUMMARY);
        reportsItems.put(new String("reports.stagesSummary"), STAGES_SUMMARY);
        reportsItems.put(new String("reports.summaryByEvents"), SUMMARY_BY_EVENTS);

        DefaultSubMenu reportsMenu = createMenuItems(reportsItems);
        reportsMenu.setLabel(getResourceAccessValue("menu.reports"));
        reportsMenu.setId(getResourceAccessValue("menu.reports") + "Id");
        this.mainMenu.addElement(reportsMenu);
    }

    private void createPaymentFeesMenu() {
        Map<String, NavigationEnum> paymentFeesItems = new HashMap<String, NavigationEnum>();
        paymentFeesItems.put(new String("paymentFees.activationFees"), ACTIVATION_FEES);
        paymentFeesItems.put(new String("paymentFees.cancelPayFees"), CANCEL_PAY_FEES);
        paymentFeesItems.put(new String("paymentFees.paymentFeesGenerate"), PAYMENT_FEES_GENERATE);
        paymentFeesItems.put(new String("paymentFees.paymentFeesList"), PAYMENT_FEES_LIST);
        paymentFeesItems.put(new String("paymentFees.effectiveFeesPayment"), EFFECTIVE_FEES_PAYMENT);

        DefaultSubMenu paymentFeesMenu = createMenuItems(paymentFeesItems);
        paymentFeesMenu.setLabel(getResourceAccessValue("menu.paymentFees"));
        paymentFeesMenu.setId(getResourceAccessValue("menu.paymentFees") + "Id");
        this.mainMenu.addElement(paymentFeesMenu);
    }

    private void createPayLegalFeesMenu() {
        Map<String, NavigationEnum> payLegalFeesItems = new HashMap<String, NavigationEnum>();
        payLegalFeesItems.put(new String("payLegalFees.payLegalFeesActivation"), PAY_LEGAL_FEES_ACTIVATION);
        payLegalFeesItems.put(new String("payLegalFees.cancelPayLegalFees"), CANCEL_PAY_LEGAL_FEES);
        payLegalFeesItems.put(new String("payLegalFees.generatePayLegalFees"), GENERATE_PAY_LEGAL_FEES);
        payLegalFeesItems.put(new String("payLegalFees.reportPayLegalFees"), REPORT_PAY_LEGAL_FEES);
        payLegalFeesItems.put(new String("payLegalFees.payLegalFees"), PAY_LEGAL_FEES);

        DefaultSubMenu payLegalFeesMenu = createMenuItems(payLegalFeesItems);
        payLegalFeesMenu.setLabel(getResourceAccessValue("menu.payLegalFees"));
        payLegalFeesMenu.setId(getResourceAccessValue("menu.payLegalFees") + "Id");
        this.mainMenu.addElement(payLegalFeesMenu);
    }

    private void createProcessesMenu() {
        Map<String, NavigationEnum> agreementItems = new HashMap<String, NavigationEnum>();
        agreementItems.put(new String("processes.assignExternalAgencies"), ASSIGN_EXTERNAL_AGENCIES);
        agreementItems.put(new String("processes.specialEventChanges"), SPECIAL_EVENT_CHANGES);
        agreementItems.put(new String("processes.loadEvents"), LOAD_EVENTS);
        agreementItems.put(new String("processes.loadJudicialEvents"), LOAD_JUDICIAL_EVENTS);
        agreementItems.put(new String("processes.guarantorInquiry"), GUARANTOR_INQUIRY);
        agreementItems.put(new String("processes.legalCustomerInquiry"), LEGAL_CUSTOMER_INQUIRY);
        agreementItems.put(new String("processes.contractInquiry"), CONTRACT_INQUIRY);
        agreementItems.put(new String("processes.legalClaim"), LEGAL_CLAIM);
        agreementItems.put(new String("processes.embargoedGoods"), EMBARGOED_GOODS);
        agreementItems.put(new String("processes.sentence"), SENTENCE);

        DefaultSubMenu processesMenu = createMenuItems(agreementItems);
        processesMenu.setLabel(getResourceAccessValue("menu.processes"));
        processesMenu.setId(getResourceAccessValue("menu.processes") + "Id");
        this.mainMenu.addElement(processesMenu);
    }

    private void createRepossessionMenu() {
        Map<String, NavigationEnum> repossessionItems = new HashMap<String, NavigationEnum>();
        repossessionItems.put(new String("repossession.vehicleStorage"), VEHICLE_STORAGE);
        repossessionItems.put(new String("repossession.repossessionReport"), REPOSSESSION_REPORT);
        repossessionItems.put(new String("repossession.repossessionVoluntarySurrender"), REPOSSESSION_VOLUNTARY_SURRENDER);

        DefaultSubMenu repossessionMenu = createMenuItems(repossessionItems);
        repossessionMenu.setLabel(getResourceAccessValue("menu.repossession"));
        repossessionMenu.setId(getResourceAccessValue("menu.repossession") + "Id");
        this.mainMenu.addElement(repossessionMenu);
    }

    private void createRecordsMenu() {
        Map<String, NavigationEnum> recordsItems = new HashMap<String, NavigationEnum>();
        recordsItems.put(new String("records.stages"), STAGES);
        recordsItems.put(new String("records.usersDealerDEList"), USERS_DEALER_DE_LIST);
        recordsItems.put(new String("records.dealerExternalAgenciesList"), DEALER_EXTERNAL_AGENCIES_LIST);
        recordsItems.put(new String("records.postalCodesRangeExternalAgencies"), POSTAL_CODES_RANGE_EXTERNAL_AGENCIES);
        recordsItems.put(new String("records.eventTableList"), EVENT_TABLE_LIST);
        recordsItems.put(new String("records.externalAgenciesAndLawyersMaintenance"), EXTERNAL_AGENCIES_AND_LAWYERS_MAINTENANCE);
        recordsItems.put(new String("records.maintenanceBusinessCategory"), MAINTENANCE_BUSINESS_CATEGORY);
        recordsItems.put(new String("records.instituteMaintenance"),  INSTITUTE_MAINTENANCE);
        recordsItems.put(new String("records.steps"), STEPS);

        DefaultSubMenu recordMenu = createMenuItems(recordsItems);
        recordMenu.setLabel(getResourceAccessValue("menu.records"));
        recordMenu.setId(getResourceAccessValue("menu.records") + "Id");

        //TODO test for add or not a menu without a result inside
        if(!recordMenu.isRendered()) {
            this.mainMenu.addElement(recordMenu);
        }
    }


    private DefaultSubMenu createMenuItems(final Map<String, NavigationEnum> menuItens) {

        DefaultSubMenu defaultSubMenu = new DefaultSubMenu();   

        for (String keyItem : menuItens.keySet()) {
            String resourceRule = getResourceRuleMenu(keyItem);

            if(BEANAuth.hasResPermission(resourceRule)) {
                String destination = menuItens.get(keyItem).getDestination();

                DefaultMenuItem menuItem = new DefaultMenuItem();
                menuItem.setId(destination + "MenuItemID");
                menuItem.setValue(getResourceAccessValue(keyItem));
                menuItem.setTitle(getResourceAccessValue(new StringBuilder(keyItem).append(DOT_TITLE).toString()));
                menuItem.setCommand("#{menuBean.addElementBreadcrumByMenu}");
                menuItem.setParam("outcome", destination);
                menuItem.setAjax(false); // TODO REMOVE AJAX TRANSACTION
                menuItem.setImmediate(true);
                menuItem.setUpdate(":mainMenuForm, :breadCrumbForm");

                Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "createMenuItems = ID MENU ITEM " + menuItem.getId());
                defaultSubMenu.addElement(menuItem);
            }
        }

        defaultSubMenu.setRendered(!defaultSubMenu.getElements().isEmpty());
        return defaultSubMenu;
    }

    private String getResourceRuleMenu(String keyItem) {
        return new StringBuilder(keyItem).append(":").append(VIEW).append(",").append(keyItem).append(":").append(MODIFY).toString();
    }

    public String addElementBreadcrumByMenu(MenuActionEvent  event) {
        MenuItem menuItem = event.getMenuItem();
        String outcome = menuItem.getParams().get("outcome").get(0);
        createHomeElementBreadcrumb();
        createElementBreadcrum(menuItem, outcome);
        Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "addElementBreadcrumByMenu(MenuActionEvent) = OutCome : " + outcome);
        return outcome;
    }

    public String addElementBreadcrumByMenuButton(MenuActionEvent  event) {
        MenuItem menuItem = event.getMenuItem();
        String outcome = menuItem.getParams().get("outcome").get(0);
        createElementBreadcrum(menuItem, outcome);
        Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "addElementBreadcrumByMenuButton(MenuActionEvent) = OutCome : " + outcome);
        return outcome;
    }

    private void createElementBreadcrum(MenuItem menuItem, String outcome) {
        DefaultMenuItem menuItemBreadCrump = new DefaultMenuItem();
        menuItemBreadCrump.setValue(menuItem.getValue());
        menuItemBreadCrump.setTitle(menuItem.getTitle());
        menuItemBreadCrump.setOutcome(outcome);

        menuItemBreadCrump.setAjax(false); // TODO REMOVE AJAX TRANSACTION

        Logger.getInstance().log(Severity.DEBUG, LOG_FACILITY, "createElementBreadcrum(MenuActionEvent) = OutCome : " + outcome);
        this.breadCrump.addElement(menuItem);
    }

    /**
     * Set BEANAuth Managed Bean for Injection.
     * 
     * @param BEANAuthBean
     */
    public void setBEANAuth(BEANAuthBean BEANAuthBean) {
        BEANAuth = BEANAuthBean;
    }
}

我创建的菜单图片:

enter image description here

enter image description here

enter image description here

我尝试过很多东西并没有取得好成绩,你能帮帮我吗?

更新

问题与组件ID 有关,原因是组件正在更改ID以重定向页面。

注意我没有立即生成MenuModel组件

我尝试使用 .generateUniqueIds()方法,但仍然失败

这是我查看ID组件的日志,对于一个菜单:

首次重定向

 getMenuModel = In here
getMenuModel = SIZE ELEMENTS 1
Sub Menu Name : Aceptación y Documentos > Sub Menu ID : 0 > Sub Menu ID CLIENT : 0
## Item Menu Name : Acepta Proceso > Item Menu ID : 0_0 > Item Menu ID CLIENT : 0_0
## Item Menu Name : Envio/Recepcion Documentos > Item Menu ID : 0_1 > Item Menu ID CLIENT : 0_1

第二次重定向

getMenuModel = In here
getMenuModel = SIZE ELEMENTS 1
Sub Menu Name : Aceptación y Documentos > Sub Menu ID : 0 > Sub Menu ID CLIENT : 0
## Item Menu Name : Acepta Proceso > Item Menu ID : 1 > Item Menu ID CLIENT : 1
## Item Menu Name : Envio/Recepcion Documentos > Item Menu ID : 1 > Item Menu ID CLIENT : 1

1 个答案:

答案 0 :(得分:0)

我设法用菜单模型的新实例修复我的问题,并传递每个重定向已经创建的元素。

如果有人有更好的答案,请添加。因为我对这个解决方案不太满意。

private void refreshMenuModel() {
        List<MenuElement> elements = this.mainMenu.getElements();
        this.mainMenu = new DefaultMenuModel();
        for (MenuElement menuElement : elements) {
            this.mainMenu.addElement(menuElement);
        }
        generateUniqueIdsMenuModel();
    }


private void generateUniqueIdsMenuModel() {
    this.mainMenu.generateUniqueIds();
}