1

how to convert html combo box to zk combo box

asked 2013-05-29 05:55:42 +0800

anujtarun gravatar image anujtarun flag of India
205 6

updated 2013-05-29 06:59:28 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

I need to convert html combo box to zk combobox

HTML code is below

<Select name="122"  > 
<option value="12">Cheque</option>
<option value="12">Cash</option>
</select>

zk combo box is below

 <combobox   model="@bind(reportlist.dynamiclist)" selectedItem="@bind(reportlist.selectedDynamiclist)" 
itemRenderer="com.systems.common.SelectOptionRenderer">
</combobox>
delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-05-29 07:02:21 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Firstly your question is not cler if you are using static combobox as you used in Html code then it will be the code..

<combobox id="box" width="100px" mold="rounded" >
        <comboitem id="a" label="value a" />
        <comboitem id="b" label="value b" />
        <comboitem id="c" label="value c" />
    </combobox>
link publish delete flag offensive edit

Comments

see the HTML code will be entered by the user from front end and it will be saved in DB, I will fetch from the DB and i have to display the value of html combobox into zk combobox and I can't ask user to to enter zk combobox code.

so i have html code like below and i have to convert it into zk comb

anujtarun ( 2013-05-29 07:57:07 +0800 )edit

you can save zul code inside DB.

hswain ( 2013-05-29 08:11:06 +0800 )edit
1

answered 2013-05-29 18:57:24 +0800

jatindersingh gravatar image jatindersingh
93 5
http://javaj2eehub.com/

If you are saving the HTML code for select box in DB then you can use the below code to parse the HTML code and save its value and name either in Model or in hashtable,later you can use to populate the combobox model.

import java.io.IOException;
import java.io.StringReader;
import java.util.Hashtable;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class MyTest 
{
public static void main(String as[])
{
    String strXml="<Select name='122'><option value='12'>Cheque</option><option value='12'>Cash</option></Select>";
    try
    {
     Document doc=loadXMLFromString(strXml);
     doc.normalize();
     NodeList nList=doc.getElementsByTagName("Select");
     Hashtable<String, String> selectBox=new Hashtable<String,String>();
     for(int i=0;i<nList.getLength();i++)
     {
        Node rootN=nList.item(i);
        if(rootN!=null && rootN.getNodeType()==Node.ELEMENT_NODE)
        {
            Element rootE=(Element)rootN;
            NodeList dataList=rootE.getElementsByTagName("option");
            for(int j=0;j<dataList.getLength();j++)
            {
                String strName=null;
                String strValue=null;
                if(dataList!=null)
                {
                    Node rootNode=dataList.item(j);
                    Element el = (Element)rootNode;
                    if(el.getFirstChild()!=null)
                    {
                        strName=el.getFirstChild().getNodeValue();
                    }
                    strValue=getAttribute(rootNode);
                    if(strValue!=null && strValue.length()>0 && strName!=null && strName.length()>0)
                    {
                        selectBox.put(strName, strValue);
                    }
                    else
                    {
                        selectBox.put(strName, strName);
                    }
                }
            }
        }
     }
    }
    catch(Exception e)
    {

    }
}
private static String getAttribute(Node node)
{
    String lookupName="";
    Element child = (Element) node;
    lookupName=child.getAttribute("value");
    return lookupName;
}
private static Document loadXMLFromString(String xml) throws Exception
{
    Document doc=null;
    try
    {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(xml));
        doc=builder.parse(is);
    }
    catch(ParserConfigurationException pce)
    {
         throw pce;
    }
    catch(IOException io)
    {
         throw io;
    }
    catch(SAXException saxe)
    {
         throw saxe;
    }
    catch(Exception e)
    {
         throw e;
    }
    return doc;
}
}
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-05-29 05:55:42 +0800

Seen: 39 times

Last updated: May 29 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More