无法在提交按钮上调用托管bean方法

时间:2015-05-06 08:14:09

标签: jsf prettyfaces

这是我的.xhtml页面的代码

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                template="/WEB-INF/templates/admin/main_body_template.xhtml">

    <ui:define name="bodycontent">
        <h:panelGroup>
            <h:form class="form-horizontal" enctype="multipart/form-data">
                    <!-- Build page from here: Usual with <div class="row-fluid"></div> -->
                    <div class="row">
                       <div class="col-lg-12">
                           <div class="panel panel-default" style="min-height: inherit;">
                             <div class="panel-heading">
                                <h4><span class="icon16 icomoon-icon-pencil-3"></span><span>Create New Module</span></h4>
                             </div>

                                <div class="panel-body">
                                   <div class="form-group">
                                      <label class="col-lg-5 control-label" for="select">Select app</label>
                                      <div class="col-lg-3 dropdown-error">
                                          <h:selectOneMenu class="form-control" required="required" value="#{moduleBean.appList}">
                                              <f:selectItem itemValue="0" itemLabel="-- Please select app --"></f:selectItem>
                                              <f:selectItem itemValue="1" itemLabel="AdMan"></f:selectItem>
                                              <f:selectItem itemValue="2" itemLabel="Neokala"></f:selectItem>
                                              <f:selectItem itemValue="3" itemLabel="Recrudesk"></f:selectItem>
                                              <f:selectItem itemValue="4" itemLabel="E-commerce"></f:selectItem>
                                              <f:selectItem itemValue="5" itemLabel="Restaurants"></f:selectItem>
                                              <f:selectItem itemValue="6" itemLabel="Account"></f:selectItem>
                                              <f:selectItem itemValue="7" itemLabel="MockExam"></f:selectItem>
                                          </h:selectOneMenu>
                                      </div>
                                   </div>
                                   <!-- End .form-group  -->
                                   <hr/>
                                   <div class="form-group a1">
                                      <label class="col-lg-5 control-label" for="normalInput">Module name</label>
                                      <div class="col-lg-3">
                                          <h:inputText class="form-control" required="true" value="#{moduleBean.selected.moduleName}"></h:inputText>
                                      </div>
                                      <a href="#" 
                                         class="btip" 
                                         rel="tooltip" 
                                         data-placement="right" 
                                         data-original-title="Tooltip on right">
                                      <span class="icon16 entypo-icon-help-2 icon-position"></span>
                                      </a>
                                   </div>
                                   <!-- End .form-group  -->
                                   <div class="form-group b1">
                                      <label class="col-lg-5 control-label" for="fileinput">Upload image</label>
                                      <div class="col-lg-3">
                                          <h:inputFile class="form-control" id="file" value="#{moduleBean.imgFile}"/>
                                      </div>
                                      <a href="#" 
                                         class="btip" 
                                         rel="tooltip" 
                                         data-placement="right" 
                                         data-original-title="Tooltip on right">
                                      <span class="icon16 entypo-icon-help-2 icon-position"></span>
                                      </a>
                                   </div>
                                   <!-- End .form-group  -->
                                   <div class="form-group">
                                      <label class="col-lg-5 control-label" for="checkboxes">Active</label>
                                      <div class="col-lg-3">
                                         <div class="normal-toggle-button toggle-custom-size">
                                             <h:selectBooleanCheckbox class="nostyle" value="#{moduleBean.selected.active}"></h:selectBooleanCheckbox>
                                         </div>
                                      </div>
                                   </div>
                                   <!-- End .form-group  -->
                                   <div class="form-group">
                                      <label class="col-lg-5 control-label" for="checkboxes">Add-on</label>
                                      <div class="col-lg-3">
                                         <div class="left marginR10">
                                            <div class="normal-toggle-button toggle-custom-size">
                                                <h:selectBooleanCheckbox class="nostyle" value="#{moduleBean.selected.addOn}"></h:selectBooleanCheckbox>
                                            </div>
                                         </div>
                                      </div>
                                   </div>
                                   <!-- End .form-group  -->
                                </div>
                                <div class="panel-heading form-footer-top">
                                   <div class="footer-btn-position">
                                       <h:commandButton class="btn btn-primary nostyle marginR5" value="Save" action="#{moduleBean.create()}"></h:commandButton>
                                       <h:commandButton type="button" class="btn btn-warning nostyle cancel-btn-position" value="Cancel"></h:commandButton>
                                   </div>
                                   <div style="clear:both;"></div>
                                </div>

                          </div>
                          <!-- End .panel -->
                       </div>
                       <!-- End .span12 -->
                    </div>
                    <!-- End .row -->  
            </h:form>
        </h:panelGroup>
    </ui:define>

