struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rick Reumann" <rick.reum...@gmail.com>
Subject Re: How to do a collection form of beans ???
Date Thu, 27 Sep 2007 02:15:37 GMT
On 9/26/07, A. Lotfi <majidnakit@yahoo.com> wrote:
>
>   Hi, I just want to get a collection of rows from a database and put them in a form.

http://www.learntechnology.net/content/struts/struts_nested.jsp

(and it's not a good idea to call your data access layer from your
action. I've given you some examples how to call that layer in
response to some of your other e-mails to the list.)


------------
>
>   I created a simple bean Vote.java
>   public class Vote {
> protected String ticketid;
> protected String title;
> protected String vote;
>   public void setTicketid(String tid) {
> this.ticketid = tid;
> }
> public String getTicketid() {
> return ticketid;
> }
> public void setTitle(String title) {
> this.title = title;
> }
> public String getTitle() {
> return title;
> }
> public void setVote(String priority) {
> this.vote = vote;
> }
> public String getVote() {
> return this.vote;
> }
> }
>
>   _____________________________________________________
>   and the Action ,
>   ______________________________________________________
>   public ComplianceAction() {
>         System.out.println("Compliance Action");
>     }
>     public ActionForward execute(ActionMapping mapping, ActionForm form,
>     HttpServletRequest request, HttpServletResponse response) throws Exception{
>
>                      ArrayList votes = getVotes(); ???
>                     return mapping.findForward("success");
>
>
>     }
>
>    protected ArrayList getVotes() {
>     Vote  vote = null;
>     ArrayList votes = new ArrayList();
>      Statement stmt = null;
>      ConnectionDb condb = null;
>
>      try {
>             condb = new ConnectionDb();
>              Connection con = condb.getConnection ();
>             stmt = con.createStatement();
>             ResultSet rs = stmt.executeQuery("select v.TICKET_ID, t.TITLE, v.VOTE"
>                                    + " from cons_voting_det v, pt7bt_ticket t"
>                                    + " where v.COEUS_RELEASE = '4.4' and "
>                                    + " v.SUB_COMM = 'Compliance' and"
>                                    + " v.USER_ID = 'majid' and"
>                                    + " v.TICKET_ID = t.TICKET_ID order by v.TICKET_ID;"
);
>    while ( rs.next() ) {
> vote = new Vote();
> vote.setTicketid(rs.getString("TICKET_ID"));
> vote.setTitle(rs.getString("TITLE"));
> vote. setVote(rs.getString("VOTE"));
> votes.add(vote);
> System.err.println("TICKET_ID : "
> + vote.getTicketid()
> + "TITLE :" + rs.getString("TITLE"));
> }
> } catch ( SQLException se ) {
>             se.printStackTrace();
>         } catch ( Exception e ) {
>             e.printStackTrace();
>         }
>         finally {
>             try {
>                 stmt.close();
>                 condb.releaseConnection();
>
>             } catch ( Exception e ) { }
>         }
>        return votes;
>    }
>
> }
>
>
>   I read but get confused, that I have to create a dynaform that will be a collection
of beans (Vote.java) ...///
>
>   How I am gonna do it in my Action class instead of returning ArrahList ?
>
>   Thanks, your help is appreciated.
>
>
>
> ---------------------------------
> Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos
& more.


-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message