繁体   English   中英

如何在@create之前在Seam组件中设置属性?

[英]How to set properties in a Seam component before @create?

我正在尝试将组件org.jboss.seam.mail.mailSession的以下成员设置为:

boolean ssl;
boolean tls = true;

(具有getter和setter方法)被称为的方法create之前。 我想防止框架使用SSL,TLS。 mailSession组件检查是否设置了这些成员。 如果是,它将创建强制javamail使用ssl的属性。

到目前为止,我尝试过:

Object comp = Component.getInstance("org.jboss.seam.mail.mailSession");

问题 :解包到无法访问组件的javax.mail.Session。

Object comp = Component.getInstance("org.jboss.seam.mail.mailSession", ScopeType.APPLICATION,false,false);

问题 :因为没有创建实例,所以返回null。

Component comp = Component.forName("org.jboss.seam.mail.mailSession");

问题 :返回了一个组件而不是实例。

我应该怎么做才能切换2位,您会建议修补框架,还是有一种更容易被我忽略的方法?

根据Seam参考手册Seam论坛,您应该能够直接在components.xml配置中禁用TLS和SSL:

<mail:mail-session debug="true" tls="false" ssl="false" ... />

你已经尝试过了吗?

您是否尝试覆盖mailSession? 我不确定它是否有效...

遵循以下原则

@Name("org.jboss.seam.mail.mailSession")
@Install(precedence=Application)
class MyMailSession extends MailSession {

  //override the stuff you want here
}

我使用以下顺序解决了它:

@In(create = true)
private Renderer renderer;
...
Component comp = Component.forName("org.jboss.seam.mail.mailSession");
MailSession ms = (MailSession)  comp.newInstance();
ms.setDebug(true);
ms.setTls(false);
ms.setSsl(false);
ms = ms.create();

renderer.render("/Mail.xhtml");

我不知道MailSession实例如何附加到该组件,但目前可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM