any playframework dynamic combobox pulldown menu examples out there?

时间秒杀一切 提交于 2020-01-16 04:14:29

问题


I am looking for an example that has some good patterns for doing a combo box....select html element in playframework and helping with the post as in seam it was nice that it auto translated it to the id of the entity I wanted....can I be storing the id with the item somehow in the pulldown so that when selected, I can give the id and label to the server?

Any examples on this would be great!!!! or links to blogs that have some good pattern for this.

thanks, Dean


回答1:


Use the select tag.

From the hotel sample application:

#{select 'booking.beds', value:booking?.beds}
    #{option 1}One king-size bed#{/option}
    #{option 2}Two double beds#{/option}
    #{option 3}Three beds#{/option}
#{/select}



回答2:


I found the answer. The code is the following where id goes as the value(guess I need to brush up on my basic html....previous java frameworks keep you so far away from the basics :( ).

<select name="parent" size="1"> 
     #{list items:projects, as:'project'} 
        <option value="${project.id}">${project.name}</option> 
     #{/list} 
</select>

okay, a better example may be this one so you don't have to worry about setting selected="selected" in the correct option field...

#{select 'parentId', items:projects, valueProperty:'id', labelProperty:'name', value:project?.parent?.id/}

The parentId is the variable name passed into the action post method. The items is the variable passed out from the get into the render. The value prop is the property on your entity. The value is what will be set on the option's value for each item and what gets seet into your parentId variable.....this is all working for me now...sweet.

NOTE: labelProperty cannot be xxx.xxx.xxx. It must be a first level property. and value is what you want read from or written to (a different entity that you passed into the page than the list itself perhaps). In my case above, I passed in projects and I passed in a project as well so items is projects and value is project.parent.id above.



来源:https://stackoverflow.com/questions/9238366/any-playframework-dynamic-combobox-pulldown-menu-examples-out-there

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!