[JBoss Seam] - EnumConverter for multi-select lists
by pgmjsd
Hi everyone. I'd like to contribute the following converter. It allows you to use a multi-select list with enum values. I just took the existing EnumConverter and added come code to look for the s:selectItems control that has a value which is a list or array of enums.
I put something up on my own wiki about it here:
http://shrubbery.mynetgear.net/wiki/Select_lists_with_Seam#Multi-select_f...
And here's the code:
| package eg;
|
| import javax.faces.component.*;
| import javax.faces.context.*;
| import javax.faces.convert.*;
| import javax.faces.el.ValueBinding;
| import java.util.List;
| import java.util.Collection;
|
| /**
| * Converter for enum multi-selects.
| * <br>User: Joshua Davis
| * Date: May 16, 2007
| * Time: 7:25:58 AM
| */
| public class EnumListConverter implements Converter
| {
| @SuppressWarnings({"unchecked"})
| public Object getAsObject(FacesContext context,
| UIComponent comp,
| String value)
| throws ConverterException
| {
| ValueBinding binding = comp.getValueBinding("value");
| Class enumType = binding.getType(context);
| if (enumType.isEnum()) // Single enum?
| return Enum.valueOf(enumType, value);
| else // List of enums.
| {
| // Find the s:selectItems so we can get the enum.
| List children = comp.getChildren();
| for (Object child : children)
| {
| if (child instanceof UIComponent)
| {
| UIComponent c = (UIComponent) child;
| ValueBinding b = c.getValueBinding("value");
| Class t = b.getType(context);
| // Array of enums: use the component type.
| if (t.isArray() && t.getComponentType().isEnum())
| {
| t = t.getComponentType();
| return Enum.valueOf(t,value);
| }
| else
| {
| Object v = b.getValue(context);
| // Collection of enum values, get the type of the first element.
| if (v instanceof Collection)
| {
| t = ((Collection) v).iterator().next().getClass();
| return Enum.valueOf(t,value);
| }
| }
| }
| }
| throw new ConverterException("Unable to find selectItems with enum values!");
| }
| }
|
| public String getAsString(FacesContext context,
| UIComponent component,
| Object object)
| throws ConverterException
| {
| if (object == null) {
| return null;
| }
|
| return ((Enum) object).name();
| }
|
| }
|
After registering it with facelets, it can be used like this:
| <h:selectManyCheckbox id="roles"
| layout="pageDirection" value="#{person.roles}"
| required="true">
| <s:selectItems value="#{enumLists.roleArray}" var="role"
| label="#{role}"/>
| <s:convertEnum/>
| </h:selectManyCheckbox>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4046424#4046424
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4046424
18 years, 11 months
[JCA/JBoss] - Problem in acessing Oracle data Source from JBoss 4
by jsbhangra
Hello,
I am trying to access Oracle data source in Jboss from a struts based web application. For doing this I have done the following:
i am using Oracle 10g Express edition.
(1) Copied the thin oracle driver (ojdbc14.jar) in server\default\lib directory of
JBOSS_HOME.
(2) Copied the oracle-ds.xml file from docs\examples\jca directory of JBOSS_HOME to
server\default\deploy of JBOSS_HOME.
which is :
<local-tx-datasource>
<jndi-name>oracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@localhost:1521:XE</connection-url>
<user-name>uname</user-name>
pwd
<type-mapping>OracleXE</type-mapping>
</local-tx-datasource>
(3) Next I have changed the default standardjaws.xml. I have changed the data source
name and its type-mapping to OracleXE.
i added type mapping for Oracle XE simply copeing the content of whole oracle 8 type mapping and just changed its name to OracleXE
java:/oracleDS
<type-mapping>OracleXE</type-mapping>
false
<default-entity>
<create-table>true</create-table>
<remove-table>false</remove-table>
<tuned-updates>true</tuned-updates>
<read-only>false</read-only>
<time-out>300</time-out>
<row-locking>false</row-locking>
<read-ahead>false</read-ahead>
</default-entity>
(4) I have changed standardjbosscmp-jdbc.xml file also.
(5) I have put an entry in login-config.xml file also.
But when i deploy my application
these are the excpetions i get in my server log :---
Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: oracle.jdbc.driver.OracleDriver
Could not create deployment: ile:/usr/local/jboss-4.0.5.GA/server/default/deploy/oracle-ds.xml
please help me out.. i am unable to figure out the problem.
some more desciptive server log dump :
14:05:45,430 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=oracleDS' to JNDI name 'java:oracleDS'
14:05:45,512 WARN [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: oracle.jdbc.driver.OracleDriver; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: oracle.jdbc.driver.OracleDriver))
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:179)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:565)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:250)
rg.jboss.resource.JBossResourceException: Failed to register driver for: oracle.jdbc.driver.OracleDriver; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: oracle.jdbc.driver.OracleDriver)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:287)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:170)
... 122 more
Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: oracle.jdbc.driver.OracleDriver
at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:306)
44 ERROR [GeneralPurposeDatabasePersistencePlugin] Cannot create timer table
org.jboss.deployment.DeploymentException: Error while checking if table aleady exists TIMERS; - nested throwable: (org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: oracle.jdbc.driver.OracleDriver; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: oracle.jdbc.driver.OracleDriver)); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: oracle.jdbc.driver.OracleDriver; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: oracle.jdbc.driver.OracleDriver))))
at org.jboss.ejb.plugins.cmp.jdbc.SQLUtil.tableExists(SQLUtil.java:1040)
at org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin.createTableIfNotExists(GeneralPurposeDatabasePersistencePlugin.java:112)
at org.jboss.ejb.txtimer.DatabasePersistencePolicy.startService(DatabasePersistencePolicy.java:95)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4046419#4046419
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4046419
18 years, 11 months
[Installation, Configuration & Deployment] - ServerBindings not working
by jcash
I have set up a server-bindings file to change the ports that JBoss uses. This file is based on the jboss example, and some of the ports (RMI) are overridden, but the http 8080 port seams unchanged.
Below is the tomcat section of my file. You will notice that 8080 has been changed to 10080.
When I start JBoss and run netscan I see that port 8080 is being used by JBoss. Is there any where else that I need to change the tomcat ports?
<!-- ********************* tomcat ********************** -->
<service-config name="jboss.web:service=WebServer"
delegateClass="org.jboss.services.binding.XSLTFileDelegate"
>
<delegate-config>
<xslt-config configName="ConfigFile"><![CDATA[
<xsl:stylesheet
xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:output method="xml" />
<xsl:param name="port"/>
<xsl:variable name="portAJP" select="$port - 71"/>
<xsl:variable name="portHttps" select="$port + 363"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match = "Connector">
<xsl:for-each select="@*">
<xsl:choose>
<xsl:when test="(name() = 'port' and . = '8080')">
<xsl:attribute name="port"><xsl:value-of select="$port" /></xsl:attribute>
</xsl:when>
<xsl:when test="(name() = 'port' and . = '8009')">
<xsl:attribute name="port"><xsl:value-of select="$portAJP" /></xsl:attribute>
</xsl:when>
<xsl:when test="(name() = 'redirectPort')">
<xsl:attribute name="redirectPort"><xsl:value-of select="$portHttps" /></xsl:attribute>
</xsl:when>
<xsl:when test="(name() = 'port' and . = '8443')">
<xsl:attribute name="port"><xsl:value-of select="$portHttps" /></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
]]>
</xslt-config>
</delegate-config>
</service-config>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4046413#4046413
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4046413
18 years, 11 months