<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Knight of the round table

    wansong

    Selecting from a list of entities

    <rich:pickList value="#{manageCountryGroup.selectedCountries}" sourceListWidth="200" targetListWidth="200">
                  <s:selectItems value="#{availableCountriesQuery.resultList}" var="c" label="#{c.name}" itemValue="#{c}" >       
                    </s:selectItems>
                    <s:convertEntity/>
                  <a4j:support action="#" event="onlistchanged" reRender="cgManagementPanel" ajaxSingle="true" />
                </rich:pickList>


    Selecting from a list of entities

    See http://docs.jboss.org/seam/latest/reference/en/html/controls.html

    • Use <s:selectItems> to produce a list of labeled select items from a list of entities.
    • Use <s:convertEntity> to map back and forth between the select items and the actual entity values. This is what allows you to map the value of the <h:selectOneMenu> directly to the property of the referencing entity (e.g. a property that is a many-to-one).
    <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>

    1. person is an entity that has been outjected into the conversation. It has a 'continent' property which is many-to-one association with another entity.
    2. continents is a Seam application framework 'query' object. This 'query' object should probably use a Seam-managed EntityManager because we want have the Hibernate session-in-view behavior so we don't get lazy initialization exceptions when rendering the labels, etc.
    3. s:convertEntity will convert the Continent entities into values for the HTML select, and vice versa.

    Tips

    1. To avoid LazyInitializationExceptions and/or writing extra code in your EJB/Controller bean to initialize objects, use session in view.
    2. For required fields, put required="true" on the selectOneMenu and override javax.faces.component.UIInput.REQUIRED in messages.properties (see Standard Faces Error Messages).

    Select from an enum

    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();

    }

    }

    1. person is an entity that has been outjected into the conversation. It has a 'status' property which is an enum.
    2. We need to expose the values of the enum as a list or an array, so we make a stateless POJO component with getters that returns arrays for various enums called enumLists.

    Multi-select from an enum

    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();

    }



    }

    Retrieved from "


    posted on 2009-04-14 11:01 w@ns0ng 閱讀(986) 評論(0)  編輯  收藏 所屬分類: Jboss Seam

    主站蜘蛛池模板: www成人免费观看网站| 亚洲国产精品自在自线观看| v片免费在线观看| 亚洲а∨天堂久久精品| 亚洲中文字幕久久精品蜜桃| 男女做羞羞的事视频免费观看无遮挡| 精品日韩亚洲AV无码 | 免费人成在线观看播放a| 日本成人在线免费观看| 麻豆亚洲AV成人无码久久精品| 成人午夜性A级毛片免费| 亚洲GV天堂GV无码男同| 亚洲成av人片在线观看天堂无码| 一个人看的免费观看日本视频www 一个人看的免费视频www在线高清动漫 | 1000部禁片黄的免费看| 亚洲理论片在线观看| 免费在线视频你懂的| 亚洲卡一卡二卡乱码新区| 午夜毛片不卡高清免费| 老司机午夜精品视频在线观看免费| www亚洲精品少妇裸乳一区二区| 色屁屁www影院免费观看视频| 亚洲美女高清一区二区三区| 在线涩涩免费观看国产精品 | 在线精品亚洲一区二区三区 | 最新猫咪www免费人成| 亚洲AV无码AV日韩AV网站| 久久精品国产亚洲7777| 免费精品无码AV片在线观看| 亚洲一区二区三区乱码在线欧洲| 在线观看永久免费视频网站| 久久av免费天堂小草播放| 久久亚洲精品无码aⅴ大香| 成人au免费视频影院| 久久久久久噜噜精品免费直播| 亚洲一区二区中文| 国产黄色片在线免费观看| 热99RE久久精品这里都是精品免费| 亚洲国产精品乱码在线观看97| 亚洲VA综合VA国产产VA中| 18禁黄网站禁片免费观看不卡|