[jboss-user] [JBoss jBPM] - Re: How to use hibernate session in jbpm xhtml files
dleerob
do-not-reply at jboss.com
Fri Oct 5 05:26:50 EDT 2007
I'm not sure how it's done using JSF, but I make use of my own tags to access info from jbpm libraries/database. Here's an example of how I do it:
/**
| * This tag will create an html dropdown list of all the current
| * groups within the jbpm database, where the value and label of
| * each option is the group name.
| *
| * @jsp.tag name="groupSelectBox" bodycontent="empty"
| */
| public class GroupListTag extends BaseTag {
|
| private static final long serialVersionUID = 1L;
| protected String name = null;
| protected String type = null;
|
| /**
| *
| */
| protected void execute() throws Exception {
| JbpmContext jbpmContext = null;
| try {
| jbpmContext = StaticVariables.jbpmConfiguration.createJbpmContext();
| //get list of jbpm groups
| Session session = jbpmContext.getSession();
| String hibernateQuery = "from org.jbpm.identity.Group g";
| if (type != null) {
| //we then only want groups with the given group type.
| hibernateQuery += " where g.type = '"+type+"'";
| }
| List jbpmGroupList = session.createQuery(hibernateQuery).list();
| //create html drop down list of desired groups.
| jspOut.println("<SELECT name='"+name+"'>");
| jspOut.println("<OPTION value=''>-- Please Select --</OPTION>");
| for (int x = 0; x < jbpmGroupList.size(); x++) {
| Group group = (Group)jbpmGroupList.get(x);
| jspOut.println("<OPTION value='"+group.getName()+"'>"+group.getName()+"</OPTION>");
| }
| jspOut.println("</SELECT>");
| }
| catch (Exception e) {
| e.printStackTrace();
| }
| finally {
| jbpmContext.close();
| }
| }
|
| /**
| * Setter for name of the dropdown list.
| * @jsp.attribute required="true" rtexprvalue="true"
| */
| public void setName(String name) {
| this.name = name;
| }
|
| /**
| * Setter for the type of group.
| * @jsp.attribute required="false" rtexprvalue="true"
| */
| public void setType(String type) {
| this.type = type;
| }
My .tld is auto generated, using the xdoclet tags you see above. Here's what it may look like:
<taglib>
|
| <tlib-version>1.0</tlib-version>
| <jsp-version>1.2</jsp-version>
| <short-name>workflow</short-name>
|
| <description><![CDATA[Custom tag library for this application]]></description>
|
| <tag>
|
| <name>groupSelectBox</name>
| <tag-class>workflow.webapp.taglib.DepartmentListTag</tag-class>
|
| <attribute>
| <name>name</name>
| <required>true</required>
| <rtexprvalue>true</rtexprvalue>
|
| </attribute>
| <attribute>
| <name>type</name>
| <required>false</required>
| <rtexprvalue>true</rtexprvalue>
|
| </attribute>
|
| </tag>
| </taglib>
Finally, my JSP page that makes use of the tag:
<workflow:groupSelectBox name="CostCentre" type="Cost Centre"/>
Hope it gives you some ideas...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4091897#4091897
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4091897
More information about the jboss-user
mailing list