0
votes

I'm new to primefaces JSF, I have three pages called Template page, Master page with dialog option and bean attached with dialog option but when I click command button in dialog box the bean method not calling. please help us if anybody knows about this issue. Thanks

MasterTemplate.xhtml

<?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:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <f:view contentType="text/html">
        <h:head>
            <f:facet name="first">
                <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
                <title><h:outputText value="#{prop.application_name}"/></title>
            </f:facet>
            <link type="text/css" rel="stylesheet" href="${facesContext.externalContext.requestContextPath}/css/default.css"/>
        </h:head>
        <h:body>
            <p:layout fullPage="true">

                <p:layoutUnit header="#{prop.application_name}" position="north" size="240" resizable="false" closable="false" collapsible="true">

                    <h:form id="toolBarForm">
                    <p:toolbar>

                        <p:toolbarGroup align="right">
                            <h:outputText value="Welcome :#{sessionScope.userName}"/>
                              <p:separator />
                            <p:commandButton  action="#{userLogout.logout}" value="#{prop.Template_button}" ajax="false" />


                        <p:menuButton value="Quick Access">  
                            <p:menuitem action="ChangePassword" icon="ui-icon-key" value="Change password"/>  
                            <p:menuitem icon="ui-icon-person" value="View Profile"/>
                            <p:menuitem action="#{userLogout.logout}" icon="ui-icon-locked" value="Logout"/>  
                        </p:menuButton>
                            </p:toolbarGroup>
                    </p:toolbar>
                        </h:form>

                </p:layoutUnit> 
                    <p:layoutUnit position="west" size="300" header="#{prop.Template_Menu_Header}" collapsible="true">
                    <h:form id="f2">
                        <p:tree value="#{menuBean.root}" var="node" id="tree" highlight="true "
                                selection="#{menuBean.selectedNode}" 
                                selectionMode="single" >
                            <p:ajax event="select"  listener="#{menuBean.onNodeSelect}" update=":mainArea"/>
                            <p:treeNode id="treeNode"  >
                                <h:outputText value="#{node}"/>
                            </p:treeNode>
                        </p:tree>

                    </h:form>

                </p:layoutUnit>
                <ui:insert name="MainBody" />

                <p:layoutUnit header="#{prop.application_footer}" position="south" closable="false" collapsible="false">

                </p:layoutUnit>
            </p:layout>



        </h:body>
    </f:view>

</html>

default.xhtml

<ui:composition template="templates/MasterTemplate.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets" 

                xmlns:p="http://primefaces.org/ui">

    <ui:define name="MainBody">

        <p:layoutUnit  position="center">
            <h:panelGroup id="mainArea">
                <ui:include src="#{menuBean.renderPage}"/>
                            </h:panelGroup>


        </p:layoutUnit>

    </ui:define>
</ui:composition>

ThirdPage.xhtml

<?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.org/ui">
    <h:head>
        <title> Title</title>
    </h:head>
    <h:body>
        <h:form id="test">

            <p:toolbar>
                <p:toolbarGroup align="left">



                    <p:commandButton value="New User" onclick="newUserDialog.show()"/>


                    <p:commandButton action="#{lbc.login}" process="@test"  value="View"  >

                    </p:commandButton>


                    <p:commandButton type="button" value="Edit" title="Update" icon="ui-icon-pencil">

                    </p:commandButton>


                    <p:separator />

                    <p:commandButton type="button" value="Delete" title="Delete" icon="ui-icon-trash"/>


                </p:toolbarGroup>

                <p:toolbarGroup align="right">

                    <p:commandButton type="button" value="Search" icon="ui-icon-search"/>
                </p:toolbarGroup>

            </p:toolbar>
        </h:form>



   <h:form prependId="false">

    <p:dialog header="Create New User" widgetVar="newUserDialog" resizable="true" id="newUserDlg" > 

        <h:panelGrid id="region" columns="2" cellpadding="5">
            <h:outputLabel for="username" value="Username:" />
            <p:inputText value="#{lbc.username}" 
                    id="username" required="true" label="username" />

            <h:outputLabel for="password" value="Password:" />
                        <p:password value="#{lbc.password}" 
                    id="password" required="true" label="password" />

            <f:facet name="footer">
                            <p:commandButton  partialSubmit="true" action="#{lbc.login}"  value="add">


                            </p:commandButton>


            </f:facet>
        </h:panelGrid>


    </p:dialog>

  </h:form>

        </h:body>
</html>
package mod.om.login;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;


@ManagedBean(name = "lbc")
@RequestScoped

public class LoginBean implements  Serializable{



    private String username;

    private String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void login() {
        System.out.println("Called");

    }
}
1
I suppose the only button which doesn't work is the one inside the dialog? Which is your lbc bean's code?Xtreme Biker
public void login() { System.out.println("Called"); }JSF Learner
When i try to call attached method does not invoke Mr. Xtreme.. awaiting for your quick support on this. thanksJSF Learner
Here ThirdPage.xhtml is a renderPage in default.xhtmlJSF Learner
As you're new to stack overflow you probably don't know it's possible to edit your entire question. Press edit below your question and provide your managed bean code ;-)Xtreme Biker

1 Answers

2
votes

I had the same problem; but in my case, it was when I migrated primefaces from version 5.0 to 6.2.

I solved it removing the <f:facet name="footer"... or wrapping with <h:panelGrid ... the <p:commandButton ... like the following example.

<f:facet name="footer">
    <h:panelGrid columns="1" >
        <p:commandButton  partialSubmit="true" action="#{lbc.login}"  value="add">
        </p:commandButton>
    </h:panelGrid>
</f:facet>