java - How to show collection elements as items in selectManyListbox? -


i have bean:

public projectserviceimpl {        public list<project> getallprojects () { ... } } 

i want list these projects items in <h:selectmanylistbox>. when user selects 1 or more items , press submit button, selected items should converted projects.

i'm confused little how list items , how correspondent converter should like?

you need implement converter#getasstring() desired java object been represented in unique string representation can used http request parameter. using database technical id (the primary key) very useful here.

public string getasstring(facescontext context, uicomponent component, object value) {     // convert project object unique string representation.     return string.valueof(((project) value).getid()); } 

then need implement converter#getasobject() http request parameter (which per definition string) can converted desired java object (project in case)`.

public object getasobject(facescontext context, uicomponent component, string value) {     // convert unique string representation of project actual project object.     return projectdao.find(long.valueof(value)); } 

finally associate converter object type in question, jsf take care conversion when project comes picture no need specify converterid or f:converter:

<converter>     <converter-for-class>com.example.project</converter-for-class>     <converter-class>com.example.projectconverter</converter-class> </converter> 

this way can create selectitem project value.

you can background info , more ideas out of blog article: http://balusc.blogspot.com/2007/09/objects-in-hselectonemenu.html


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -