Got it. :jumping: It seems my lack of understanding of the wiring model had
me.
In case other people have problems getting it to work I'll post my way to
get it to work.
1. Read the documentation
2. Re-read it
The problem was that the JSP code needs you to implement the TODO: part(that
I missed)
AdresseForm.jsp:
============
<!-- TODO: change this to read the identifier field from the other pojo -->
<s:select name="adresse.postadresse.id" list="postadresseList"
listKey="id" listValue="postnummer"></s:select>
I have changed the values in the "s:select" tag to reflect using the id as
listkey and postnummer(String field) as value for the dropdown.
Next I needed to add a some to the AdresseAction
AdresseAction.java:
==============
Added field:
private GenericManager<Postadresse, Long> postadresseManager;
Added a setter:
public void setAdresseManager(GenericManager<Adresse, Long> adresseManager)
{
this.adresseManager = adresseManager;
}
And added the method(which is called due to the list="postadresseList"):
public List getPostadresseList() {
return postadresseManager.getAll();
}
Lastly I needed to add a littlebit to the applicationContext.xml:
=============
<bean id="adresseAction" class="no.etj.webapp.action.AdresseAction"
scope="prototype">
<property name="adresseManager" ref="adresseManager"/>
<property name="postadresseManager" ref="postadresseManager"/>
</bean>
This did the trick!
Full source files after the change is here:
adresseForm.jsp:
=============
<%@ include file="/common/taglibs.jsp"%>
<head>
<title><fmt:message key="adresseDetail.title"/></title>
<meta name="heading" content="<fmt:message
key='adresseDetail.heading'/>"/>
</head>
<s:form id="adresseForm" action="saveAdresse" method="post" validate="true">
<s:hidden key="adresse.id" cssClass="text medium"/>
<s:textfield key="adresse.beskrivelse" required="false" cssClass="text
medium"/>
<s:textfield key="adresse.gatenavn" required="false" cssClass="text
medium"/>
<!-- todo: change this to read the identifier field from the other pojo
-->
<s:select name="adresse.postadresse.id" list="postadresseList"
listKey="id" listValue="postnummer"></s:select>
<li class="buttonBar bottom">
<s:submit cssClass="button" method="save" key="button.save"
theme="simple"/>
<c:if test="${not empty adresse.id}">
<s:submit cssClass="button" method="delete" key="button.delete"
onclick="return confirmDelete('Adresse')" theme="simple"/>
</c:if>
<s:submit cssClass="button" method="cancel" key="button.cancel"
theme="simple"/>
</li>
</s:form>
<script type="text/javascript">
Form.focusFirstElement($("adresseForm"));
</script>
AdresseAction.java
==============
package no.etj.webapp.action;
import java.util.List;
import no.etj.model.Adresse;
import no.etj.model.Postadresse;
import org.appfuse.service.GenericManager;
import org.appfuse.webapp.action.BaseAction;
public class AdresseAction extends BaseAction {
private GenericManager<Adresse, Long> adresseManager;
private GenericManager<Postadresse, Long> postadresseManager;
private List adresses;
private Adresse adresse;
private Long id;
public void setAdresseManager(GenericManager<Adresse, Long>
adresseManager)
{
this.adresseManager = adresseManager;
}
/**
* @param postadresseManager
* the postadresseManager to set
*/
public void setPostadresseManager(
GenericManager<Postadresse, Long> postadresseManager) {
this.postadresseManager = postadresseManager;
}
public List getPostadresseList() {
return postadresseManager.getAll();
}
public List getAdresses() {
return adresses;
}
public String list() {
adresses = adresseManager.getAll();
return SUCCESS;
}
public void setId(Long id) {
this.id = id;
}
public Adresse getAdresse() {
return adresse;
}
public void setAdresse(Adresse adresse) {
this.adresse = adresse;
}
public String delete() {
adresseManager.remove(adresse.getId());
saveMessage(getText("adresse.deleted"));
return SUCCESS;
}
public String edit() {
if (id != null) {
adresse = adresseManager.get(id);
} else {
adresse = new Adresse();
}
return SUCCESS;
}
public String save() throws Exception {
if (cancel != null) {
return "cancel";
}
if (delete != null) {
return delete();
}
boolean isNew = (adresse.getId() == null);
adresseManager.save(adresse);
String key = (isNew) ? "adresse.added" : "adresse.updated";
saveMessage(getText(key));
if (!isNew) {
return INPUT;
} else {
return SUCCESS;
}
}
}
applicationContext.xml:
=================
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- Add new DAOs here -->
<!--PostadresseManager-START-->
<bean id="postadresseManager"
class="org.appfuse.service.impl.GenericManagerImpl">
<constructor-arg>
<bean class="org.appfuse.dao.hibernate.GenericDaoHibernate">
<constructor-arg value="no.etj.model.Postadresse"
index="1"/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</constructor-arg>
</bean>
<!--PostadresseManager-END-->
<!--AdresseManager-START-->
<bean id="adresseManager"
class="org.appfuse.service.impl.GenericManagerImpl">
<constructor-arg>
<bean class="org.appfuse.dao.hibernate.GenericDaoHibernate">
<constructor-arg value="no.etj.model.Adresse" index="1"/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</constructor-arg>
</bean>
<!--AdresseManager-END-->
<!-- Add new Managers here -->
<!--PostadresseAction-START-->
<bean id="postadresseAction"
class="no.etj.webapp.action.PostadresseAction" scope="prototype">
<property name="postadresseManager" ref="postadresseManager"/>
</bean>
<!--PostadresseAction-END-->
<!--AdresseAction-START-->
<bean id="adresseAction" class="no.etj.webapp.action.AdresseAction"
scope="prototype">
<property name="adresseManager" ref="adresseManager"/>
<property name="postadresseManager" ref="postadresseManager"/>
</bean>
<!--AdresseAction-END-->
<!-- Add new Actions here -->
</beans>
--
View this message in context:
http://www.nabble.com/Strange-%40ManyToOne-form-display-problem-%28Struts2%29-tf4330767s2369.html#a12394194
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]