Then, when the JSP renders, the html:form tag uses its action attribute to look up the ActionMapping for the submission ("/categoryEdit"). This ActionMapping specifies that its form bean should be stored under the attribute name "val_categoryEdit". There is nothing in the request under that name, so Struts creates a new form, which is not initialized, and uses it for prepopulating form field values.
Again, if you do not specify an "attribute" in an <action> element, the value defaults to the form's name (as specified in the <action>'s "name" attribute). I have never had a reason to specify "attribute" in the <action> element, but if you do, you need it to be consistent between the actions that are cooperating.
Hope this helps, Joe
At 4:19 PM +0700 1/12/05, Dody Rachmat Wicaksono wrote:
I'm trying to create an edit page. I think I already in the right direction, but still unable to populate data even with a direct value via action class. Please let me what's wrong here. I've spend 3 days alone with this problem.
Thank you.
I created two action file:
- SetUpCategoryEditAction.java (this action will populate data from db to form)
- CategoryEditAction.java (this action will save the data)
My formbean: CategoryEditForm.java
----------------------
public class CategoryEditForm extends ValidatorForm { private String name;
private String categoryId;
public void setName(String s) {
this.name = s;
}
public String getName() {
return name;
} public void setcategoryId(String s) {
this.categoryId = s;
}
public String getcategoryId() {
return categoryId;
}
}
My struts-config.xml
----------------------
<form-bean name="categoryEditForm" type="com.strutsgen.garuda.CategoryEditForm"/>
<action path="/setUpCategoryEditForm" type="com.strutsgen.garuda.SetUpCategoryEditAction" name="categoryEditForm" scope="request" validate="false" > <forward name="continue" path="/categoryEditForm.jsp"/> </action>
<action path="/categoryEdit" type="com.strutsgen.garuda.CategoryEditAction" name="categoryEditForm" attribute="val_categoryEdit" scope="request" validate="true" input="/categoryEditForm.jsp" > <forward name="success" path="/categoryEditOk.jsp"/> </action>
SetUpCategoryEditAction.java: ---------------------- public final class SetUpCategoryEditAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
CategoryEditForm categoryEditForm = (CategoryEditForm)form; categoryEditForm.setName("testing");
return (mapping.findForward("continue")); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "Narrow minds are weapons made for mass destruction" -The Ex
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]