简体   繁体   English

如何以编程方式访问faces-config.xml中设置的端点属性?

[英]how can I access endpoint properties set in faces-config.xml programmatically?

I am using the IBM Social Business Toolkit. 我正在使用IBM Social Business Toolkit。 I have defined a connection for my Notes app via endpoints in the faces-config xml file. 我已经通过faces-config xml文件中的端点为我的Notes应用程序定义了一个连接。 I wonder how I can access this file pro grammatically since I could not find a service that returns me the base url of IBM Connections. 我想知道如何以编程方式访问此文件,因为我找不到返回IBM Connections基本URL的服务。

It's useful to remember that an endpoint definition is really just creating a managed bean. 记住端点定义实际上只是创建一个托管bean是很有用的。 The managed bean has a variable name you refer to it - the managed-bean-name property. 托管bean具有您引用它的变量名称 - managed-bean-name属性。 You can access this directly from SSJS or via ExtLibUtil.resolveVariable() in Java. 您可以直接从SSJS或通过Java中的ExtLibUtil.resolveVariable()访问它。 The definition also tells you the Java class that's being used, eg com.ibm.sbt.services.endpoints.ConnectionsBasicEndpoint. 该定义还告诉您正在使用的Java类,例如com.ibm.sbt.services.endpoints.ConnectionsBasicEndpoint。 That really gives you all the information you need to get or set the properties. 这确实为您提供了获取或设置属性所需的所有信息。

So from SSJS you can just cast it to the class name, eg 所以从SSJS你可以把它转换为类名,例如

var myService:com.ibm.sbt.services.endpoints.ConnectionsBasicEndpoint = connections

So the bit after the colon will be the managed-bean-class value and the bit after the equals sign will be the managed-bean-name. 因此冒号后面的位将是managed-bean-class值,而等号后面的位将是managed-bean-name。 In Java, you can use 在Java中,您可以使用

ConnectionsBasicEndpoint myService = (ConnectionsBasicEndpoint) ExtLibUtil.resolveVariable(ExtLibUtil.getXspContext().getFacesContext(), "connections");

You'll then have access to all the methods of the class, so you should be able to retrieve what you need. 然后,您将可以访问该类的所有方法,因此您应该能够检索所需的内容。

The properties are part of the Java class, who are referred to in the Faces-Config.xml. 这些属性是Java类的一部分,在Faces-Config.xml中引用它们。 So get the class by his fully qualified name or by bean name and set or get the properties 因此,通过他的完全限定名称或bean名称来获取类,并设置或获取属性

I think the best route will most likely be what Paul is suggesting: resolve the variable by its name and use the getters to get the effective properties that way. 我认为最好的路线很可能就是Paul所建议的:通过名称解析变量并使用getters以这种方式获得有效的属性。

Sven's suggestion is a good one to keep in mind for other situations. 对于其他情况,斯文的建议是一个很好的建议。 By accessing the faces-config.xml file as a resource, you could load it into an XML parser and find the values using XPath. 通过将faces-config.xml文件作为资源访问,您可以将其加载到XML解析器中并使用XPath查找值。 I'm doing much that sort of technique in the next version of the OpenNTF Domino API, which will have a set of methods for manipulating the Faces config. 我在OpenNTF Domino API的下一个版本中做了很多这样的技术,它将有一组操作Faces配置的方法。 However, one key aspect there is that reading the XML file directly will just get you the string values, which may be EL expressions, whereas going the resolveVariable route will get you the real current properties. 但是,一个关键方面是直接读取XML文件只会获得字符串值,这可能是EL表达式,而使用resolveVariable路径将获得真正的当前属性。

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

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