Spring @ViewScope不';如果不工作,则为每个请求创建bean
我正在从JSF1.2迁移到2.1,我将faces-config.xml中bean的条目更改为注释。我尝试使用@ViewScoped代替@RequestScoped和@ManagedProperties(对于少数类中的许多参数),但每次我为注释为@ViewScoped的表单bean单击submit时,都会重新创建。对于@SessionScoped,一切正常 我在这里读了一些问答,但是我没有强迫它工作 我将JSTL标记更改为rendered atribute,或者将c:if与ui:param rendered一起更改 在my web.xml中,我设置了参数:Spring @ViewScope不';如果不工作,则为每个请求创建bean,spring,jakarta-ee,jsf-2,migration,tomcat6,Spring,Jakarta Ee,Jsf 2,Migration,Tomcat6,我正在从JSF1.2迁移到2.1,我将faces-config.xml中bean的条目更改为注释。我尝试使用@ViewScoped代替@RequestScoped和@ManagedProperties(对于少数类中的许多参数),但每次我为注释为@ViewScoped的表单bean单击submit时,都会重新创建。对于@SessionScoped,一切正常 我在这里读了一些问答,但是我没有强迫它工作 我将JSTL标记更改为rendered atribute,或者将c:if与ui:param ren
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>CLIENT</param-value>
</context-param>
bean的示例使用
<h:selectOneMenu value="#{someNameBean.dataIn.currencyId}" id="currencyId" tabindex="2" >
<f:selectItems value="#{someNameBean.dataIn..availableCurrencies}"/>
</h:selectOneMenu>
更新2:
这是我的错。感谢@kolossus为他指明了方向。
我在寻找答案,我找到并阅读了,现在我不应该在backingbean操作中返回字符串。使用null而不是字符串,它可以工作。我不太理解视图的概念,我认为只要tab/windows相同,viewsped bean id就会存在。现在我知道这就是JSF视图。
我很抱歉给你添麻烦
是否可以使用@viewsped重定向到新页面?注意:如果您从两个不同的视图引用相同的(非会话范围)bean,将创建该bean的两个实例 从支持JSF视图的任何类型的bean来看,在JSF中导航都是非常基本和直接的
public String navigateAway(){
//Do whatever processing you want here
return "page2"; //where page2 is the name of an actual .xhtml file in your application
}
faces\u config.xml
文件中指定的JSF导航案例结果
public String navigateAway(){
//Prior processing
return "go somewhere else" ; //where go somewhere else is a navigation outcome you've specified in your faces_config.xml file
}
在faces\u config.xml
文件中,您将看到
<navigation-rule>
<from-view-id>/register.xhtml</from-view-id>
<navigation-case>
<from-outcome>go somewhere else</from-outcome>
<to-view-id>/review_registration.xhtml</to-view-id>
<redirect/>
</navigation-case>
/register.xhtml
去别的地方
/review_registration.xhtml
null
,而不是方法中的字符串,您将不会被带到另一个视图。此外,根据支持bean的范围,如果返回空值,您可以确保将使用相同的bean实例
要了解更多详细信息,请查看是否放置了@ManagedBean注释?您的@ManagedBean是否有正确的导入?你能向我们展示这个bean的精简版本以及你是如何访问它的吗?你解决了之前问题中描述的序列化问题了吗?如果视图范围的bean不能被序列化,那么就不能为下一个请求保留它。然后,一个新的系统将真正被创建。您需要先解决序列化问题。@BalusC我想已经解决了,javax.faces.STATE\u SAVING\u METHOD=SERVER解决了序列化问题,我也在一个字段中添加了临时字。我现在并没有异常,但ViewScoped仍然不起作用。@jedrus07我编辑了这篇文章。在我看来,序列化仍然可能有问题。这可能是因为您在层次结构中重复了几次@ManagedBean?这里有一些相关问题,您可以查看:和
public String navigateAway(){
//Prior processing
return "go somewhere else" ; //where go somewhere else is a navigation outcome you've specified in your faces_config.xml file
}
<navigation-rule>
<from-view-id>/register.xhtml</from-view-id>
<navigation-case>
<from-outcome>go somewhere else</from-outcome>
<to-view-id>/review_registration.xhtml</to-view-id>
<redirect/>
</navigation-case>