Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Struts - populating a form

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

609 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