Ok, I cleaned up the code to show you what is needed for this problem:
Here is the bean that shows the item list:
| @Name("itemList")
| @Scope(ScopeType.CONVERSATION)
| @Stateful
| @LoggedIn
| public class MItemListActionBean implements MItemListAction {
|
| @In(create = true, value = "myEM")
| private EntityManager em;
|
| // other stuff...
|
| @DataModel("items")
| private List<Item> items;
|
| @DataModelSelection("items")
| private Item item;
|
| @Begin(join=true)
| @Factory("items")
| public void init() {
| // retrieving
| this.allItems = null;
| this.allItems = getItemsFromDB();
| // sorting
| // etc...
| }
|
| @End
| public String selectItem() {
| return "edit";
| }
| }
|
The method getItemsFromDB() just queries the db. Note that if a property changes, the
query returns the same list than before the modification (the only difference will be an
element change in the properties collection inside item).
Here is the bean to edit an item (I show you this just to show the conversation model):
| @Name("editItem")
| @Scope(ScopeType.CONVERSATION)
| @Stateful
| @LoggedIn
| public class EditItemActionBean implements EditItemAction {
|
| @In(create = true, value = "myEM")
| private EntityManager em;
|
| @Begin(nested=true)
| @Factory("itemPropertyList")
| public void initProperties() {
| if(this.item != null) {
| em.refresh(this.item);
| Set<MProperty> set = item.getProperties();
|
| //put properties in the datamodel that will be shown....
|
| }
|
| // other methods ...
|
| public String saveItem() {
|
| // do some stuff with the properties...
|
| // Ends conversation before redirecting to item list
| Conversation conversation = Conversation.instance();
| log.info("Ending " + conversation.getDescription());
| conversation.end(true);
|
| return "ok";
| }
|
|
This is the entity class Item:
| @Entity
| @Name("item")
| @Table(name="item")
| public class Item {
|
| @ManyToOne( targetEntity = ItemClass.class )
| @JoinColumn(name = "it_class", nullable = false)
| private ItemClass itemClass;
|
| @ManyToMany
| @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
| @org.hibernate.annotations.Cascade({
| org.hibernate.annotations.CascadeType.SAVE_UPDATE,
| org.hibernate.annotations.CascadeType.MERGE,
| org.hibernate.annotations.CascadeType.PERSIST})
| @JoinTable(
| name = "item_prop",
| joinColumns = {@JoinColumn(name = "ip_item")},
| inverseJoinColumns = {@JoinColumn(name = "ip_prop")})
| private Set<Property> properties = new HashSet<Property>();
|
| // getters, setters, other stuff...
| }
|
Here is the jsf that shows the item list:
| <div class="section">
| <h:form id="sc_itemlist">
| <t:dataTable value="#{items}" var="row">
|
| <t:columns value="#{itemList.columnHeaders}"
var="columnHeader">
| <f:facet name="header">
| <h:outputText value="#{columnHeader.propertyClassLabel}" />
| </f:facet>
| <!-- triggers iterator to get the next property (property is stored into
currentProperty and can be manipulated without triggering the iterator) -->
| <h:inputHidden value="#{row.nextProperty}" />
| <h:outputText value="#{row.currentProperty.typedValue}"
converter="OutputTextFieldConverter"/>
| </t:columns>
|
| <h:column>
| <f:facet name="header">
| <h:outputText value="Action"/>
| </f:facet>
| <s:link action="#{itemList.selectItem}" value="Edit"/>
| <h:outputText value=" " />
| <s:link action="#{itemList.deleteItem}"
value="Delete"/>
| </h:column>
|
| </t:dataTable>
| </h:form>
| </div>
|
Hope this code is enough to understand the problem... Thanx!
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4062283#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...