锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
seam generate
鍚姩JBoss
seam explode 鍙樻洿縐誨叆jboss搴旂敤鏈嶅姟鍣?br />
seam hot deploy to jboss5.1:
yes just delete <value>WEB-INF/dev</value> from line 100 of $JBOSS_HOME/server/default/conf/bootstrap/profile.xml
seam 浠ar緇撴瀯閮ㄧ講鍒癹boss錛岄亣鍒頒竴涓棶棰橈紙not bound錛夛細
<transaction:ejb-transaction/>
鎸塖eam鍙傝冩墜鍐岋紝JBoss Seam欏圭洰鐨勬祴璇曞彲浠ヤ嬌鐢╫rg.jboss.seam.mock.SeamTest鏉ュ畬鎴愩?/p>
http://happydev.javaeye.com/blog/328099
See http://docs.jboss.org/seam/latest/reference/en/html/controls.html
<h:selectOneMenu value="#{person.continent}" required="true"> (1)
<s:selectItems value="#{continents.resultList}" var="continent" (2)
label="#{continent.name}" noSelectionLabel="Please Select..."/>
<s:convertEntity /> (3)
</h:selectOneMenu>
This works just like selecting an entity, but <s:convertEnum/> is used instead.
XHTML:
<h:selectOneMenu id="marketStatus" value="#{person.status}" (1)
required="true">
<s:selectItems value="#{enumLists.statusArray}" var="status" (2)
label="#{status}"
noSelectionLabel="Select a status..."/>
<s:convertEnum/>
</h:selectOneMenu>
EnumLists.java:
@Name("enumLists")
@Scope(ScopeType.STATELESS)
public class EnumLists
{
public Status[] getStatusArray()
{
return Status.values();
}
}
Here we use a selectManyCheckbox.
<h:selectManyCheckbox id="roles"
layout="pageDirection" value="#{person.roles}"
required="true">
<s:selectItems value="#{enumLists.roleArray}" var="role"
label="#{role}"/>
<s:convertEnum/>
</h:selectManyCheckbox>
Unfortunately, Seam's convertEnum can't handle multi selects yet. This example will yeild a strange exception:
java.lang.IllegalArgumentException: java.util.List is not an enum type
Luckily, it's very easy to create custom converter tags with Facelets. Here is the converter class that handles both ordinary enums and multi-selects:
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();
}
}