Solved

Struts - populating a form

Posted on 2006-11-28
3
391 Views
Last Modified: 2008-01-09
I am having this strange problem with Struts, using JDeveloper 10.1.3.

I've seen it working properly elsewhere, so I can't explain what it's not working on my project.

I want to display an <edit> form. So my action is passing a struts form with all the data. I'm println()'ing, so I know that the data is there. The action ends normally with

request.setAttribute("updateSupplierForm", aForm);

and the JSP page contains

<html:form action="/updateSupplier">
       <br/>a<html:text maxlength="120" size="50" property="firm" />
       <br/>a<html:text maxlength="120" size="50" property="address1" />
      ..........

(where updateSupplier is properly defined in struts-config)

**I am expecting those form fields to display the existing data, from the struts form.**
I know that this works (definately with struts 1.2). I have tried 1.1 and 1.3 and the fields are always empty. I cannot believe that it's a version problem. So now I need to put some JSP in the field tag to display the data:

    <br/>a<html:text maxlength="120" size="50" property="firm" value="<%=aForm.getFirm()%>"/>

Any ideas? Why my form is not automatically populated as it should?
   
0
Comment
Question by:piou
  • 2
3 Comments
 
LVL 14

Expert Comment

by:boonleng
ID: 18033427
Can you post the struts-config.xml.
0
 

Author Comment

by:piou
ID: 18043403
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">

<struts-config>
 
  <form-beans>
    <form-bean name="addStatusForm" type="project1.forms.AddStatusForm"/>
    <form-bean name="addAssetTypesForm" type="project1.forms.AddAssetTypesForm"/>
    <form-bean name="editSupplierForm" type="project1.forms.EditSupplierForm"/>
    <form-bean name="viewSupplierForm" type="project1.forms.ViewSupplierForm"/>
    <form-bean name="updateSupplierForm" type="project1.forms.UpdateSupplierForm"/>
  </form-beans>
 
  <action-mappings>
    <action path="/home" type="project1.actions.HomeAction">
      <forward name="success" path="home.page"/>
    </action>
    <action path="/getStatus" type="project1.actions.GetStatusAction">
      <forward name="success" path="/WEB-INF/jsp/status.jsp"/>
    </action>
    <action path="/editStatus" type="project1.actions.EditStatusAction">
      <forward name="success" path="/getStatus.do?edit=success" redirect="true" />
    </action>
    <action path="/removeStatus" type="project1.actions.RemoveStatusAction">
      <forward name="success" path="/getStatus.do?remove=success" redirect="true" />
    </action>
    <action path="/addStatus" type="project1.actions.AddStatusAction" name="addStatusForm" validate="true" input="/getStatus.do">
      <forward name="success" path="/getStatus.do?add=success" redirect="true" />
    </action>
    <action path="/getAssetTypes" type="project1.actions.GetAssetTypesAction">
      <forward name="success" path="/WEB-INF/jsp/assetTypes.jsp"/>
    </action>
    <action path="/editAssetTypes" type="project1.actions.EditAssetTypesAction">
      <forward name="success" path="/getAssetTypes.do?edit=success" redirect="true" />
    </action>
    <action path="/addAssetTypes" type="project1.actions.AddAssetTypesAction" name="addAssetTypesForm" validate="true" input="/getAssetTypes.do">
      <forward name="success" path="/getAssetTypes.do?add=success" redirect="true" />
    </action>
    <action path="/removeAssetTypes" type="project1.actions.RemoveAssetTypesAction">
      <forward name="success" path="/getAssetTypes.do"/>
    </action>
    <action path="/getSuppliers" type="project1.actions.GetSuppliersAction">
      <forward name="success" path="/WEB-INF/jsp/suppliers.jsp"/>
    </action>
    <action path="/viewSupplier" type="project1.actions.ViewSupplierAction" name="viewSupplierForm" >
      <forward name="success" path="/WEB-INF/jsp/viewSupplier.jsp"/>
      <forward name="error" path="/WEB-INF/jsp/common/error.jsp"/>
    </action>
    <action path="/editSupplier" type="project1.actions.EditSupplierAction" name="editSupplierForm">
      <forward name="success" path="/WEB-INF/jsp/editSupplier.jsp"/>
      <forward name="error" path="/WEB-INF/jsp/common/error.jsp"/>
    </action>
    <action path="/updateSupplier" type="project1.actions.UpdateSupplierAction" name="updateSupplierForm">
      <forward name="success" path="/viewSupplier.do?suppguid="/>
    </action>
    <action path="/removeSupplier" type="project1.actions.RemoveSupplierAction" name="editSupplierForm">
      <forward name="success" path="/getSuppliers.do" redirect="true"/>
    </action>
    <action path="/addSupplier" type="project1.actions.AddSupplierAction" name="updateSupplierForm" validate="true"
            input="/WEB-INF/jsp/addSupplier.jsp">
      <forward name="create" path="/viewSupplier.do?suppguid="/>
      <forward name="prepare" path="/WEB-INF/jsp/addSupplier.jsp"/>
      <forward name="error" path="/WEB-INF/jsp/common/error.jsp"/>
    </action>
  </action-mappings>

  <message-resources parameter="project1.ApplicationResources" />
 
  <plug-in className="org.apache.struts.tiles.TilesPlugin">
    <set-property property="definitions-config"
                 value="/WEB-INF/tiles-defs.xml"/>
  </plug-in>
 
</struts-config>
0
 
LVL 14

Accepted Solution

by:
boonleng earned 125 total points
ID: 18053152
You are storing the bean into HTTPRequest attribute.
>>  request.setAttribute("updateSupplierForm", aForm);

But the struts-config didn't specify the scope for the action, by default it will use "session".
So it unable to lookup the value for the property.
>>  <action path="/updateSupplier" type="project1.actions.UpdateSupplierAction" name="updateSupplierForm">

Try specify the scope to "request" or store the bean to HTTPSession.
Example:
<action path="/updateSupplier"
            type="project1.actions.UpdateSupplierAction"
            name="updateSupplierForm"
            scope="request">
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Display current date,month,and year to JTextField 3 47
unit test DAO layer 1 134
build fail in maven project 11 179
maven project jars 7 50
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now