title: API Jena - Get values of data properties
body: <p>I created an interface in java with 4 labels, 4 textfields and some buttons like "Add", "modify, "next", etc. The user will enter name, first name, birth date, etc. After clicking the button "add", the information that he has entered will be added on rdf file. I'm using API Jena. The "next" (in french "Suivant") button does not work. When i click "Next", nothing appears on textfields. I don't understand why. Can you explain me what's wrong?</p>
  
  <h3>Complete Code:</h3>
  
  <pre><code>import java.util.*;
  import com.hp.hpl.jena.rdf.model.*;
  import com.hp.hpl.jena.ontology.*;
  import com.hp.hpl.jena.ontology.impl.*;
  import com.hp.hpl.jena.util.*;
  import java.io.*;
  import java.awt.*;  
  import java.awt.event.*; 
  import com.hp.hpl.jena.vocabulary.RDF;
  import com.hp.hpl.jena.vocabulary.XSD;
  import com.hp.hpl.jena.util.iterator.ExtendedIterator;
  
  
  public class FamilyModel extends Frame
  {   
  TextField[]tabTF=new TextField[4];
  Button bAjout, bModifier, bSupprimer, bPrecedent, bSuivant;
  OntModel model;
  Onto onto;
  
  Button creerBouton(String S, int x, int y)
  {
      Button b=new Button(S);
      add(b);         
      b.setBounds(x,y,120,30);
      return b;
  }
  
  void creerLabel(String etiquette, int x, int y)
  {
      Label la=new Label(etiquette);
      la.setBounds(x,y,100,25);
      add(la);
  }
  
  
  public FamilyModel ()
  {
          setLayout (null);
          setBackground (Color.pink);
          setBounds (100,200,600,450);
  
          creerLabel("Prenom : ",10,50);
          creerLabel("Nom : ",10,100);
          creerLabel("Date de Naissance: ",10,145);
          creerLabel("Genre (H ou F): ",10,190);
  
          //TextFields
          for(int i=0;i&lt;4;i++)
          {
              tabTF[i]=new TextField("");
              tabTF[i].setBackground(Color.white);
              add(tabTF[i]);
          }
          tabTF[0].setBounds(120,45,150,25);
          tabTF[1].setBounds(120,100,150,25);
          tabTF[2].setBounds(120,145, 100,25);
          tabTF[3].setBounds(120,190, 45,25);
  
          bAjout=creerBouton("Ajouter",20,250); 
          setVisible(true);
  
          bModifier=creerBouton("Modifier",138,250); 
          setVisible(true);
  
          bSupprimer=creerBouton("Supprimer",250,250); 
          setVisible(true);
  
          bPrecedent=creerBouton("Precedent",360,250); 
  
          bSuivant=creerBouton("Suivant",450,250); 
          setVisible(true);   
  
          onto = new Onto();
  
          readFileRDF();
  
          traitement(this); 
  
  
  }
  
  
  
  void traitement(Frame fenetre)
  {
  
      bAjout.addActionListener(new ActionAjoutPersonne());
      bSuivant.addActionListener(new ActionSuivant());
  }
  
  
  //Button Add
  public class ActionAjoutPersonne implements ActionListener
  {
  
      public void actionPerformed(ActionEvent evt)
      {
  
          Resource p1 = onto.model.createResource(onto.uriBase+tabTF[0].getText());
  
  
          p1.addProperty(onto.aPourPrenom, tabTF[0].getText());         
          p1.addProperty(onto.aPourNom, tabTF[1].getText());         
          p1.addProperty(onto.aDateNaiss, tabTF[2].getText()); 
  
          if (tabTF[3].getText().equals("F"))
          {
              p1.addProperty(onto.aGenre, tabTF[3].getText()); 
              p1.addProperty(RDF.type, onto.femme);
          }
          else if (tabTF[3].getText().equals("H"))
          {
              p1.addProperty(onto.aGenre, tabTF[3].getText());    
              p1.addProperty(RDF.type, onto.homme);
          }
  
          StringWriter sw = new StringWriter();
          onto.model.write(sw, "RDF/XML-ABBREV");
          String owlCode = sw.toString();
          File file = new File("d:/Onto1.rdf");
          try{
              FileWriter fw = new FileWriter(file);
              fw.write(owlCode);
              fw.close();
          } catch(FileNotFoundException fnfe){
              fnfe.printStackTrace();} 
          catch(IOException ioe){
                  ioe.printStackTrace();
          }                
      }
  }
  
  
  
  public void readFileRDF(){
       String inputFile="D:/Onto1.rdf";
       try{
       InputStream in =new  FileInputStream(inputFile);
        if (in == null) {  
        System.out.println("File not found");
       }  
        onto.model.read(in," ");
  
       }catch(Exception e) {
             System.out.println("model.read catched error: " + e);
       }
  }
  
  //Button Next
  class ActionSuivant implements ActionListener
  {
      public void actionPerformed(ActionEvent evt)
      {
  
          readFileRDF();
  
          //Instances Classe Personne    
          ExtendedIterator instances=onto.personne.listInstances();
  
  
          while (instances.hasNext())
              {
  
                   Individual thisInstance = (Individual) instances.next();
                   thisInstance.getLocalName();
  
                   {
  
                     tabTF[0].setText((thisInstance.getPropertyValue(onto.aPourPrenom)).toString());
                     tabTF[1].setText((thisInstance.getPropertyValue(onto.aPourNom)).toString());
                     tabTF[2].setText((thisInstance.getPropertyValue(onto.aDateNaiss)).toString());
                     tabTF[3].setText((thisInstance.getPropertyValue(onto.aGenre)).toString());
                   }
                   System.out.println("Hello-Apres If");                 
               }
           }
      }
  
  
  //ontologie
  public class Onto 
  {
      OntClass personne, genre, homme, femme, feminin, masculin, evenement, deces, mariage, divorce;
      OntModel model;
      String uriBase;
      ObjectProperty aPourFils, aPourFille, aGenre;
      DatatypeProperty aPourNom, aPourPrenom, aDateNaiss;
  
      public Onto (){
      model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
      uriBase = "http://www.something.com/FAM";
      model.createOntology(uriBase);
  
      //Classes
      personne = model.createClass(uriBase+"#personne");
      femme = model.createClass(uriBase+"#femme");
      homme = model.createClass(uriBase+"#homme");
      genre = model.createClass(uriBase+"#genre");
      feminin = model.createClass(uriBase+"#feminin");
      masculin = model.createClass(uriBase+"#masculin");
      evenement = model.createClass(uriBase+"#evenement");
      deces = model.createClass(uriBase+"#deces");
      mariage = model.createClass(uriBase+"#mariage");
      divorce = model.createClass(uriBase+"#divorce");
  
  
      //Sous-classes
      genre.addSubClass(feminin);
      genre.addSubClass(masculin);
      personne.addSubClass(homme);
      personne.addSubClass(femme);
      evenement.addSubClass(deces);
      evenement.addSubClass(mariage);
      evenement.addSubClass(divorce);
  
      aPourFils = model.createObjectProperty(uriBase+"#aPourFils");
      aPourFils.setDomain(personne);
      aPourFils.setRange(homme);
  
      aPourFille = model.createObjectProperty(uriBase+"#aPourFille");
      aPourFille.setDomain(personne);
      aPourFille.setRange(femme);
  
      aGenre = model.createObjectProperty(uriBase+"#aGenre");
      aGenre.setDomain(personne);
      aGenre.setRange(genre);
  
      aPourNom = model.createDatatypeProperty(uriBase+"#aPourNom"); 
      aPourNom.setDomain(personne);
      aPourNom.setRange(XSD.xstring);
  
      aPourPrenom = model.createDatatypeProperty(uriBase+"#aPourPrenom"); 
      aPourPrenom.setDomain(personne);
      aPourPrenom.setRange(XSD.xstring);
  
      aDateNaiss = model.createDatatypeProperty(uriBase+"#aDateNaiss"); 
      aDateNaiss.setDomain(personne);
      aDateNaiss.setRange(XSD.xstring);
      }
  
  }
  
  public static void main(String args[]) 
  {
  
      new FamilyModel();      
  }
  }
  </code></pre>
  
  <p><strong>Onto.rdf file:</strong></p>
  
  <pre><code>&lt;rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:owl="http://www.w3.org/2002/07/owl#"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
  xmlns:j.0="http://www.something.com/FAM#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"&gt;
    &lt;owl:Ontology rdf:about="http://www.something.com/FAM"/&gt;
    &lt;owl:Class rdf:about="http://www.something.com/FAM#divorce"&gt;
  &lt;rdfs:subClassOf&gt;
    &lt;owl:Class rdf:about="http://www.something.com/FAM#evenement"/&gt;
  &lt;/rdfs:subClassOf&gt;
    &lt;/owl:Class&gt;
    &lt;owl:Class rdf:about="http://www.something.com/FAM#masculin"&gt;
      &lt;rdfs:subClassOf&gt;
        &lt;owl:Class rdf:about="http://www.something.com/FAM#genre"/&gt;
      &lt;/rdfs:subClassOf&gt;
    &lt;/owl:Class&gt;
    &lt;owl:Class rdf:about="http://www.something.com/FAM#deces"&gt;
      &lt;rdfs:subClassOf rdf:resource="http://www.something.com/FAM#evenement"/&gt;
    &lt;/owl:Class&gt;
    &lt;owl:Class rdf:about="http://www.something.com/FAM#feminin"&gt;
      &lt;rdfs:subClassOf rdf:resource="http://www.something.com/FAM#genre"/&gt;
    &lt;/owl:Class&gt;
    &lt;owl:Class rdf:about="http://www.something.com/FAM#mariage"&gt;
       &lt;rdfs:subClassOf rdf:resource="http://www.something.com/FAM#evenement"/&gt;
    &lt;/owl:Class&gt;
    &lt;owl:Class rdf:about="http://www.something.com/FAM#femme"&gt;
      &lt;rdfs:subClassOf&gt;
        &lt;owl:Class rdf:about="http://www.something.com/FAM#personne"/&gt;
      &lt;/rdfs:subClassOf&gt;
    &lt;/owl:Class&gt;
    &lt;owl:Class rdf:about="http://www.something.com/FAM#homme"&gt;
      &lt;rdfs:subClassOf rdf:resource="http://www.something.com/FAM#personne"/&gt;
     &lt;/owl:Class&gt;
    &lt;owl:ObjectProperty rdf:about="http://www.something.com/FAM#aGenre"&gt;
      &lt;rdfs:range rdf:resource="http://www.something.com/FAM#genre"/&gt;
      &lt;rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/&gt;
    &lt;/owl:ObjectProperty&gt;
    &lt;owl:ObjectProperty rdf:about="http://www.something.com/FAM#aPourFille"&gt;
      &lt;rdfs:range rdf:resource="http://www.something.com/FAM#femme"/&gt;
      &lt;rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/&gt;
    &lt;/owl:ObjectProperty&gt;
    &lt;owl:ObjectProperty rdf:about="http://www.something.com/FAM#aPourFils"&gt;
      &lt;rdfs:range rdf:resource="http://www.something.com/FAM#homme"/&gt;
      &lt;rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/&gt;
    &lt;/owl:ObjectProperty&gt;
    &lt;owl:DatatypeProperty rdf:about="http://www.something.com/FAM#aPourNom"&gt;
      &lt;rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/&gt;
      &lt;rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/&gt;
    &lt;/owl:DatatypeProperty&gt;
    &lt;owl:DatatypeProperty rdf:about="http://www.something.com/FAM#aDateNaiss"&gt;
      &lt;rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/&gt;
      &lt;rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/&gt;
    &lt;/owl:DatatypeProperty&gt;
    &lt;owl:DatatypeProperty rdf:about="http://www.something.com/FAM#aPourPrenom"&gt;
      &lt;rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/&gt;
      &lt;rdfs:domain rdf:resource="http://www.something.com/FAM#personne"/&gt;
     &lt;/owl:DatatypeProperty&gt;
    &lt;j.0:femme rdf:about="http://www.something.com/FAMRita"&gt;
      &lt;j.0:aGenre&gt;F&lt;/j.0:aGenre&gt;
      &lt;j.0:aDateNaiss&gt;Mars&lt;/j.0:aDateNaiss&gt;
      &lt;j.0:aPourNom&gt;Henriques&lt;/j.0:aPourNom&gt;
      &lt;j.0:aPourPrenom&gt;Rita&lt;/j.0:aPourPrenom&gt;
    &lt;/j.0:femme&gt;
    &lt;rdf:Description rdf:about="http://www.something.com/FAMRicardo"&gt;
      &lt;j.0:aGenre&gt;H&lt;/j.0:aGenre&gt;
      &lt;j.0:aDateNaiss&gt;maio&lt;/j.0:aDateNaiss&gt;
      &lt;j.0:aPourNom&gt;Silva&lt;/j.0:aPourNom&gt;
      &lt;j.0:aPourPrenom&gt;Ricardo&lt;/j.0:aPourPrenom&gt;
    &lt;/rdf:Description&gt;
  </code></pre>
  
  <p></p>