数据源:
<xe:objectData var="league" ignoreRequestParams="true" scope="request">
<xe:this.saveObject><![CDATA[#{javascript:leagueService.set(league)}]]></xe:this.saveObject>
<xe:this.createObject><![CDATA[#{javascript:return leagueService.get(viewScope.currentKey);}]]></xe:this.createObject>
</xe:objectData>
和几个组合框
<xp:comboBox id="idLeagueList" value="#{viewScope.currentKey}">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript: return eu.jeroensomhorst.cms.util.JSFUtil.asSelectItem(leagueService.getAll(season),true);}]]></xp:this.value>
</xp:selectItems>
<xp:eventHandler event="onchange" submit="true" refreshMode="complete"></xp:eventHandler>
</xp:comboBox>
<xp:listBox id="lstAvailableTeams">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:eu.jeroensomhorst.cms.util.JSFUtil.asSelectItem(teamService.getAll());}]]></xp:this.value>
</xp:selectItems>
</xp:listBox>
和一个按钮,用于将lstAvailableTeams中的选定团队添加到选定的leage对象
<xp:button value=">" id="addTeam" >
<xp:eventHandler event="onclick" submit="true" refreshMode="complete" disableValidators="true">
<xp:this.action>
<xp:actionGroup>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var teamList = getComponent("lstAvailableTeams");
var strTeamKey = teamList.getValue();
eu.jeroensomhorst.cms.util.LeagueUtil.addTeam(league.getKey(),strTeamKey);}]]></xp:this.script>
</xp:executeScript>
</xp:actionGroup>
</xp:this.action></xp:eventHandler></xp:button>
<xp:listBox id="leagueTeams">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:return eu.jeroensomhorst.cms.util.JSFUtil.asSelectItem(league.getTeams());}]]></xp:this.value>
</xp:selectItems>
</xp:listBox>
leagueutil的代码如下:
public static void addTeam(String leagueKey,String key){
LeagueService lService = (LeagueService) DominoUtil.getVariableValue("leagueService");
League l = (League) lService.get(leagueKey);
TeamService service = (TeamService) DominoUtil.getVariableValue("teamService");
Team t = service.get(key);
Vector<Team> teams = l.getTeams();
if(teams == null){
teams = new Vector();
teams.add(t);
}else{
if(!teams.contains(t)){
teams.add(t);
}
}
l.setTeams(teams);
// save into database.. this works.
lService.set(l);
}
因为你看不到任何想象。但问题是如下。每当我更改idLeagueList组合框值并执行changelistener时(它会更新viewscope)。它总是检索在leagueteams组合框中显示的先前值。这是一个非常基本的问题,但我完全没有选择..
答案 0 :(得分:2)
createObject
的{{1}}过早执行:在恢复视图阶段完成之前。这种方式objectData
从objectData
获取旧值。
viewScope.currentKey
解决问题的一种可能方法是使用联盟对象的视图范围变量。您可以在createObject: viewScope.currentKey = old value
afterRestoreView: viewScope.currentKey = old value
beforeRenderResponse: viewScope.currentKey = new value
和beforePageLoad
个事件中进行设置。
beforeRenderResponse
并在listBox中使用它
viewScope.league = leagueService.get(viewScope.currentKey)
和按钮代码
... eu.jeroensomhorst.cms.util.JSFUtil.asSelectItem(viewScope.league.getTeams())
以下是用于测试目的的代码的简短版本。它使用print语句在几个JSF阶段显示... eu.jeroensomhorst.cms.util.LeagueUtil.addTeam(viewScope.league.getKey(),strTeamKey)
的当前值:
viewScope.currentKey