gpt4 book ai didi

httpresponse - 如何解决 JSF1095 Flash Warning "Response already committed"in f :selectItems component?

转载 作者:行者123 更新时间:2023-12-04 05:02:23 35 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Getting warning from JSF: The response was already committed by the time we tried to set the outgoing cookie for the flash

(4 个回答)


3年前关闭。




我在 Mojarra 上遇到了 JSF 2.4 的奇怪行为。
我正在使用 flash 参数从一个页面传递到另一个页面。
每次我到达一个新页面时,我都会在 Postconstruct 注释方法中检索我的 flash 参数。
然后,如果页面被刷新,用户将被重定向到另一个页面。 (因为刷新后会删除flash参数)。

对于相同的代码,如果我从不同的数据(硬编码或数据库查询)填充我的选择项,我会遇到此错误:

JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash. Any values stored to the flash will not be available on the next request.



我想解决这个问题,也许与以下事情有关:

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;
}

最佳答案

始终尝试使用 Mojarra 最新版本来使用 Flash。在您的情况下,尝试将其更新到 2.2.6。正如这里的几篇文章所述,Mojarra 实现中的闪存范围存在很多问题。然而,他们似乎已经解决了这个问题。看到这个 answer (BTW 解释了如何正确使用上下文)。

另见:

  • JSF/Mojarra "flash scope" problems
  • Exception about flash in Mojarra JSF
  • 关于httpresponse - 如何解决 JSF1095 Flash Warning "Response already committed"in f :selectItems component?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22560119/

    35 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com