Primefaces CommandButton不工作

时间:2013-12-25 08:07:50

标签: jsf primefaces

我是Primefaces JSF的新手,我有三个名为Template页面的页面,带有对话框选项的主页面和带有对话框选项的bean,但是当我在对话框中单击命令按钮时,bean方法没有调用。如果有人知道这个问题,请帮助我们。感谢

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 个答案:

答案 0 :(得分:0)

我有同样的问题;但就我而言,那是我将素数从5.0迁移到6.2的时候。

我解决了它,删除了 或使用 包装

如以下示例。

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