Take array values returned from another class

Asked

Viewed 1,040 times

3

I need to pass the variable value sgEstado for the other class but I can’t, the value is in the return when threshing, but I can’t get the value out in the other class.

 ArrayList estados;
            try {
                Session session = InitSessionFactory.getInstance().getCurrentSession();
                estados = (ArrayList) session.createCriteria(FilialComplementoTO.class).addOrder(Order.asc("sgEstado")).list();

            } catch (Exception e) {
                Logger.getLogger(this.getClass().getName()).error(e.getMessage());
                throw new IntegrationException(e);
            }
            return estados;
        }

Second code, if the value of sgSstado come out in the "passed" below is great, Grateful.

try {
            ctx.get(FilialComplementoTO.FILIAL_COMPLEMENTO_KEY);
            //FilialComplementoTO filialComplementoTO = (FilialComplementoTO) ctx.get(FilialComplementoTO.FILIAL_COMPLEMENTO_KEY);
            LocalizarLojasCompositeEntity localizarLojasCompositeEntity = new LocalizarLojasCompositeEntity();
            localizarLojasCompositeEntity.findEstadosBySgEstado();
            System.out.println(localizarLojasCompositeEntity.findEstadosBySgEstado());
            System.out.println("passou");
}
  • The top code is the method localizarLojasCompositeEntity.findEstadosBySgEstado()? What happens when you run? Something appears that shouldn’t? If you guarantee that estados has a value the only problem is that you are returning a ArrayList, or is a variable with multiple elements. You cannot have a ArrayList as a whole, you would need to print the elements of it (even so it depends on how each element of this array). This is usually done with for in.

  • The code is the locationLojasCompositeEntity, it normally executes when executed, it appears the "passed" and I verify that the value of 'states' which is a list is correct, with the data I want, in the other code I do not know how to pull from the list created above only the field "Sgestado", which is the field I wish to do a filtering by customer’s state. I don’t know how to just pull a data from the list built in the end method()

  • And what is the content (type) of each element of this ArrayList?

  • The answer helped? You can accept it.

1 answer

2

It seems to me what you need to do is just sweep the array returned by the method that provides the list of states:

try {
    ctx.get(FilialComplementoTO.FILIAL_COMPLEMENTO_KEY);
    //FilialComplementoTO filialComplementoTO = (FilialComplementoTO) ctx.get(FilialComplementoTO.FILIAL_COMPLEMENTO_KEY);
    LocalizarLojasCompositeEntity localizarLojasCompositeEntity = new LocalizarLojasCompositeEntity();
    estados = localizarLojasCompositeEntity.findEstadosBySgEstado();
    for(string estado : estados) {
        System.out.println(estado);
    }
    System.out.println("passou");
}

I put in the Github for future reference.

I kicked that in the ArrayList of estados exist strings. Otherwise I’d need to change the guy in for in and if the type is another data structure, take the specific element you want to print.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.