2

I'm involved in a migration of a Java Web Application from Primefaces 6.2 to Primefaces 8.0. After resolving all issues as per official migration guides the application works properly except for the behavior on a p:menubutton component.

It regards a xhtml that produce a datatable where a column contains the DefaultMenuItem objects rendered by the attribute model on p:menubutton component.

ISSUE: First time I invoke one of the action setted into each DefaultMenuItem it works. The action opens a dialog but closing the dialog opened without doing a new submit, the second invocation doesn't produce any output. I can evaluate ajax request into the network tab of the browser console and nothing sounds wrong, it is equals to the first call. There're no errors in server console neither in browser console. This wasn't happening on Primefaces 6.2. All the components involved are the same before and after the migration.

Code as follow:

list.xhtml the ui:composition that contains the p:menubutton component

<ui:composition>
        
    <h:form id="someForm" enctype="multipart/form-data">
    
        <p:menuButton 
            model="#{SomeBean.model}"
            id="idmenubutton" 
            icon="fa fa fa-ellipsis-v"
            menuStyleClass="response-single-style" 
            title="some_title"
            disabled="false"/>
    
    </h:form>
</ui:composition>

dialog.xhtml the ui:composition rendered after invoke actions setted on each DefaultMenuItem

<ui:composition>

    <p:importEnum type="some.path.SomeEnum" var="someEnum"/>

    <p:dialog id="idDlgGeneric" header="some_header" styleClass="generic_pnlMaxWidth95" 
              widgetVar="dlgGeneric" modal="true" onShow="dlgOnShow(this.jqId);onShowForClosableDlg('dlgGeneric')"
              responsive="true" fitViewport="true" showEffect="fade" hideEffect="fade" resizable="false" closable="true">
        
        <p:panel rendered="true">
            <p:panelGrid layout="grid" columns="2" columnClasses="ui-grid-col-6,ui-grid-col-6" styleClass="ui-panelgrid-blank">
                <p:commandButton id="saveDlg" icon="fa fa-pencil" value="Save" action="#{SomeOtherBean.save}" styleClass="generic_width100"/>
                <p:commandButton icon="fa fa-times" value="Close" action="#{SomeBean.destroyBeanViewScope('SomeOtherBean')}" onclick="PF('dlgGeneric').hide()" styleClass="generic_width100 uniqueCloseButton"/>
                <p:defaultCommand target="@form:saveSomeOtherBean" scope="@form:idDlgGeneric" />
            </p:panelGrid>
        </p:panel>
        
    </p:dialog>

</ui:composition>

SomeBean.java the class that initialize the model used into p:menubutton component

@Named(ConstantsWeb.MBean.SOME_BEAN)
@ViewScoped
public class SomeBean extends AbstractBean {

    private transient MenuModel model;
    
    public MenuModel initModel() {
        
                model = new DefaultMenuModel();
                final DefaultMenuItem title = DefaultMenuItem.builder()
                        .value("value_description")
                        .disabled(true)
                        .style("opacity:1;font-weight:bold;")
                        .build();
                model.getElements().add(title);

                for (final SomeEnum resp : responsSingle) {
                    Map<String, List<String>> map = new LinkedHashMap<String, List<String>>();
                    List<String> list = new ArrayList<String>();
                    list.add(String.valueOf(resp.getId()));
                    map.put("respId", list);
                    
                    final DefaultMenuItem menuItem = DefaultMenuItem.builder()
                            .value(resp.getDisplayName())
                            .command("#{SomeBean.someMethod}")
                            .params(map)
                            .onstart("PF('statusDialog').show();")
                            .onsuccess("PF('statusDialog').hide();")
                            .update(someForm:idDlgGeneric)
                            .icon(resp.getIcon())
                            .disabled(false)
                            .build();
                    model.getElements().add(menuItem);
                }

                model.generateUniqueIds();
            }
        } else {
            model = null;
        }
        return model;
    }
    
    public void someMethod() {
        
    }
    
    public void destroyBeanViewScope(final String... yourBeanArray) {
        FacesHelper.destroyBeanViewScope(yourBeanArray);
        renderResponse = false;
        FacesHelper.update(someForm:idDlgGeneric);
    }
}

Anyone could help me?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
mulivieri
  • 21
  • 3
  • 1
    Hmmm your code looks right so something must be off. If you create a Primefaces Test reproducer that would help us all debug it much better: github.com/primefaces/primefaces-test – Melloware Dec 03 '22 at 14:02
  • Also I see you are calling `model.generateUniqueIds();` is that necessary? – Melloware Dec 03 '22 at 14:03
  • Thanks. Without ```model.generateUniqueIds();``` an ERROR - Caused by: java.lang.NumberFormatException: For input string: "" ... ... at org.primefaces.renderkit.MenuItemAwareRenderer.findMenuitem(MenuItemAwareRenderer.java:193) at org.primefaces.renderkit.MenuItemAwareRenderer.decode(MenuItemAwareRenderer.java:61) at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:478) at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1407) at org.primefaces.component.menubutton.MenuButton.processDecodes(MenuButton.java:49)``` is thrown – mulivieri Dec 05 '22 at 09:31
  • I create a simple menubutton test with github.com/primefaces/primefaces-test as suggested but I wasn't able to produce the same error. So I have to assume the problem is in the wrapper components of this menubutton or somewhere in my configuration (I didn't change anything from Primefaces 6.2 to Primefaces 8.0). Any idea what I should check ? – mulivieri Dec 05 '22 at 09:41
  • I'm on a debug breakpoint on SomeBean.someMethod (the command setted into DefaultMenuItem). On the first invocation both PF6.2 and PF8 reach java code but on the second call with PF8 I'm not able to execute my java method anymore. – mulivieri Dec 05 '22 at 09:47
  • Yep try and reproduce with PrimeFaces Test project. If you can't then it means something is wrong with your code and a bug fix between 6.0 and 8.0 closed some loophole that was previously making it work. – Melloware Dec 05 '22 at 16:30

0 Answers0