After reading Freddy's book, I'm diving into writing my first
(super-simple) app. And though I /think/ I'm headed in the right
direction, I needs some guidance to show me:
a) What am I doing wrong and?
b) What should I be doing better/different?
The app is a single page that takes a users's e-mail address and persists
it to the database. I've brought up the DB gui, and can see my Person
table exists.
I've used quickstart to get the base structure of the app up and running.
On submission of my form, I get the following:
net.sourceforge.stripes.exception.StripesServletException: Unhandled
exception in exception handler.
net.sourceforge.stripes.exception.DefaultExceptionHandler.handle(DefaultExceptionHandler.java:158)
net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:249)
root cause
java.lang.IllegalArgumentException: attempt to create create event with
null entity
I suspect this is because when I save the form, I'm never applying the
saved address to the person object in the action, but I'm confused as to
what I should be doing in the action and would like some pointers.
Guidance and suggestions would be much appreciated!
TIA!
JSP:
home.jsp (partial):
...
<s:form
beanclass="org.stripesbook.quickstart.action.HomeActionBean">
<s:errors/>
<s:text name="person.email" class="required" />
<s:submit name="save" value="Submit" />
</s:form>
...
Models:
model/ModelBase.java:
@MappedSuperclass
public abstract class ModelBase {
@Id
@GeneratedValue
private Integer id;
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
@Override
public boolean equals(Object obj) {
try { return id.equals(((ModelBase) obj).getId()); }
catch (Exception exc) { return false; }
}
@Override
public int hashCode() {
return 31 + ((id == null) ? 0 : id.hashCode());
}
}
model/Person.java:
@Entity
public class Person extends ModelBase {
private String email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
Actions:
action/BaseActionBean.java:
public class BaseActionBean implements ActionBean {
private ActionBeanContext context;
public ActionBeanContext getContext() {
return context;
}
public void setContext(ActionBeanContext context) {
this.context = context;
}
}
action/HomeActionBean.java:
@UrlBinding("/Home.action")
public class HomeActionBean extends BaseActionBean {
private static final String HOME = "/WEB-INF/jsp/home.jsp";
private Person person;
@DefaultHandler
public Resolution view() {
return new ForwardResolution(HOME);
}
@ValidateNestedProperties ({
@Validate(field="email", required=true, on="save",
converter=EmailTypeConverter.class)
})
public Resolution save() {
EntityManager em = Stripersist.getEntityManager();
em.persist(person);
getContext().getMessages().add(
new SimpleMessage("{0} has been saved.", person)
);
return new RedirectResolution("http://www.google.com");
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
}
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users