How to Call Values from Another Class

Asked

Viewed 337 times

3

I am creating a vehicle control, and in it I have a register of Fuel that has description and value, and another record of Supplies. My supply record has a autoComplete of Fuel. The problem starts here, when I select the fuel I need to call the cost value that is registered in this fuel.

Example: I selected Diesel.

TOTAL = Valor * LitrosAbastecidos.

But the variable Valor is in the Fuel class. Would someone have some simple way to solve this?

Note: System made in Java, Hibernate, JSF

Calls to the Combustible

<p:autoComplete id="combustivel" value="#{abastecimentoControle.abastecimento.combustivel}" completeMethod="#{combustivelControle.listaFiltrando}"
                                       converter="#{combustivelControle.combustivelConverter}"
                                       var="c"
                                       disabled="true"
                                       itemValue="#{c}"
                                       itemLabel="#{c.descricao}"/>

My Filtering List

public List<Combustivel> listaFiltrando(String parte){
    System.out.println("Parte: "+parte);
    return combustivelFacade.listaFiltrando(parte);
}
  • How are you doing this? select in the database ? in a java list? try to edit your question in more detail.

  • I edited it, man, if you need any more details

  • I found your question somewhat confusing. I couldn’t understand exactly what it is you’re asking or what it is you’re trying to do. Maybe if you give more details about the class Combustivel, get better at understanding.

  • My fuel class has: Id, description and value. In my supply I will have to select the fuel take the value of this selected fuel and do the bill. My difficulty is how to get the value of the selected fuel.

  • You could implement a call via ajax in the "onChange" method of your field and fetch fuel from the selected object...

  • How would you do that ?

Show 1 more comment

1 answer

2


Leandro, when you call the fuel apparently you arrow the fuel attribute of the fuel supply object which is an attribute of the fuel object:

value="#{abastecimentoControle.abastecimento.combustivel}"

So I would do so within the supply classControl:

Double total = this.getAbastecimento().getCombustivel().getValor() * litrosAbastecidos
  • Yes, I could understand, but how would I get the fuel that the user selected ? This I could not understand

  • When you enter the fuel in the autocomplete input, the attribute: value="#{fueling Control.refueling}" gets the selected value from the list: completeMethod="#{combustivelControl.listand}"

  • Sorry, I just entered before completing the comment... It is as follows: the component primefaces autocomplete receives the dao object list through: completeMethod="#{combustivelControl.listanFiltrando}" and uses this list to autocomplete the input when you type something, at the same time as you arrow the attribute: "#{fuelling...

  • I get it, but how am I supposed to get the number? Sorry I’m new to the subject rs this is my listFilling public List<Combustible> listFiltrando(String part){ System.out.println("Part: "+part); Turn combustible.listFiltrando(part); }

  • I believe that the return of the method(Fuel Remanufacturelist.listFilting(part);) returns a list of dao(correct?) objects so when you enter the fuel in the input the value submitted to the controller(value="#{Fuel ForwardControl.refueling}") is actually the combustible object of the list that came from dao, who does this is the component, maybe you have to put a button or use ajax to submit(setar) the value in the controller, I can only think this with the information you passed, maybe if I saw the dao, the convert and the screen with more details would help you more

  • Guy got a lot of thanks, your tips helped me a lot

  • Good, happy, good luck!!

Show 2 more comments

Browser other questions tagged

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