RequestedScope CDI bean null值

时间:2013-02-05 19:29:09

标签: java java-ee

我在我的网络应用程序中使用JSF和CDI。我创建了一个JSF表单和一个RequestScoped bean来保存表单数据。然后我创建了一个CDI bean来处理表单。这是表格:

            <h:outputText value="Mailing Address: " />  
            <p:inputText value="#{profile.mailAddress}" />  

            <h:outputText value="Cell Phone: " />  
            <p:inputText value="#{profile.cellPhone}"/>  

            <h:outputText value="Home Phone: " />  
            <p:inputText value="#{profile.homePhone}"/>  

            <h:outputText value="Work Phone: " />  
            <p:inputText value="#{profile.workPhone}"/>
            <p:commandButton action="#{profileController.test}" value="submit" ajax="false" />

这是请求范围的bean:

package entities;

import java.io.Serializable;
import javax.faces.bean.RequestScoped;
import javax.inject.Named;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author G2
 */
@Named
@RequestScoped
@XmlRootElement
public class Profile implements Serializable{
    private String mailAddress;
    private String homePhone;
    private String workPhone;
    private String cellPhone;
    public String getMailAddress() {
        return mailAddress;
    }

    @XmlElement
    public void setMailAddress(String mailAddress) {
        this.mailAddress = mailAddress;
    }

    public String getHomePhone() {
        return homePhone;
    }

    public void setHomePhone(String homePhone) {
        this.homePhone = homePhone;
    }

    public String getWorkPhone() {
        return workPhone;
    }

    @XmlElement
    public void setWorkPhone(String workPhone) {
        this.workPhone = workPhone;
    }

    public String getCellPhone() {
        return cellPhone;
    }

    @XmlElement
    public void setCellPhone(String cellPhone) {
        this.cellPhone = cellPhone;
    }

}

这是CDI bean:

package jsf.classes;

import entities.Profile;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author yg
 */
@Named
@ConversationScoped
public class ProfileController implements Serializable {

    @Inject
    private Profile current;
    @Inject
    private Conversation conversation;

    public Profile getSelected() {
        return current;
    }

    public void setSelected(Profile profile) {
        this.current = profile;
    }

    public void beginConversation() {
        if (conversation.isTransient()) {
            conversation.begin();
        }
    }

    public void endConversation() {
        if (!conversation.isTransient()) {
            conversation.end();
        }
    }

    @PostConstruct
    public void init() {
        beginConversation();
    }
}

但是,当我在表单中输入值并单击“提交”时,profileController.current中的所有属性都为null。如何让profileController接收我通过表单输入的数据?

0 个答案:

没有答案