我在 Mojarra 上遇到了 JSF 2.4 的奇怪行为。我正在使用 flash 参数从一个页面传递到另一个页面。每次我到达一个新页面时,我都会在 Postconstruct 注释方法中检索我的 flash 参数。然后,如果页面被刷新,用户将被重定向到另一个页面。(因为刷新后闪存参数被擦除)。
对于相同的代码,如果我从不同的数据(硬编码或数据库查询)填充我的 selectItems,我会遇到此错误:
JSF1095:在我们尝试为 flash 设置传出 cookie 时,响应已经提交。存储到闪存中的任何值在下一次请求时都将不可用。
我想解决这个问题,也许与以下有关:
facesContext.responseComplete();
facesContext.renderResponse()
我不明白如何使用它们。
我读了大约2:
<h:selectOneMenu id ="loc" value="#{participantController.localisation}"
validatorMessage="Vous devez renseigner la localisation." >
<f:selectItems value="#{participantController.locFeaturesList}"
var="locFeature" itemLabel="#{locFeature.locName}"
itemValue="#{locFeature.locName}" />
</h:selectOneMenu>
我的列表对象:
public static class LocFeatures{
public String locName;
public String codeName;
public LocFeatures(String locName, String codeName){
this.locName = locName;
this.codeName = codeName;
}
public String getLocName(){
return locName;
}
public String getCodeName(){
return codeName;
}
}
将数据放入我的列表对象中:
public LocFeatures[] loadLocalisationpAdicapCodeAssociativeMenu() {
List <Static> loc2Code = staticBo.get(STATIC_CATEGORY_PARTICIPANT_LOCALISATION_CODE);
locFeaturesList = new LocFeatures[loc2Code.size()+1];
// if I populate my list with only some values no errors will be thrown but it doesn't work when i populate it by a big database request
//locFeaturesList = new LocFeatures[1];
locFeaturesList[0] = new LocFeatures("-----",null); // Associations Classe - Name
int indice = 1;
for (Static assocation : loc2Code) {
locFeaturesList[indice] = new LocFeatures(assocation.getKey(),assocation.getValue()); // Associations Classe - Name
indice ++;
}
return locFeaturesList;
}
我的@PostConstruct 方法:
@PostConstruct
public void setFlashParam() {
//locFeaturesList = loadLocalisationpAdicapCodeAssociativeMenu();
FacesContext facesContext = FacesContext.getCurrentInstance();
String studyNameFlashed = (String) facesContext.getExternalContext().getFlash().get("study_name");
// Gere un refresh qui ferait disparaitre le type de l'étude.
if (studyNameFlashed == null) {
try { ExternalContext ec = facesContext.getExternalContext(); ec.redirect(ec.getRequestContextPath() + "/Accueil"); } catch (IOException e) {e.printStackTrace();}
return;
}
return;
}