Solved

Struts Logic:Iterate not returning values from page

Posted on 2006-06-27
12
1,302 Views
Last Modified: 2010-05-18
I have a Struts application under development (V 1.2.7) and I am using the Struts html:Logic iterate tag on a few of the forms to process tabular data. I have implemented separate action mappingss  to both open and save the data. The open works exactly as I expect. It rerieves data from a DAO object and sets it to the attribute aa descibed in the formbean.(actually I am using dynaformbeans with Tiles, although I don't think that either is the issue) Here is an example of one table based maaping and bean I coded,

<form-bean name="signatureFlowForm"  type="org.apache.struts.action.DynaActionForm">
<form-property name="id" type="java.lang.String" />      
<form-property name="number" type="java.lang.String" />
<form-property name="description" type="java.lang.String" />      
<form-property name="approvers" type="com.engineering.readiness.beans.Approver[]" />            
</form-bean>      

<action path="/openSignatureFlow"
      type="com.pweh.engtech.readiness.actions.ActionSignatureFlowOpen"
      name="signatureFlowForm"
      scope="session">
      <forward name="success" path="display.edit.signature.form" />
</action>
                                    
<action path="/saveSignatureFlow"
      type="com.pweh.engtech.readiness.actions.ActionSignatureFlowSave"
      name="signatureFlowForm"
      scope="session">
      <forward name="success" path="/common-ui/confirmation-save.jsp" />
</action>
 

public class ActionSignatureFlowOpen extends BaseAction {

      public ActionForward execute(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) {                  

            HttpSession session = request.getSession();
            DataSource ds = null;
            String env = this.getDatasource_Environment();

            ds = (DataSource) getDataSource(request, env);
            
            Collection c = new ArrayList();
            

            try {
                  //      Generate the complete list of approvers or approver roles
                  c = ApproverDAO.buildCollection(key);
            } catch (SQLException sqle) {
                  logger.error("Exception thrown in class " + this.getClass().getName().toUpperCase()
                              + ": "       + sqle.getLocalizedMessage());
            }

            Approver[] approvers = (Approver[]) c.toArray(new Approver[0]);

            // Retrieve the selections
            DynaActionForm f = (DynaActionForm) form;
                                                      
            f.set("requiredapprovers", approvers );            

            return (mapping.findForward("success"));

      }


public final class ActionSignatureFlowSave extends BaseAction {

      public ActionForward execute(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, ServletException {
            HttpSession session = request.getSession();

            Approver[] approvers;

            DynaActionForm view = (DynaActionForm) form;

            DataSource ds = null;

            String env = this.getDatasource_Environment();

            ds = (DataSource) getDataSource(request, env);

            approvers = transferDataFromView(view);

            showme(approvers);

            return mapping.findForward("success");
      }

      private void showme(Approver[] approvers) {
            for (int j = 0; j < approvers.length; j++) {
                  Approver approver = approvers[j];
                  System.out.print("\nApprover: " + approver.toString());
            }

      }

      private Approver[] transferDataFromView(DynaActionForm view) {
            Approver[] required = (Approver[]) view.get("requiredapprovers");
            showme(required);      
            return required;
      }

why am I able to send data to the page(tile) but not rerieve it ? I have spent a couple of days on this already and read a few articles, but nothing jumps out at me as being incorrect. Can anyone help me?
0
Comment
Question by:OMyStuckAgin
  • 7
  • 5
12 Comments
 

Author Comment

by:OMyStuckAgin
ID: 16997880
.ps, yes BaseAction extends Action....I just do some commonly required housekeeping things in it,
0
 
LVL 14

Expert Comment

by:boonleng
ID: 17000971
Can you post the jsp file.
0
 

Author Comment

by:OMyStuckAgin
ID: 17003853
which file, BaseAction ?
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:OMyStuckAgin
ID: 17008091
sorry, I misread your previous comment, my bad...here is the important portion of the jsp


<logic:iterate id="required" name="signatureFlowForm" property="requiredapprovers"      scope="session">
<tr>
<td nowrap="nowrap" align="left" style="WIDTH: 200px"
      height="30"><bean:write name="required"
      property="disciplineTitle" /></td>
<td align="center" width="10%"><img src="../images/ic_ok.gif"
      border="0" /></td>
<td colspan="3">&nbsp;</td>
      <bean:define id="approver">
      <bean:write name="required" property="disciplineTitleID" />                              </bean:define>
                                                            
<td nowrap="nowrap" valign="bottom">
      <html:text name="required" property="approverClockID" style="WIDTH: 0px" styleId='<%="id"+approver%>'/>
      <html:text name="required" property="approverEMail" style="WIDTH: 0px" styleId='<%    ="email"+approver%>'/>
      <html:text name="required" property="approverName" style="WIDTH: 200px" maxlength="50"
      styleId="<%=approver%>" />                                          
                                                            <a      href='javascript:flagDirty(); javascript:getValue("<%=approver%>" , "<%="id"+approver%>",
                "<%="email"+approver%>"  )'><img alt="Global Address List" src="../images/book14.gif"
                                                                  border="0" align="top" /></a></td>
</tr>
</logic:iterate>
let me know if I there is anything else I can do. I appreciate the help.
0
 
LVL 14

Expert Comment

by:boonleng
ID: 17009221
You are declaring a bean com.engineering.readiness.beans.Approver as the form property, so you need to use <nested> tag in order to save the value back to the bean.
Example:
<nested:text property="requiredapprovers.approverClockID"/>
or
<nested:iterate name="signatureFlowForm" property="requiredapprovers" scope="session">
    <nested:write property="disciplineTitle" />
    <nested:text property="approverClockID"/>
</nested:iterate>

Your can refer to this tutorial on how to use nested tag.
http://www.laliluna.de/struts-nested-iteration-tutorial.html
0
 

Author Comment

by:OMyStuckAgin
ID: 17016800
Thanks, I will check this out today and get back.
0
 

Author Comment

by:OMyStuckAgin
ID: 17016966
I got this.....

Error 500: ServletException in '/pages/edit-SignatureFlow.jsp': No getter method for property requiredapprovers.approverClockID of bean signatureFlowForm

here is the portion of the Approver bean.....

public class Approver {

      private int approverId;
      private int tpdID;
      private String disciplineTitleID;
      private String disciplineTitle;
      private String approverClockID;
      private String approverName;
      private String approverEMail;
      private String required;
      private String notified;
      private String signOff;
      private String roleRequired;
      private String roleNotified;
      private String roleSelectable;
      private Date dateSigned;
      private int itemOrder;
      private String revisedBy;

      public Approver() {
            /**
             * Business Rule: All process owners are selectable unless otherwise designated as either
             * 'required' or 'notified' by means of the role that they hold for the given technology.
             */
            this.setRoleSelectable("Y");
      }

                public String getApproverClockID() {
            return approverClockID;
      }

      public void setApproverClockID(String value) {
            approverClockID = value;
      }

is this error message complaining about the bean definition shown here or the form bean definition given earlier which describes a collection of beans ( <form-property name="approvers" type="com.engineering.readiness.beans.Approver[]" />  ) but not their individual properties ?
0
 
LVL 14

Expert Comment

by:boonleng
ID: 17017260
Sorry, I think i confused you.
Actually if the form property is a single bean, you can use the following.
    <nested:text property="requiredapprovers.approverClockID"/>

If is a collection, then need to iterate it.
    <nested:iterate name="signatureFlowForm" property="requiredapprovers" scope="session">
        <nested:write property="disciplineTitle" />
        <nested:text property="approverClockID"/>
    </nested:iterate>
0
 

Author Comment

by:OMyStuckAgin
ID: 17017696
Now I get  

Error 500: ServletException in '/pages/edit-SignatureFlow.jsp': No getter method for property requiredapprovers[0].requiredapprovers.approverClockID of bean signatureFlowForm


by the way here is how my jsp looks now( just to make sure I coded what you explained previously).

      <nested:iterate name="signatureFlowForm" property="requiredapprovers"
                                          scope="session">
      <tr>
      <td nowrap="nowrap" align="left" style="WIDTH: 200px" height="30">
            <nested:write property="disciplineTitle" /></td>
      <td align="center" width="10%"><img src="../images/ic_ok.gif" border="0" /></td>
                                                            <bean:define id="approver"> <nested:write property="disciplineTitleID" /></bean:define>
                                                            
       <nested:text property="requiredapprovers.approverClockID" style="WIDTH: 0px"
                              styleId='<%="id"+approver%>'/>  
                                                            <nested:text property="requiredapprovers.approverEMail" style="WIDTH: 0px"
                              styleId='<%="email"+approver%>'/>
                                                            <nested:text property="requiredapprovers.approverName" style="WIDTH: 0px"
                              styleId="<%=approver%>"/>
                                    
      <a      href='javascript:flagDirty(); javascript:getValue("<%=approver%>" , "<%="id"+approver%>", "<%="email"+approver%>"  )'>
      <img alt="UTC Global Address List" src="../images/book14.gif" border="0" align="top" /></a></td>

      </tr>
      </nested:iterate>
0
 
LVL 14

Accepted Solution

by:
boonleng earned 500 total points
ID: 17023673
Coz the bean "requiredapprovers" is inside the collection. So you dont need to specify the bean name again inside the <nested:iterate>, all the <nested> tag inside the loop will automatically refer to the bean.

Example:
    <nested:text property="approverClockID" style="WIDTH: 0px" styleId='<%="id"+approver%>'/>  
0
 

Author Comment

by:OMyStuckAgin
ID: 17024133
Bingo!!!!   have a great weekend. Thanks for your help AGAIN!!!  
0
 
LVL 14

Expert Comment

by:boonleng
ID: 17025574
Glad I could help :)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

830 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