</ui:composition>

以下是我的托管bean代码。

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptegrainc.ymapps.supadm.managedbeans.masters;

import com.aptegrainc.ymapps.supadm.controller.masters.ModuleController;
import com.aptegrainc.ymapps.supadm.dto.ModuleVo;
import com.aptegrainc.ymapps.supadm.managedbeans.UserDataBean;
import static com.aptegrainc.ymapps.supadm.managedbeans.UserDataBean.setErrorMessage;
import static com.aptegrainc.ymapps.supadm.managedbeans.UserDataBean.setInfoMessage;
import java.io.Serializable;
import java.util.List;
import java.util.ResourceBundle;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.servlet.http.Part;

/**
 *
 * @author Vaibhavi
 */
@ManagedBean(name = "moduleBean")
@ViewScoped
public class ModuleBean extends UserDataBean implements Serializable{

    private static final long serialVersionUID = 1L;

    private DataModel items;
    private ModuleVo current;
    private Part imgFile;
    private boolean createPanel = false;

    private ModuleController moduleController = new ModuleController();

    private String appList;

    public Part getImgFile() {
        return imgFile;
    }

    public void setImgFile(Part imgFile) {
        this.imgFile = imgFile;
    }

    public ModuleVo getSelected() {
        if (current == null) {
            current = new ModuleVo();
        }
        return current;
    }

    /**
     * Creates a new instance of ModuleBean
     */
    public ModuleBean() {

    }


    public String create() {
        System.out.println("current : " + current);
        System.out.println("---------"+current.getAppName()+current.getModuleName()+current.isActive()+current.isAddOn());
        if(checkError()){
            try {
                System.out.println("---------"+current.getAppName()+current.getModuleName()+current.isActive()+current.isAddOn());
                current.setActive(true);
                boolean val = moduleController.create(current);
                if(!val){
                    return "pretty:commonerror";
                } else if (val){
                    setInfoMessage("Module created successfully");
                }

                setCreatePanel(false);
                recreateModel();
                return "success";
            } catch (Exception e) {
                setErrorMessage(ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            }
        }

        return "fail";
    }

    public boolean checkError(){
        boolean flag = true;

        if(current.getModuleName() == null || current.getModuleName().equals("")){
            //setErrorMessage("Enter module name");
            flag = false;
        }
        return flag;
    }

    private void recreateModel() {
        items = null;
    }

    // Getters, Setters

    /**
     * @return the items
     */
    public DataModel getItems() {
        if (items == null) {
            List<ModuleVo> moduleVos = null;
            //moduleVos = moduleController.findAll();
            items = new ListDataModel(moduleVos);
        }
        return items;
    }

    /**
     * @param items the items to set
     */
    public void setItems(DataModel items) {
        this.items = items;
    }

    /**
     * @return the current
     */
    public ModuleVo getCurrent() {
        return current;
    }

    /**
     * @param current the current to set
     */
    public void setCurrent(ModuleVo current) {
        this.current = current;
    }

    /**
     * @return the moduleController
     */
    public ModuleController getModuleController() {
        return moduleController;
    }

    /**
     * @param moduleController the moduleController to set
     */
    public void setModuleController(ModuleController moduleController) {
        this.moduleController = moduleController;
    }

    /**
     * @return the appList
     */
    public String getAppList() {
        return appList;
    }

    /**
     * @param appList the appList to set
     */
    public void setAppList(String appList) {
        this.appList = appList;
    }

    /**
     * @return the createPanel
     */
    public boolean isCreatePanel() {
        return createPanel;
    }

    /**
     * @param createPanel the createPanel to set
     */
    public void setCreatePanel(boolean createPanel) {
        this.createPanel = createPanel;
    }


}

我刚刚在提交按钮上调用了一个方法,但它甚至没有调用方法。我已多次检查代码,但无法找到任何逻辑错误。我不明白为什么没有调用bean方法。

0 个答案:

没有答案