Actually, that's incorrect. I want to *read* from the Role bean. I want to *write* to the form bean. I just don't know how to go about it yet. :) It seems like I have to read/write to the same form bean, which doesn't make sense, because I don't have the form bean until I get to the JSP page, so there's no way to initialize it.
Thanks for the help, Anthony Frasso --- Puneet Lakhina <[EMAIL PROTECTED]> wrote: > On 8/30/06, Anthony N. Frasso <[EMAIL PROTECTED]> > wrote: > > > > Hello all, > > > > public class Role { > > > > private int id; > > private String name; > > private String description; > > > > private boolean permissionA; > > private boolean permissionB; > > ... > > private boolean permissionN; > > } > > > > Each of those properties has getter and setter > > methods. By the way, in the *actual* Role class, > the > > permission booleans are named such things as > > "canAccessProjects" and "canEditCustomers" and > other > > such actual permissions, which is why I am not > using > > an array of booleans in this case. I want to > refer to > > them by name. > > > > Now I wanted to create a JSP that contained a > form, > > that allowed a user to edit a role. Here is the > > definition of my form bean (called EditRoleForm): > > > > public class EditRoleForm extends ActionForm { > > > > private boolean roleId; > > private boolean roleName; > > private boolean roleDescription; > > > > private boolean rolePermissionA; > > private boolean rolePermissionB; > > ... > > private boolean rolePermissionN; > > } > > > I kinda dont understand why do you need 2 beans as > long as u only care about > reading from them. > you could have somehting like this in your form > bean > public class EditRoleForm extends ActionForm { > Role role = new Role(); > /*getter method*/ > } > and then in your jsp you have > > <html:text property="role.name" /> > > Permission A: <html:checkbox > property="role.permissionA" /> > > you dont need to specify a value explicitly, it > loads the field with > whatever value the property has. > > In this instance, the form bean looks quite similar > to > > the role bean. > > > > In my JSP, I have the following: > > > > <html:form action="/EditRole" method="POST"> > > <table> > > <tr> > > <td>Name:</td> > > <td><html:text property="name" > > value="${role.name}" /></td> > > </tr> > > <tr> > > <td>Description:</td> > > <td><html:textarea > property="roleDescription" > > > value="${role.description}" > > /></td> > > </tr> > > <tr> > > <td>Permission A:</td> > > <td><html:checkbox > property="rolePermissionA" > > value="true" /></td> > > </tr> > > <tr> > > <td>Permission B:</td> > > <td><html:checkbox > property="rolePermissionB" > > value="true" /></td> > > </tr> > > ... > > <tr> > > <td>Permission N:</td> > > <td><html:checkbox > property="rolePermissionN" > > value="true" /></td> > > </tr> > > <tr> > > <td></td> > > <td><html:submit value="Submit" /></td> > > </table> > > </html:form> > > > > As you can see, all of the checkboxes are going to > be > > initialized blank. I would instead prefer them to > be > > initialized with the value in the role within the > > request scope. I was able to do this using the > > "value" parameter in the text and textarea tags, > but > > the value parameter is used differently for the > > checkbox tag. > > > > I hope this clears it up. > > > > One final note: After reading everyone's > responses, > > and also reading around on the web, I seem to be > > getting an idea that the name of the property in > the > > Role bean and the Form bean should be identical, > and > > this is the way it is able to initialize the value > in > > the checkbox, and also set the correct value in > the > > form bean when it is submitted. This seems like a > bad > > idea. For one, how do we know that there is a > > one-to-one mapping of beans to form beans? If I'm > > modifying a few beans all on the same JSP page, I > > certainly don't want there to be confusion. > > > > I hope I've made myself clear, and I look forward > to > > everyone's response. I really appreciate the time > and > > effort everyone has taken in helping me out thus > far. > > > > Regards, > > Anthony Frasso > > > > __________________________________________________ > > Do You Yahoo!? > > Tired of spam? Yahoo! Mail has the best spam > protection around > > http://mail.yahoo.com > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: > [EMAIL PROTECTED] > > For additional commands, e-mail: > [EMAIL PROTECTED] > > > > > > > -- > Puneet > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]