JavaScript - And Creating and using Java Objects

og7

New Member
I am creating a web app that requires the use of a Java Object from either a jar or class file. How do I bridge my Java class and JavaScript? (I am fairly new to JavaScript and Web Development in general).(Most of the search results I am getting for this topic are from people who don't realize that Java and JavaScript have nothing to do with each other. This is not the case here.)What I want to accomplish:The PropertiesEditor object first loads a properties file template and splits up the properties into an ArrayList. Then a form is generated on the webpage for each property, and allows the user to edit the values and submit with a new file name. The values are then passed to the PropertiesEditor object and the properties file is created, and saved with the other properties files. This web app will allow non programming users to create new properties files from an existing template; in my case for localization of text language.Java Class:\[code\]public class PropertiesEditor {private File propertiesFile;private ArrayList<Property> propertyList;private Scanner scan;/** * */public void load(String fileName) { try { propertiesFile = new File(fileName); scan = new Scanner(propertiesFile); } catch (FileNotFoundException e) { e.printStackTrace(); } propertyList = new ArrayList<Property>(); try{ while (scan.hasNext()){ String string = scan.nextLine(); if (!(string.startsWith("#"))){ String[] array = string.split("="); String key = array[0]; String value = http://stackoverflow.com/questions/8931997/array[1]; Property property = new Property(key, value); propertyList.add(property); } } }catch (NoSuchElementException nse){ }}public void save(String fileName){ Properties properties = new Properties(); for (Property current : propertyList){ properties.setProperty(current.getKey(), current.getValue()); } try { File file = new File(fileName +".properties"); FileOutputStream fileOut = new FileOutputStream(file); properties.store(fileOut, fileName); fileOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }}public int getNumberOfProperties(){ return propertyList.size();}public String getPropertyKey(int index){ return propertyList.get(index).getKey();}public String getPropertyValue(int index){ return propertyList.get(index).getValue();}public void setPropertyValue(int index, String value){ propertyList.get(index).setValue(value);}}\[/code\]How I'm thinking the JavaScript should look:\[code\]<script type='text/javascript'> var pe = <PropertiesEditorObject>;//Obviously where I want to create the Java Object pe.load("en-us.properties"); function formValidator(){ for (i=0;i<pe.getNumberOfProperties();i++){ var current = document.getElementById(i); pe.setPropertyValue(i, current); } pe.save(document.getElementById('fileName'); } function createForm(){ document.write("<form onsubmit='return formValidator()' >") for (i=0;i<pe.getNumberOfProperties();i++){ document.write( pe.getPropertyValue(i) + "<input type='text' id='" + i + "' /><br />" } document.write("Properties File Name: <input type='text' id='fileName' /><br /><input type='submit' value='http://stackoverflow.com/questions/8931997/Check Form' /><br /></form>"); } </script>\[/code\]
 
Top