Question

Hi I am trying to list the words in a HTML div.The list of word is coming from Application.java in controller in play framework.Following is part of Application.java which returns the list.I am not sure if its correct.

Public stattic void explore(){
List<String> suggestionlist = new ArrayList<String>();
 try {  
      String s = null;
      int i=0;

        String[]callAndArgs= {"C:\\Python27\\python.exe","D:\\Dualist\\gui\\app\\controllers\\word2Vec_impl.py" , "D:\\Dualist\\data\\Short_tweets_ground_truth.csv"};
        Process p = Runtime.getRuntime().exec(callAndArgs);
        BufferedReader stdInput = new BufferedReader(new 
        InputStreamReader(p.getInputStream()));
        BufferedReader stdError = new BufferedReader(new 
        InputStreamReader(p.getErrorStream()));
        String[] words = stdInput.readLine().split("#");
        suggestionlist.addAll(Arrays.asList(words));
        for(int j = 0 ;j<=suggestionlist.size()-1 ;j++)
        {
            System.out.println(suggestionlist.get(j));
        }
        }  
     catch (IOException e) 
     {  
        e.printStackTrace();  
     } 

    // done! render!
    render(suggestionlist);
     }

In HTML I want to use these list data as select options .something like below

<select id="birthyear" name="birthyear">
    <option >suggestionlist[0]</option>
    <option >suggestionlist[1]</option>
    <option >suggestionlist[3]</option>
    <option >suggestionlist[4]</option>

</select>

I know this can be done using list tag in play framework but not sure how to use. All kind of inputs are appreciated. Thanks in advance!!

Was it helpful?

Solution

Check out Play! Actions.

Instead of using "render(suggestionlist)", either have this function return the list and call the function from within your action, or build this into your Play! Action. Then, within your Action, you can return "Ok(views.html.thePathToYourTemplate(explore()))", or "Ok(views.html.thePathToYourTemplate(suggestionList))", respectively.

Then, within your Play! template, you can declare the list at the top, and loop through the contents of the list to build your select box.

Hope this helps!

OTHER TIPS

Ok, I'm not sure on how big you want the list to be, but give your option tags id's and then in the <script> area of your code, you can do:

_Array = [];
_Array[0] = "option1" // Array stores the Id's of your option tags....
_Array[1] = "option2"
_Array[2] = 'ect
_Array[3] = 'ect'
for(x=0;x<4;x++)
{
optionName = document.createTextNode(SuggestionListVAriable);
options = document.getElementById(_Array[x]);
options.appendChild(optionName);
}

Not quite sure if this answers your question...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top