Re: Problem wo loop WOHyperlink
Thanks for answering. I learned something new. I'm going to change my code. Hugo On Fri, Jul 13, 2012 at 6:25 PM, Chuck Hill wrote: > > On 2012-07-13, at 2:52 PM, Hugo Cambero wrote: > > > Hi Everybody > > > > I'm Hugo, I've been developing using WebObjects and Wonder Frameworks, > I'm newbie in this topic. > > > > I have a problem and I hope you can help me. I'm developing a test > application, I want to display a list of ERXGenericRecord, but, in the last > column, > > I want to display a picture that can delete the selected row. > > > > Example: > > > > ID NAMELASTNAME USERNAME ACTIONS > > 120 Hugo Perezsun13 delete > > 160 Aaron Anthonyaaron12 delete > > > > If the user clicks the delete picture of the first row, the application > deletes the record 120. > > > > I'm trying to do it using the next code: > > > > > > > > ID > > Name > > Lastname > > Username > > Actions > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- > > DeleteLink : WOHyperlink { > > directActionName="deleteRecord"; > > You don't want a direct action here, change this to (notice no quotes!): > > action = deleteRecord; > > Then in AdminPage.java add this: > > > public WOComponentAction deleteRecord() { > editingContext.deleteObject(entryItem); > editingContext.saveChanges(); // This can throw if the deletion > fails > } > > > You also need the fixes below so the EOEditingContext is not changing all > the time. > > Chuck > > > > > } > > > > DeleteImage : WOImage { > > filename = "css/img/boton/delete.png"; > > mimeType="image/gif"; > > } > > -- > > package your.app.components; > > > > import your.app.model.User; > > import com.webobjects.appserver.WOContext; > > import com.webobjects.foundation.NSArray; > > import er.extensions.components.ERXComponent; > > import er.extensions.eof.ERXEC; > > > > public class AdminPage extends ERXComponent { > > private User entryItem; > > private EOEditingContext editingContext; > > > > > > public AdminPage(WOContext context) { > > super(context); > > editingContext = ERXEC.newEditingContext(); > > > > } > > > > public User entryItem() { > > return entryItem; > > } > > > > public void setEntryItem(User entryItem) { > > this.entryItem = entryItem; > > } > > > > public NSArray allUsers() { > > return User.fetchAllUsers( ERXEC.newEditingContext() ); > > > return User.fetchAllUsers( editingContext ); > > > > } > > } > > > > I think, I can solve this problem, adding a key or data in GET method in > the 'Delete Link', but, I don't know. > > What do you recommend me? > > What is the best way to do this exercise? > > > > Thanks! > > ___ > > Do not post admin requests to the list. They will be ignored. > > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > > Help/Unsubscribe/Update your Subscription: > > > https://lists.apple.com/mailman/options/webobjects-dev/chill%40global-village.net > > > > This email sent to ch...@global-village.net > > -- > Chuck Hill Senior Consultant / VP Development > > Practical WebObjects - for developers who want to increase their overall > knowledge of WebObjects or who are trying to solve specific problems. > http://www.global-village.net/gvc/practical_webobjects > > > > > > > > > ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Problem EOEditingContext
Thanks for your answers, yes I found a method like this: public static User createUser(EOEditingContext editingContext, String maternalName , String name , String password , String paternalName , String username) But I prefer to user the method like this: User newUser = ERXEOControlUtilities.createAndInsertObject(ec, User.class ); On Thu, Jul 12, 2012 at 5:39 PM, Lon Varscsak wrote: > Oh, I like that! > > -Lon > > On Thu, Jul 12, 2012 at 3:26 PM, Maik Musall wrote: > > > > Am 12.07.2012 um 23:58 schrieb Louis Demers: > >> User newUser = (User)EOUtilities.createAndInsertInstance(ec, > User.ENTITY_NAME) ; > > > > Much too wordy for my taste, and needs a cast on top of it. Just add a > second constructor in your template which does ec.insertObject(this), so > that you can simply use > > > > User newUser = new User( ec ); > > > > Do not delete the parameter-less constructor though, because EOF needs > that internally when restoring objects from db. But refrain from using that > anywhere in your app. > > > > Maik > > ___ > > Do not post admin requests to the list. They will be ignored. > > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > > Help/Unsubscribe/Update your Subscription: > > > https://lists.apple.com/mailman/options/webobjects-dev/lon.varscsak%40gmail.com > > > > This email sent to lon.varsc...@gmail.com > ___ > Do not post admin requests to the list. They will be ignored. > Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/webobjects-dev/hhch40%40gmail.com > > This email sent to hhc...@gmail.com > ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Problem EOEditingContext
Thanks for your recommendation Johann Wernet Yes, you are right, I have a problem with my model, I'll change it, and I'll seek about ERXEOControlUtilities Regards On Thu, Jul 12, 2012 at 1:56 PM, Johann Werner wrote: > Hi Hugo, > > welcome to WO! > > Am 12.07.2012 um 20:46 schrieb Hugo Cambero: > > Hi Everybody > > My name is Hugo, I'm from Mexico. I have been developing using WebObjects > and Wonder Frameworks, I'm newbie in this topic. > > Well, I have a problem, I hope you can help me. I'm developing a test > application, I want to learn about EOF. > > I have 2 entities, that I created using EOModel. The first entity is: > User, the second is Role. The relationship between the entities is: One user > can have many Roles. > > Well, I tried to insert a row using the next code: > > EOEditingContext ec = ERXEC.newEditingContext(); > Role userRole = Role.fetchRole( ec, > Role.NAME.eq("user") ); //Get the correct Role to the new user > > User newUser = new User(); > > > don't create EOs that way, use > > ERXEOControlUtilities.createAndInsertObject(ec, User.class); > > newUser.setName( name.toLowerCase() ); > newUser.setPaternalName( paternalName.toLowerCase() ); > newUser.setMaternalName( maternalName.toLowerCase() ); > newUser.setBirthday( new NSTimestamp() ); > newUser.setUsername( username ); > newUser.setPassword( password ); > > newUser.setRole( userRole ); //Set > the role to the user > > > you said that User <-->> Role but setRole() would point to a to-one > relationship. A to-many relationship should give you > > user.addToRoles(role); > user.removeFromRoles(role); > > so there seems to be a problem with your model or with your java classes. > > > ec.insertObject( newUser ); > //Insert object to the EOEditingContext > ec.saveChanges(); > //Commit to the DataBase > > But, the server has the next error: > > java.lang.RuntimeException: You crossed editing context boundaries > attempting to set the 'role' relationship of pk:"null"> (which is not in an editing context) to pk:"2"> (in EC er.extensions.eof.ERXEC@762a5241). > > I understand that the primary key of the user is null, because it's a new > user and I want to insert it to the data base. > > What is the correct way to insert row, when it have a relationship between > the entities? > > Thanks for you time > > > ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com