Hi gurus!
we have a many to many asso. from contact to receiverlist. and both are in a many to one asso. to user. means a user can have many receiverlists and many contacts. and a contact can belong to may receiverlists and inverse.
if we now make a update in our receiverlist. e.g. add a new contact to the receiverlist. in the tables it will be updated. also in the "consists_of" table
( m2m tablename). but if we load the new receiverlist, it wont be updated in our jsp view...
some one's got an idea.. or need some code snippets?
THX A LOT
receiverlist.hbm.xml:
...
<many-to-one name="user" column="u_id" class="user.User"/>
<set name="contacts" table="consists_of" cascade="save-update" >
<key column="receiverlist_id"/>
<many-to-many class="contact.Contact" column="contact_id" />
</set>
...
contact.hbm.xml:
...
<many-to-one name="user" column="u_id" class="user.User"/>
<set name="receiverlists" table="consists_of" cascade="save-update" inverse="true">
<key column="contact_id"/>
<many-to-many class="receiverlist.Receiverlist" column="receiverlist_id"/>
</set>
...
show_recieverlist.jsp:
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@page import="user.*, receiverlist.*, java.util.*"%>
<%
User user = (User) session.getAttribute("user");
if (user == null)
{
%>
<h1><bean:message key="error.login"/></h1>
<p><a href='<%= response.encodeURL("view/login/login.jsp")%>'>
<bean:message key="link.login"/></a><p>
<%
return;
}
String receiverlist_id = request.getParameter("receiverlist_id");
Set receiverlists = user.getReceiverlists();
Iterator iter = receiverlists.iterator();
Receiverlist receiverlist = (Receiverlist)iter.next();
while(receiverlist.getReceiverlist_id() != Integer.parseInt(receiverlist_id))
{
if(iter.hasNext())
{
receiverlist = (Receiverlist)iter.next();
}
else
{
%>
<p><bean:message key="error.receiverlist"/></p>
<%
return;
}
}
Set contacts = receiverlist.getContacts();
%>
<h1><bean:message key="home.title"/>
<bean:write name="user" property="firstname"/>
<bean:write name="user" property="name"/></h1>
<h2><bean:message key="receiverlist.title"/></h2>
<logic:iterate id="contactsIter" collection="<%= contacts %>">
<bean:write name="contactsIter" property="firstname"/>
</logic:iterate>
|