无法在bean中获取inputtext值

时间:2014-02-25 11:10:39

标签: jsf primefaces spring-webflow

我无法在我的bean中获取输入文本值

我已在工作流程中将coverage bean设置为会话bean,但是当我尝试从输入文本中获取值时,它返回null

此ID位于面板中,包含返回false的表单

<ui:composition 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"
    xmlns:f="http://java.sun.com/jsf/core">
<h:form id="form2" >
    <div class="contract-menubar-internal-9x90 coverage-prod-mid-panel">
        <div class="cvrg-row-div-dimension">
            <p:panel id="cvrg_panel">
                <h:outputLabel value="Type : " styleClass="cvrg-labels" />
                <p:selectOneMenu value="" styleClass="cvrg-inputs">
                    <f:selectItem itemLabel="Select" itemValue="" />
                    <f:selectItem itemLabel="ELW" itemValue="1" />
                    <f:selectItem itemLabel="Maintenance" itemValue="2" />
                    <f:selectItem itemLabel="WT" itemValue="3" />
                </p:selectOneMenu>

                <h:outputLabel value="Damage Code : " styleClass="cvrg-labels" />
                <p:inputText styleClass="cvrg-inputs">
                </p:inputText>


                <h:outputLabel value="Baumuster : " styleClass="cvrg-labels" />
                <p:selectOneMenu value="" styleClass="cvrg-inputs">
                    <f:selectItem itemLabel="Select" itemValue="" />
                    <f:selectItem itemLabel="207" itemValue="1" />
                    <f:selectItem itemLabel="221" itemValue="2" />

                </p:selectOneMenu>

                <h:outputLabel value="Class : "
                    styleClass="cvrg-labels cvrg-class-srch-label" />
                <p:selectOneMenu value="" styleClass="cvrg-inputs">
                    <f:selectItem itemLabel="Select" itemValue="" />
                    <f:selectItem itemLabel="S" itemValue="1" />
                    <f:selectItem itemLabel="C" itemValue="2" />

                </p:selectOneMenu>
            </p:panel>
            <p:panel>
                <div class="srch-cvrg-btn">
                    <p:commandButton value="Search" />
                </div>
                <div class="reset-cvrg-btn">
                    <p:commandButton value="Reset" id="reset_cvrg" update="cvrg_panel"
                        process="@this">
                        <p:resetInput target="cvrg_panel"></p:resetInput>
                    </p:commandButton>
                </div>
            </p:panel>
        </div>
        <p:commandButton value= "Save"  styleClass="add-coverage-btn" action="#{coverageFlowManager.add}" ajax="false" > </p:commandButton>

        <p:commandButton value="Add Coverage" styleClass="add-coverage-btn"
            onclick="addCoverage()"  />

        <p:commandButton value="Save" styleClass="save-coverage-btn"
            id="saveCoverage" action="#{productModel.saveCoverage}"
            immediate="true" partialSubmit="true" />
        <p:commandButton value="Cancel" styleClass="cancel-coverage-btn"
            onclick="cancelCoverage()" />
        <p:inputText id="type_inp1" value="#{coverageBean.type}" /> 
    </div>

/ **  *  * /

package com.daimler.contract.flow;

import java.util.*;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlInputText;

import org.springframework.security.core.context.SecurityContextHolder;

import com.daimler.contract.bean.CoverageBean;
import com.daimler.contract.bean.ProductBean;
import com.daimler.contract.entity.CoverageEntity;
import com.daimler.contract.entity.ProductEntity;
import com.daimler.contract.model.ProductModel;
import com.daimler.contract.service.CoverageService;
import com.daimler.contract.service.ProductService;
import com.mbcl.common.bean.User;


/**
 * @author Jyoti
 *
 */

public class CoverageFlowManager {
    private CoverageService coverageService;
    private ProductModel productModel;
    private CoverageBean coverageBean;
    HtmlInputText type;


    public HtmlInputText getType() {
        return type;
    }



    public void setType(HtmlInputText type) {
        this.type = type;
    }



    public void setCoverageBean(CoverageBean coverageBean) {
        this.coverageBean = coverageBean;
    }

    public static final String query = "select * from COVERAGE_MGT";





    /**
     * @return the coverageService
     */
    public CoverageService getCoverageService() {
        return coverageService;
    }



    /**
     * @param coverageService the coverageService to set
     */
    public void setCoverageService(CoverageService coverageService) {
        this.coverageService = coverageService;
    }



    /**
     * @return the productModel
     */
    public ProductModel getProductModel() {
        return productModel;
    }



    /**
     * @param productModel the productModel to set
     */
    public void setProductModel(ProductModel productModel) {
        this.productModel = productModel;
    }


    public void showCMDataTable() {
        String countryCode = ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal())
        .getCountryCode();
        System.out.println("jyoti THROUGH DIFF");
        List<CoverageEntity> cmDataTableEntity = coverageService.getCMDataTable(countryCode, query);
        productModel.setCoverageEntityList(cmDataTableEntity);

        //System.out.println("set in model"+pmDataModel.getPmList());
    }
    public String add()
    {
        System.out.println("Gaurav");
        System.out.println(coverageBean.getType());
        System.out.println(productModel.getCoverageEntityList().get(0).getId());
        System.out.println(getType().getValue());
//      productModel.getCoverageEntityList().add(productModel.getNewCoverage());
        return null;

    }
}

1 个答案:

答案 0 :(得分:2)

在您的XHTML中

<p:inputText id="type_inp1" value="#{coverageBean.type}" /> 

映射到

HtmlInputText type;

这是错误的。该值应映射到variable类型的String

更改:

private String type;
    public String getType() {
        return type;
    }
    public void setType(Stringtype) {
        this.type = type;
    }

进行以上更改并尝试它应该有效。

仅供参考 - 仅HtmlInputText使用binding。但你不需要在这里绑定。