简体   繁体   中英

How to generate setters and getters at runtime in java..?

I am having an functionality through which I am displaying the properties of a document on JSF. The properties are coming through a map and I am iterating it over the JSF as follows:

<af:iterator var="list" value="#{MainContentBean.documentProperties}" id="i1">
    <af:inputText label="#{list.key}" id="it1"editable="always" value="list.value">                
</af:iterator>

This is working fine till I want to use it only for the display purpose, but if I want to make it up datatable, ie the user can change the values of the input text box it's not working. The input text box is always displayed in read only mode if the setters and getters are not present. The values I am getting in map is uncertain, so in this situation, how can I generate setters and getters for each property value at runtime? Is this possible to do that?

Yes, it is possible using cglib. Take a look at "Adding setter/getters with cglib to compete with RoR... Dumb idea? Input from Crazy Bob"

Also, take a look at this answer which suggest using ASM

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM