?
Solved

Struts - populating a form

Posted on 2006-11-28
3
Medium Priority
?
423 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

752 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