Skip to main content
summaryrefslogtreecommitdiffstats
blob: e7f817e74d39b17b90565d41556a201ce27a93f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http:// www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.jsf.ui.converter.jsfhtml;

import java.util.List;

import org.eclipse.jst.jsf.core.internal.tld.IJSFConstants;
import org.eclipse.jst.pagedesigner.IHTMLConstants;
import org.eclipse.jst.pagedesigner.converter.ConverterUtil;
import org.eclipse.jst.pagedesigner.converter.JSFConverterUtil;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

/**
 * @author mengbo
 * @version 1.5
 * @deprecated Use DTTagConverter meta-data instead
 */
public abstract class SelectBasedTagConverter extends SelectTagConverter
{

    /**
     * @param host
     */
    public SelectBasedTagConverter(Element host)
    {
        super(host);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
     */
    protected Element doConvertRefresh()
    {
        Element hostEle = getHostElement();

        // Render an HTML "select" element.
        Element selectEle = createElement(IHTMLConstants.TAG_SELECT);

        // Render the clientId of the component as the value of the "name" attribute.
        ConverterUtil.copyAttribute(hostEle, IJSFConstants.ATTR_ID, selectEle, IHTMLConstants.ATTR_NAME);

        // XXX: handle ignore
        JSFConverterUtil.copyAllAttributes(hostEle, selectEle, null);
        
//      If the "styleClass" attribute is specified, render its value as the value of 
        // the "class" attribute on the "select" element.
        JSFConverterUtil.copyAttribute(hostEle, IJSFConstants.ATTR_STYLECLASS, selectEle, IHTMLConstants.ATTR_CLASS);
        selectEle.removeAttribute(IJSFConstants.ATTR_STYLECLASS);

        // child class may generated different multiple and size attribute
        handleMultipleAndSize(hostEle, selectEle);

        // next generated the options under the <select>, so they can also be displayed.
        List selectItems = this.getSelectItems(hostEle);
        for (int i=0, size=selectItems.size(); i<size; i++)
        {
            SelectItemModel item = (SelectItemModel) selectItems.get(i);
            Element option = createElement(IHTMLConstants.TAG_OPTION);
            option.setAttribute(IHTMLConstants.ATTR_VALUE, item.getItemValue());
            Text textNode = createText(item.getDisplayString());
            option.appendChild(textNode);
            selectEle.appendChild(option);
        }

        return (selectEle);
    }

    /**
     * @param hostEle
     * @param selectEle
     */
    protected abstract void handleMultipleAndSize(Element hostEle, Element selectEle);

}

Back to the top