不是被动的JSF commandButton。为什么?

时间:2013-11-07 00:10:23

标签: jsf ejb-3.0 commandbutton

我在客户端非常粗糙,所以对于谁在JSF中比我更有成就(这非常容易!:D)这可能是一个非常容易的问题但是我有些日子已经失去了我的头...幸运的只是在我空闲的时间里。 但我在那个(死)点需要帮助。请帮忙,否则我会把所有的夜晚都粘在键盘上!

我创建了一个包含两个表单的.xhtml页面,第二个指向会话Bean,该会话Bean初始化要创建的对象并重定向到页面,并使用表单为其变量赋值。

这是第一个.xhtml页面:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Modify A Cafeteria Element</title>        
    </h:head>
    <h:body>

        <f:view>
            <h:form>
                <h1><h:outputText value="Modify A Cafeteria Element"/></h1>
                <h:panelGrid columns="2">
                    <h:outputLabel value="Description:" for="description" />
                    <h:inputText id="description" value="#{cafeteriaElementBean.cafeteriaElement.description}" title="Description" />                   

                </h:panelGrid>

                <p:commandButton action="#{cafeteriaElementBean.saveOrEdit()}" value="Save" />
                <p:commandButton action="#{cafeteriaElementBean.edit()}" value="Edit" />
                <p:button outcome="cafeteriaElementList" value="Back" />
            </h:form>
        </f:view>
        <br/>
        #{cafeteriaElementBean.cafeteriaElement.description} periodicity list:
        <br/>

        <f:view>
            <h:form>
                <h1><h:outputText value="List"/></h1>
                <h:dataTable value="#{elementPeriodBean.filteredPerElement(cafeteriaElementBean.cafeteriaElement)}" var="item">
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="MaxAbsoluteForPeriod"/>
                        </f:facet>
                        <h:outputText value="#{item.maxAbsoluteForPeriod}"/>
                    </h:column>                   
                    <!-- code omissed for brevity-->
                </h:dataTable>

                <p:commandButton action="#{elementPeriodBean.create(cafeteriaElementBean.cafeteriaElement)}"  value="Add a new Periodicity"/> 

            </h:form>
        </f:view>



    </h:body>
</html> 

这是enter image description here

的打印屏幕

单击“ new periodicity ”按钮驱动器为空:调试器没有感知到它,服务器终端没有写任何东西。浏览器都没有重定向到第二页。 :(

会话Bean 如下:(有一些削减)

package com.cafeteria.business;

import com.cafeteria.facades.ElementPeriodFacade;
import com.cafeteria.model.CafeteriaElement;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import com.cafeteria.model.ElementPeriod;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;

@Named
@SessionScoped
public class ElementPeriodBean implements Serializable, CRUD <ElementPeriod>{

    private ElementPeriod elementPeriod;

    @Inject
    ElementPeriodFacade elementPeriodFacade;

    public List <ElementPeriod> getAll(){
        return elementPeriodFacade.findAll();
    }

    public List <ElementPeriod> filteredPerElement(CafeteriaElement cafeteriaElement){
        return elementPeriodFacade.findForElement(cafeteriaElement);
    }

    public String create(){
       this.elementPeriod = new ElementPeriod();
        return "newElementPeriod";
    }

    public String create(CafeteriaElement cafeteriaElement){
        this.elementPeriod = new ElementPeriod();
        this.elementPeriod.setCafeteriaElement(cafeteriaElement);
        return "newElementPeriod";
    }

    public String modify(ElementPeriod elementPeriod){
        this.elementPeriod = elementPeriod;
        return "newElementPeriod";
    }

    public String saveOrEdit(){
        elementPeriodFacade.create(elementPeriod);
        return "editCafeteriaElement";
    }

      public String edit(){
        elementPeriodFacade.edit(elementPeriod);
        return "editCafeteriaElement";
    }

    public String remove(ElementPeriod elementPeriod){
        elementPeriodFacade.remove(elementPeriod);
        return "editCafeteriaElement";
    }

    public ElementPeriod find(Long id){
        return elementPeriodFacade.find(id);
    }

    public ElementPeriod getElementPeriod() {
        if(this.elementPeriod== null) this.elementPeriod = new ElementPeriod();
        return this.elementPeriod;
    }  

    public void setElementPeriod(ElementPeriod elementPeriod) {
        this.elementPeriod = elementPeriod;
    }
}

这是插入数据的表单页面:

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Create periodicity for Cafeteria Element</title>        
    </h:head>
    <h:body>

        <f:view>
            <h:form>
                <h1><h:outputText value="Create/Edit Periodicity for #{cafeteriaElementBean.cafeteriaElement.description}"/></h1>

                <h:panelGrid columns="2">                 
                    <h:outputLabel value="Periodicity:" for="periodicity" />
                    <h:selectOneMenu id="periodicity" value="#{elementPeriodBean.elementPeriod.periodicity}" title="Periodicity" >
                        <!-- TODO: update below reference to list of available items-->
                        <f:selectItems value="#{periodicityBeam.all}"/>
                    </h:selectOneMenu>

                    <h:outputLabel value="MaxAbsoluteForPeriod:" for="maxAbsoluteForPeriod" />
                    <h:inputText id="maxAbsoluteForPeriod" value="#{elementPeriodBean.elementPeriod.maxAbsoluteForPeriod}" title="MaxAbsoluteForPeriod" />

                    <h:outputLabel value="MaxPercentageForPeriod:" for="maxPercentageForPeriod" />
                    <h:inputText id="maxPercentageForPeriod" value="#{elementPeriodBean.elementPeriod.maxPercentageForPeriod}" title="MaxPercentageForPeriod" />

                    <h:outputLabel value="FixValue:" for="fixValue" />
                    <h:inputText id="fixValue" value="#{elementPeriodBean.elementPeriod.fixValue}" title="FixValue" />   
                </h:panelGrid>

                <p:commandButton value="Save" action="#{elementPeriodBean.saveOrEdit()}"/>

                <!--p:button outcome="editCafeteriaElement" value="Back" /-->
            </h:form>
        </f:view>
    </h:body>
</html>

备注: - newElementPeriod从faces-config.xml正确指向第一页面 - 无论是否直接从浏览器调用,都可以使用newElemelPeriod.xhtml - 其他按钮有效:不是随处可见,因为有些按钮具有与此相似的行为

请帮忙!我疯了!

提前谢谢你, 安德烈

2 个答案:

答案 0 :(得分:0)

您可以检查链接可能是commandButton的process属性 CommandButton not firing

答案 1 :(得分:-1)

为什么要尝试从会话范围的bean中为create方法提供参数?尝试删除参数并注入其他会话范围的bean ...