EJB"
(Created page with '{{ZKDevelopersReferencePageHeader}} =Version History= {{LastUpdated}} {| border='1px' | width="100%" ! Version !! Date !! Content |- | | | |} {{ZKDeveloper…') |
m |
||
Line 1: | Line 1: | ||
{{ZKDevelopersReferencePageHeader}} | {{ZKDevelopersReferencePageHeader}} | ||
+ | |||
+ | Enterprise JavaBeans (EJB) technology is the server-side component architecture for Java EE. Here we described to use them in a ZUML document. | ||
+ | |||
+ | Here we use [http://jboss.org JBoss] as the example. The configuration of the server might vary from one server to another, but the ZUML document is the same. | ||
+ | |||
+ | = Use JndiVariableResolver to Resolve EJB in EL Expressions= | ||
+ | Referencing an EJB in an EL expression is straightforward: specifying <javadoc>org.zkoss.zkplus.jndi.JndiVariableResolver</javadoc> in [[ZUML Reference/ZUML/Processing Instructions/variable-resolver|the variable-resolver directive]]. For example, | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <?variable-resolver class="org.zkoss.zkplus.jndi.JndiVariableResolver" ?> | ||
+ | <window> | ||
+ | ... | ||
+ | </window> | ||
+ | </source> | ||
+ | |||
+ | Depending your configuration, you might have to pass extra information about JNDI to it such as: | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <?variable-resolver class="org.zkoss.zkplus.jndi.JndiVariableResolver" | ||
+ | arg0="ZkEJB3Demo" | ||
+ | arg1="mail=java:comp/env/mailing,sec=java:comp/security/module" ?> | ||
+ | <!-- | ||
+ | arg0: prepend - the prepended part of JDNDI name | ||
+ | arg1: mapping - the key-value pairs for JNDI names and the corresponding variable names | ||
+ | --> | ||
+ | <window> | ||
+ | ... | ||
+ | </window> | ||
+ | </source> | ||
+ | |||
+ | <javadoc>org.zkoss.zkplus.jndi.JndiVariableResolver</javadoc> will resolve variables in the following order: | ||
+ | |||
+ | # java:comp/env | ||
+ | # java:comp | ||
+ | # java: | ||
+ | # Variable could be found as a session beans with the <tt>prepend</tt> argument (arg0). | ||
+ | # The key-value pairs which is defined in the <tt>mapping</tt> argument (arg1) | ||
+ | |||
+ | = Example: Retrieve Session Beans = | ||
+ | |||
+ | The session beans are bound to the <tt>java:comp/env</tt> configured by <tt>jboss-web.xml</tt> and <tt>web.xml</tt>. For example, suppose we have them as follows: | ||
+ | |||
+ | <tt>'''jboss-web.xml'''</tt>: | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <ejb-local-ref> | ||
+ | <ejb-ref-name>personLocalBean</ejb-ref-name> | ||
+ | <ejb-ref-type>Session</ejb-ref-type> | ||
+ | <local>demo.PersonBeanLocal</local> | ||
+ | <local-jndi-name>ZkEJB3Demo/PersonBean/local</local-jndi-name> | ||
+ | </ejb-local-ref> | ||
+ | </source> | ||
+ | |||
+ | <tt>'''web.xml'''</tt>: | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <ejb-local-ref> | ||
+ | <ejb-ref-name>personLocalBean</ejb-ref-name> | ||
+ | <ejb-ref-type>Session</ejb-ref-type> | ||
+ | <local-home>demo.PersonBeanLocal</local-home> | ||
+ | <local>demo.PersonBeanLocal</local> | ||
+ | </ejb-local-ref> | ||
+ | </source> | ||
+ | |||
+ | Then, we could access them as follows. | ||
+ | |||
+ | <source lang="xml" high="7"> | ||
+ | <?variable-resolver class="org.zkoss.zkplus.jndi.JndiVariableResolver" ?> | ||
+ | <listbox width="600px"> | ||
+ | <listhead sizable="true"> | ||
+ | <listheader label="name" sort="auto"/> | ||
+ | <listheader label="email" sort="auto"/> | ||
+ | </listhead> | ||
+ | <listitem forEach="${personLocalBean.allPersons}"> <!-- resolve personLocalBean from JNDI --> | ||
+ | <listcell label="${each.name}"/> | ||
+ | <listcell label="${each.email}"/> | ||
+ | </listitem> | ||
+ | </listbox> | ||
+ | </source> | ||
+ | |||
+ | The variables provided by a variable resolver is also available to the Java code in [[ZK Developer's Reference/UI Composing/ZUML/Scripts in ZUML|zscript]]. For example, | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <zscript> | ||
+ | personLocalBean.createDemoData(); | ||
+ | </zscript> | ||
+ | </source> | ||
=Version History= | =Version History= |
Revision as of 11:21, 13 January 2011
Enterprise JavaBeans (EJB) technology is the server-side component architecture for Java EE. Here we described to use them in a ZUML document.
Here we use JBoss as the example. The configuration of the server might vary from one server to another, but the ZUML document is the same.
Use JndiVariableResolver to Resolve EJB in EL Expressions
Referencing an EJB in an EL expression is straightforward: specifying JndiVariableResolver in the variable-resolver directive. For example,
<?variable-resolver class="org.zkoss.zkplus.jndi.JndiVariableResolver" ?>
<window>
...
</window>
Depending your configuration, you might have to pass extra information about JNDI to it such as:
<?variable-resolver class="org.zkoss.zkplus.jndi.JndiVariableResolver"
arg0="ZkEJB3Demo"
arg1="mail=java:comp/env/mailing,sec=java:comp/security/module" ?>
<!--
arg0: prepend - the prepended part of JDNDI name
arg1: mapping - the key-value pairs for JNDI names and the corresponding variable names
-->
<window>
...
</window>
JndiVariableResolver will resolve variables in the following order:
- java:comp/env
- java:comp
- java:
- Variable could be found as a session beans with the prepend argument (arg0).
- The key-value pairs which is defined in the mapping argument (arg1)
Example: Retrieve Session Beans
The session beans are bound to the java:comp/env configured by jboss-web.xml and web.xml. For example, suppose we have them as follows:
jboss-web.xml:
<ejb-local-ref>
<ejb-ref-name>personLocalBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>demo.PersonBeanLocal</local>
<local-jndi-name>ZkEJB3Demo/PersonBean/local</local-jndi-name>
</ejb-local-ref>
web.xml:
<ejb-local-ref>
<ejb-ref-name>personLocalBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>demo.PersonBeanLocal</local-home>
<local>demo.PersonBeanLocal</local>
</ejb-local-ref>
Then, we could access them as follows.
<?variable-resolver class="org.zkoss.zkplus.jndi.JndiVariableResolver" ?>
<listbox width="600px">
<listhead sizable="true">
<listheader label="name" sort="auto"/>
<listheader label="email" sort="auto"/>
</listhead>
<listitem forEach="${personLocalBean.allPersons}"> <!-- resolve personLocalBean from JNDI -->
<listcell label="${each.name}"/>
<listcell label="${each.email}"/>
</listitem>
</listbox>
The variables provided by a variable resolver is also available to the Java code in zscript. For example,
<zscript>
personLocalBean.createDemoData();
</zscript>
Version History
Version | Date | Content |
---|---|---|