-
1. Re: Newbie question, how to create new item
dhinojosa Jan 4, 2009 1:13 AM (in response to philip142au.philip_andrew.hotmail.com)If I understand your question right, what typically is done, is you map two different entity components. One that is to be a new entity (used for creation) and a managed entity (used to update, and delete). Take a look at the framework section of the documentation for an example.
-
2. Re: Newbie question, how to create new item
joblini Jan 4, 2009 1:40 AM (in response to philip142au.philip_andrew.hotmail.com)Since you used SeamGen, you have an EntityHome to manage the instance. The getInstance method will, if the id has been set, query the database and return a
managed
instance. If the id has not been set, a new instance, which can subsquently be persisted, will be returned. The isManaged method can be used to distinguish these cases.Getting back to your original question, the edit page will cover both of these cases, calling update if the instance is managed, and persist if if is not.
It would seem that in your case you are passing the id of an existing instance, so you are in update mode. If you ensure that no id is passed in your link, you should go into the mode you desire, allowing you to create a new instance.
-
3. Re: Newbie question, how to create new item
joblini Jan 4, 2009 1:45 AM (in response to philip142au.philip_andrew.hotmail.com)Referring to the code produced by SeamGen, look at ArtGroupEdit.page.xml, as well as the
rendered
attribute of the buttons on the ArtGroupEdit.xhtml page. -
4. Re: Newbie question, how to create new item
philip142au.philip_andrew.hotmail.com Jan 4, 2009 4:18 AM (in response to philip142au.philip_andrew.hotmail.com)Hi,
I tried to clear the seam component.
@Begin(join=true)
public String itemSelectedNew(String name, String actionResult, String seamComponent) {
// Clear seam component
EntityHome e1 = (EntityHome) Component.getInstance(seamComponent, true);
e1.clearInstance();
// Return page to go to
return this.itemSelected(name, actionResult);
}
Is this right?
Not seem to work in one case and work in another case...
Philip -
5. Re: Newbie question, how to create new item
joblini Jan 4, 2009 4:55 AM (in response to philip142au.philip_andrew.hotmail.com)Set the id to null, subsequent call to getInstance will return a new instance.
If your entity is Foo, it would be
e1.setFooId(null); e1.wire();
Assuming that your EntityHome was produced by SeamGen.