0

i am working on project using play 2 framework with java. I want to populate a drop down list from a database table. I have this code that gets a list of the items from the database. the code snippet is shown below.

public static Result gestureNames()
  {
  List <GestureClassEntity> gcet = GestureClassEntity.find.all();
  return ok(render(gcet)); 
}

however when i run this code play framework tells me that it cannot find render.

i have tried to modify the code which i have shown below

public static void gestureNames()
  {
  List <GestureClassEntity> gcet = GestureClassEntity.find.all();
  render(gcet); 
}

play tells me again that it cannot use a method returning Unit as an Handler

still struggling to understand the play framework can some kindly help me out. Cos i am working on a project and time is running out.

1 Answer 1

6

Remember previous question? https://stackoverflow.com/a/12180812/1066240

render() is method of the view, so to use it, you need to specify the view

public static Result gestureNames(){
    List <GestureClassEntity> gcet = GestureClassEntity.find.all();
    return ok(views.html.gestures.render(gcet));    
}

app/views/gestures.scala.html

@(gesturesListFromMyController: List[GestureClassEntity])

@for(gesture <- gesturesListFromMyController){
    <div class="gesture-item">
        <h2>@gesture.name</h2>
        <p>@gesture.description</p>
    </div>
}

BTW: try to simplify your enigmatic models' names, your life will be better. Can't be GestureClassEntity named just as Gesture ???

Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much will try and get back to u. stay blessed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.