Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1364
  • Last Modified:

Struts Logic:Iterate not returning values from page

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
OMyStuckAgin
Asked:
OMyStuckAgin
  • 7
  • 5
1 Solution
 
OMyStuckAginAuthor Commented:
.ps, yes BaseAction extends Action....I just do some commonly required housekeeping things in it,
0
 
boonlengCommented:
Can you post the jsp file.
0
 
OMyStuckAginAuthor Commented:
which file, BaseAction ?
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
OMyStuckAginAuthor Commented:
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
 
boonlengCommented:
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
 
OMyStuckAginAuthor Commented:
Thanks, I will check this out today and get back.
0
 
OMyStuckAginAuthor Commented:
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
 
boonlengCommented:
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
 
OMyStuckAginAuthor Commented:
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
 
boonlengCommented:
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
 
OMyStuckAginAuthor Commented:
Bingo!!!!   have a great weekend. Thanks for your help AGAIN!!!  
0
 
boonlengCommented:
Glad I could help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now