![preRenderView preRenderView]()
如果我添加此<f:param name="cid" value="#{javax.enterprise.context.conversation.id}"/>,则一切正常.我有误会吗?If I add this <f:param name="cid" value="#{javax.enterprise.context.conversation.id}"/> then everything works fine. Do I have a misunderstanding? P.S如果没有f:param,则第二次单击commandLink时效果很好,但第一次却没有:(.P.S Without the f:param it works fine when I click on the commandLink for the second time, but not on the first time:(.推荐答案在上一个答案的基础上,肯定是因为TestConversation bean尚未被构建,直到为该表单自动包含cid而为时已晚Building on the previous answer, it's definitely because the TestConversation bean is not being constructed until it's already too late for the form to include the cid automatically.在这种情况下,您正在为视图初始化数据,因此最好将其放在preRenderView事件侦听器中.In this case, you're initializing data for the view, so it's probably better to put it in a preRenderView event listener instead.<f:event type="preRenderView" listener="#{testConversation.init}"/>将此内容放置在facelet模板的早期,例如f:metadata(通常与f:viewParam结合使用),然后删除@PostConstruct批注.这使得init的调用是显式的,而不是依赖于正在构造的bean的副作用而运行,因为它是在EL表达式中引用的.Put this early in your facelet template, such as in the f:metadata (as it's often used in conjunction with f:viewParam), and remove the @PostConstruct annotation. That makes the invocation of init explicit rather than relying on it being run as a side effect of the bean being constructed because it was referenced in an EL expression. 这篇关于会话在提交表单时不会自动传播吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-18 23:42