Solved

Struts - populating a form

Posted on 2006-11-28
3
388 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A Short Story about the Best File Recovery Software – Acronis True Image 2017
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now