开发者

logic:iterator not working

I am new to struts please help me to find out the error.my error like value does not parse from data base.while im executing the page some empty value.please find out this mistake. I could not iterate the value.

What i am doing wrong?

My jsp page:

      <%-- 
                Document   : dublicateId
                Created on : Aug 8, 2011, 5:36:20 PM
                Author     : Trainnee
            --%>
            <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
            <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
            <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
            <%@ page import="com.rec.bookbank.persitencejavafile.DuplicateIdObject" %>
            <%@page contentType="text/html" pageEncoding="UTF-8"%>
            <%@ page import="java.util.*;"%>

            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
            <LINK REL="stylesheet" href="<%=request.getContextPath()%>/css/dublicate.css">

            <html>
                <head>

                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                    <title>JSP Page</title>
                </head>
                  <body>
                      <html:form  action="/id" ></html:form>

                        <div id="container">
                            <div id="header">
                                <table width="960">
                                      <tr>
                                        <td id="header1"  align="center">
                                            DUBLICATE ID CARD REQUEST 
                                        </td><td><a href="/REC_BookBank/jsp/exisitingUser.jsp">Back</a></td>
                                    </tr>
                                </table>    

                            </div>
                            <div id="content">

                            <table cellpadding="10" align="center">


                                 <tr><td>Reason For Requesting Dublicate ID:</td>
                                    <tr><td>
                                    </td><td>
                                        <logic:iterate id="duplicate" name="duplicate" type="com.rec.bookbank.persitencejavafile.DuplicateIdObject">
                                        <html:select property="reason" name="duplicate">
                                        <html:option value='<bean:write property="duplicate" name="reason"/>'/>
                                        </html:select>

                                  </td>                        
                                     <tr>
                                         <tr><td>Mode of dispatch </td>
                                    <tr><td>
                                    </td><td>

                                        <html:select property="reason" name="duplicate">
                                        <html:option value='<bean:write property="duplicate" name="reason"/>'/>
                                        </html:select>
                                 </logic:iterate>            
                                  </td>                        
                                     <tr>
                                      <td>
                                           Conformation Of Mailing Address:      
                                      </td>
                                      <td>

                                      </td>
                                    </tr>
                                    <tr>
                                        <td><font size="3"id="header1">Charges Applicable</font></td>
                                    </tr>
                                    <tr><td>Components  </td><td>Amount IN INR</td></tr>
                                    <tr><td>Dublicate Card Charges</td><td><html:text property="cardcharges" value=""/></td>
                                    </tr>
                                    <tr>
                                        <td>Courier Charges                   
                                        </td><td>
                                   </td>
                                    </tr>
                                    <tr>
                                        <td>Grant Total</td><td>></td>  
                                    </tr>
                                    <tr><td><html:submit property="submit" value="paynow" /></td><td><html:button property="" value="Later"/></td></tr>
                                </table>
                            </div>
                        </div>
                </body>
            </html>

MY dao:

     package com.rec.bookbank.dao;
            import com.rec.bookbank.form.DuplicateIdForm;
            import com.rec.bookbank.sessionCfg.HibernateUtil;
            import java.util.ArrayList;
            import java.util.List;
            import org.hibernate.Session;
            import org.hibernate.Query;
            import com.rec.bookbank.persitencejavafile.DuplicateIdObject;

            public class DuplicateIdDAO
            {

                public static  List duplicateidrequest()
                {
                    Session session=null;
                       try
                       {
                        List  duplicate=new ArrayList();

                        session = HibernateUtil.getSession();
                        System.out.println(" Session :: "+session);
                        Query query=session.createSQLQuery("{call SP_Duplicate()}");
                        duplicate  = getList(query.list());
                        System.out.println("in dao getduplicate----"+duplicate);
                        if(duplicate!=null)
                        return duplicate;
                        else
                            return new ArrayList();
                       }
                       catch(Exception e)
                       {
                           System.out.println("Exception in duplicateidrequest::"+e);
                           return  null;
                       }
                       finally
                       {
                           session.close();
                       }          
                      }     

                public static  List<DuplicateIdObject> getList ( List<Object[]>duplicate )
                {
                System.out.println("in convertor");
                List<DuplicateIdObject>duplicateobjectlist = new ArrayList<DuplicateIdObject>();
                for(Object[] array:duplicate)
                {
                    System.out.println("value in method::"+duplicate.size());
                    DuplicateIdObject duplicateIdObject=new DuplicateIdObject();


                           duplicateIdObject.setReason(array[0].开发者_运维问答toString());
                           duplicateIdObject.setReason(array[1].toString());
                           duplicateobjectlist.add(duplicateIdObject);

                }
                return duplicateobjectlist;
                }
            } 

My persistence class:

 /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */

    package com.rec.bookbank.persitencejavafile;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import java.io.Serializable;

    /**
     *
     * @author Trainnee
     */
    @Entity
    public class DuplicateIdObject implements Serializable
    {
        @Id
    private int id;
    private String reason;
    private String dispatch;
    private String address;
    private String cardcharges;
    private String couriercharges;
    private String total;

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getCardcharges() {
            return cardcharges;
        }

        public void setCardcharges(String cardcharges) {
            this.cardcharges = cardcharges;
        }

        public String getCouriercharges() {
            return couriercharges;
        }

        public void setCouriercharges(String couriercharges) {
            this.couriercharges = couriercharges;
        }

        public String getDispatch() {
            return dispatch;
        }

        public void setDispatch(String dispatch) {
            this.dispatch = dispatch;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getReason() {
            return reason;
        }

        public void setReason(String reason) {
            this.reason = reason;
        }

        public String getTotal() {
            return total;
        }

        public void setTotal(String total) {
            this.total = total;
        }


    }

My Action class:

package com.rec.bookbank.action;
import com.rec.bookbank.form.DuplicateIdForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import com.rec.bookbank.Constants.Constants;
import com.rec.bookbank.persitencejavafile.DuplicateIdObject;

import com.rec.bookbank.dao.DuplicateIdDAO;
import java.util.List;
import java.util.ArrayList;

public class DuplicateIdAction extends org.apache.struts.action.Action {



        public ActionForward execute(ActionMapping mapping, ActionForm  form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        DuplicateIdForm duplicateIdForm=(DuplicateIdForm)form;
        List<DuplicateIdObject> convert=new ArrayList<DuplicateIdObject>();
        convert=DuplicateIdDAO.duplicateidrequest();
        System.out.println("list in action::" +convert.size());
        request.setAttribute("duplicate", convert);
        System.out.print("request in Action::"+request.getAttribute("duplicate"));


        return mapping.findForward(Constants.ACTION_FORWARD_SUCCESS);
  }
}


At first look, I found that You have made following mistake in your code

  1. You can not embed one Struts tag into another (as you did in html:option ). Instead use html:options or html:optionsCollection whatever you feel is good. I recommend html:options since it is very much similar to what you want to do.

This may solve your problem.

Edited - Note: You do not need to implement logic:iterate for taking options of the select.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