Java RequestedScope CDI bean空值
我正在为我的web应用程序使用JSF和CDI。我创建了一个JSF表单和一个RequestScoped bean来保存表单数据。然后我创建了一个CDIBean来处理表单。表格如下:Java RequestedScope CDI bean空值,java,jakarta-ee,Java,Jakarta Ee,我正在为我的web应用程序使用JSF和CDI。我创建了一个JSF表单和一个RequestScoped bean来保存表单数据。然后我创建了一个CDIBean来处理表单。表格如下: <h:outputText value="Mailing Address: " /> <p:inputText value="#{profile.mailAddress}" /> <h:outputText
<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" />
这是CDIBean:
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接收我通过表单输入的数据?可能是
Profile
bean上的RequestScoped
的包错误?请尝试从javax.enterprise.context
导入它。抱歉,我刚刚更改了包,但问题仍然存在。如果将表单输入文本值修改为#{profileController.current.mailAddress}?
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();
}
}