Solved

Struts - populating a form

Posted on 2006-11-28
3
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 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