问题标签 [postconstruct]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2246 浏览

java - 未调用 Weblogic 10.3.4 上的 @PostConstruct 注释

(这似乎与https://stackoverflow.com/questions/5862085/weblogic10-3-ignores-postconsturt-method重复,但细节很少,没有得到回答)。

我有一个这样的 ManagedBean:

在我的 xhtml 中,我只有Bean Message: #{TestBean.greeting}. 但是,在访问页面时,该方法没有被调用,我得到的是

而不是预期的

getGreeting()控制台确实显示来自该方法 的 sysout ,但不显示来自prepareSomething()

更多信息:我正在使用 JSF 1.2(使用来自 Weblogic 10.3.4 的 jar MW_HOME/common/deployable-libs/jsf-1.2.war!/WEB-INF/lib)、Facelets 1.1.14、RichFaces 3.3.2。我有以下罐子WEB-INF/lib

我也尝试过放置/移除annotations-api.jar,同样的症状。

如有必要,我可能会发布其他文件。

0 投票
1 回答
5317 浏览

exception-handling - JSF PostConstruct 异常处理 - 重定向

我想通过重定向到另一个页面来处理 JSF @PostConstruct 异常。我正在使用FacesContext.getCurrentInstance().getExternalContext().dispatch("page.jsf");which 效果很好,但由于页面使用 2 个支持 bean,它会继续加载另一个支持 bean(如果在另一个支持 bean 上遇到错误,它永远不会到达该调度/重定向)。我的问题是..有没有办法强制调度立即发生而不加载其他所有内容?

0 投票
2 回答
3127 浏览

jsf - ICEfaces 2.0 and h:commandButton method not called, with ice:commandButton everything is ok

I'm trying to use ace:fileEntry to upload a picture, as I read this component requires a submit from h:commandButton in order to start downloading. My problem is that when I switched my ice:commandButton with h:, my managed bean (which is in Conversation Scope) gets created again (@PostConstruct called) and the method in h:commandButton and also the fileEntryListener aren't called anymore.
And as another problem that might be causing this is that when I first enter my page the managed bean gets created and I call conversation begin, but when I do a second request (from a commandLink) the managed bean is created again, and a new conversation is started, after that you can play how long do you want the managed bean doesn't get created again.
Back to my initial question, if I have ice:commandButton the managed bean ins't created again, if it's with h: it gets created again.
And to add a little bit more fun in it, if I remove the rendered attribute (which resolves to true) from ace:fileEntry the fileEntryListener is called, but the action from h:commandButton isn't called no matter what.
I tried to add explicit ids to the components, tried to change ice:form with h:form .. nothing.

Please Help.

Ps: why ICEfaces 2 can't work with all ice components, why does it requires h:commandButton, instead of ice:commandButton, why the new JSF 2.0 stuff with f:selectItems backed by a regular list isn't working with ice:selectOneMenu, works just with h:selectOneMenu ? What's up with ICEfaces ? And why CDI doesn't work as expected, with Seam 2 also I had problems with conversations called twice .. ps2: if I don't navigate to another view ?cid=1 isn't present in the URL.

0 投票
1 回答
1050 浏览

jsf - JSF 1.1 中的@postConstruct

如何模拟@postConstructJSF 1.1 中的行为,就像在 JSF 1.2 和更新版本中一样?

实际上,我想在页面加载期间自动调用一个 bean 方法?

我在 JSF 1.1 上使用 IceFaces 1.8。

0 投票
2 回答
14861 浏览

jsf - 如果 ManagedBean 在 jar 库中,则 JSF 不会调用 @PostConstruct

我正在运行以下问题。

目前,我有一些托管 Bean 在两个 JSF 应用程序之间共享。由于我不想在两者中复制和粘贴代码(将来会更多),我已将此共享托管 bean 放入 JAR 库中。我关注了这个博客:http: //jsflive.wordpress.com/2011/03/24/custom-component-library/

好吧,即使我将 faces-config.xml 放在 JAR/META-INF/ 中,@ManagedBean 和 @ViewScoped 也不起作用。我不知道为什么,但是如果我在 faces-config.xml 中注册 bean(JAR 的,而不是 WAR 的)这个问题就消失了。

我可以忍受这个,但令我惊讶的是,在 JAR 库中没有为这个托管 bean 调用 @PostConstruct 注释。我没有收到任何错误、警告或其他信息。我想 bean 正在加载,但它们的注释没有被处理。

有没有人遇到过这个?

我的环境:Glassfish 3.1.1 (build 12) JSF 2.1.3

提前致谢。

0 投票
1 回答
5132 浏览

jsf - ViewScoped bean 根据每个请求构建...第 99 部分

啊……这似乎有一百个答案,我还没有找到适合我的答案,所以我想我真的会再问一次。这是我的场景:

从技术上讲,我的网站只有一个页面,其内容被换出,而不是您导航到的多个页面。起点是这个块:

resourceInclude.xhtml 包含我的 css 文件:

main.xhtml 是视图:

它由三个h:panelGroups 组成。第一个是一组四个通用导航链接,每个链接都会更改viewSelector.modeName用于包含第二个内容h:panelGroup的值<ui:include src="#{viewSelector.modeName}-view.xhtml" />。我已经为这个例子去掉了这个,所以每个视图基本上都是这样的:

第三个h:panelGroup是所有消息的页脚,用于调试出错的地方。

无论如何,每次我单击其中一个导航链接时,都会调用 viewSelector bean 的构造函数。这就是我的 viewSelector bean 的样子:

我知道我一定是以错误的方式做某事,否则我错过了关于 JSF 如何工作的核心内容。任何输入?

0 投票
2 回答
427 浏览

jsf - 在从 Core JSF 迁移到 Seam 时移植托管 bean 的功能

我曾经用预定义的值初始化实体对象的某些属性,早在它在 jsf 托管 bean(甚至托管 bean 的构造函数)的 @PostConstruct 方法中实例化时。在将项目移植到 Seam 而托管 bean 消失时,我无法再保留此功能(还想知道在没有托管 bean 的 JSF 2.2 中它会如何)。

实体类:

JSF 托管 Bean

JSF 页面

Seam 版本中的无状态会话 Bean 也承担了 jsf 托管 bean 的责任

缝版形式:

我需要有关如何使任务对象保存日期并在实例化时预先填充的登录用户数据(最好是默认类别)的建议。

0 投票
1 回答
400 浏览

jsf - 在显示之前初始化 h:selectOneMenu

我有访问页面,我在其中检查有效用户,如果存在,则传递到下一页并创建一个

基于 typeOfUser。因此,如果用户是 A 型,则选项应为:

如果用户是 B 型,选项应该是:

在任何其他情况下,选项应该是:

而在xhtml页面中如下:

我可以在@PostConstruct 方法中实现这一点吗?或者有没有更好的地方。

谢谢 !

0 投票
2 回答
10608 浏览

ajax - 执行 f:ajax 时始终调用 JSF2 preRenderComponent

我有一个由 NewsBean.java 支持的 JSF 页面,它具有<f:event type="preRenderComponent" listener="#{newsBean.init}" />bean 初始化程序。

页面底部有一个用于发送评论的按钮,其中包含: <f:ajax event="click" execute="@form" render="@form" listener="#{newsBean.sendComment}" /><h:form>。当按钮被点击时,NewsBean.init()总是被调用。

我的 bean 范围是视图。这是一个有效的行为(总是调用 init())吗?我怎样才能防止总是打电话init()

0 投票
1 回答
1112 浏览

jsf - @PostConstruct 和 commandButton/commandLink 参数大小写

我想知道以下场景是否有共同的模式。

假设我有一个由一个请求范围 bean 支持的 JSF 页面。当用户进入此页面时,我想从数据库表中获取所有数据行。同一个 JSF 页面包含一个提供查询条件的表单。当用户提供查询条件并提交表单时,我也想在同一页面上显示结果。

在页面入口处获取所有行的合适位置是 @PostConstruct 方法。这是一个很好的地方,因为额外的(注入的)请求参数已经在这里可用并且可以在查询中使用。但是,从表单提交的参数尚不可用。它们可以在 action 方法中访问。

如果用户使用表单条件查询数据库表,在这种情况下,数据库将被查询两次。将重新创建请求范围的 bean,并在表单操作方法获取用户想要的内容之前调用获取所有行的 @PostConstruct 方法。

当然,我可以将表单结果重定向到另一个 JSF 页面,该页面由不同的 bean 支持,仅在 action 方法中使用 DB 查询。但是有没有办法只获取一个 JSF 页面和一个托管 bean 所需的内容?