[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Struts Logic:Iterate not returning values from page

Posted on 2006-06-27
12
Medium Priority
?
1,336 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
[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
  • 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

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 2000 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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

656 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