Jsf 如何在CDIBean中使用对话?

Jsf 如何在CDIBean中使用对话?,jsf,cdi,Jsf,Cdi,JavaScript使用此url pl_edit.xhtml?id=1请求页面。它使用下面的PlayerEditBean。load方法从数据库中获取播放器。它很好用。该页面包含一个Save按钮,该按钮发布到下面显示的Save方法 这是我第一次尝试对话。我没有多页对话框。我只是希望对话能为我保留playerEditBean.player的状态。不幸的是,它不起作用。在save中,新构造的player对象具有空id 我使用对话的方式有问题吗 @Named @ConversationScoped()

JavaScript使用此url pl_edit.xhtml?id=1请求页面。它使用下面的PlayerEditBean。load方法从数据库中获取播放器。它很好用。该页面包含一个Save按钮,该按钮发布到下面显示的Save方法

这是我第一次尝试对话。我没有多页对话框。我只是希望对话能为我保留playerEditBean.player的状态。不幸的是,它不起作用。在save中,新构造的player对象具有空id

我使用对话的方式有问题吗

@Named
@ConversationScoped()
public class PlayerEditBean implements Serializable {
private static final long serialVersionUID = 1L;

@Inject
private Conversation conversation;

@Inject
PlayerService playerService=null;

private Player player=null;


@PostConstruct
public void load() {
    conversation.begin();

    // assume valid id is passed and we're loading a player from database
    String strId=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id");
    player=playerService.getPlayer(Long.valueOf(strId));

}


public void save() {

    System.out.println("Persisting player with id " + player.getId());
    playerService.savePlayer(player);
    conversation.end();     
}

您需要从第一次调用中检索cid参数,并将其与save调用一起发送,以将请求与正确的对话联系起来。

任何形式的充实都将是伪代码,因为OP没有提到他们正在使用的特定库或前端技术。