-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: filling html-options with hibernate and struts
PostPosted: Mon Jun 21, 2004 5:59 am 
Newbie

Joined: Wed Jun 16, 2004 8:26 am
Posts: 19
i've integrated hibernate in struts with hibernate.plugin successfully.

now i want to create a html-form to writing data into the database.

for that i want to fill some data from the database into a html-select box.

how can i do that?

- for using the html:select and html:options tag i must create the appropriate java-bean out of the database.

- can i use the session.load method without giving an identifier or what can i do?

does somebody knows an example for displaying / manipulating hibernate data in a web-application using jakarta-struts?

thanks in advance.

_________________
Have Fun!

Torsten


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 9:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The Middlegen example (CVS version) has an example application that has generated struts pages and used EJB for a backend but now uses hibernate. We have also a new plugin (used in this example) called hibernate-adapter that acts as a bridge. This might be helpful. Aside from this there are a number of examples application some use struts - see the appropriate wiki section.


Top
 Profile  
 
 Post subject: return types of query-methods from hibernate-session
PostPosted: Tue Jun 22, 2004 2:13 am 
Newbie

Joined: Wed Jun 16, 2004 8:26 am
Posts: 19
Thank for your reply.


Another Question concerning the api-docs.

for further work with the data returned form the different hibernate session-methods:

what is exactly the return type of the methods session.get / - find and -iterate ?


i need this for handling the data retrieved from the methods above.

_________________
Have Fun!

Torsten


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 07, 2004 3:24 am 
Newbie

Joined: Wed Jun 16, 2004 8:26 am
Posts: 19
here is my own solution

maybe useful for someone beginning with hibernate and struts:

Action class
Code:
   public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws IOException, ServletException, HibernateException {

      String target = null;
      Collection liste_update = HibernateQueryUtil.getUpdateCollection();

      if (liste_update != null) {
         request.setAttribute("liste_update", liste_update);
         target = "success";
      } else {
         System.err.println(
            "Fehler beim Auslesen einer oder mehrerer Tabellen der Datenbank !");
         target = "failure";
      }
      return (mapping.findForward(target));
   }


helper class
Code:
   public static Collection getUpdateCollection()
      throws IOException, ServletException, HibernateException {

      Session session = HibernateUtil.currentSession();
      Transaction tx = session.beginTransaction();
      List results = null;
      Collection updates = new Vector();

      try {
         tx = session.beginTransaction();

         results =
            session.find(
               " from Bean_Update up" + " order by up.id_Update_ISB desc");

         if (results.size() == 0) {
            System.out.println("Keine Werte gefunden! \n");
         }

         Iterator iter = results.iterator();
         while (iter.hasNext()) {
            Bean_Update update = (Bean_Update) iter.next();
            updates.add(update);
         }

         tx.commit();

      } catch (Exception e) {
         e.printStackTrace(System.err);
         if (tx != null)
            tx.rollback();
      } finally {
         HibernateUtil.closeSession();
      }
      return updates;
   }


jsp
[code]
<html:form action="/new_update_insert" focus="id_update">
<html:errors />
<table align="center" cellspacing="0">
<tr>
<td class="header">&nbsp;
<html:img page="/gui/pics/small_logo.gif"/>
</td>
<td class="header" colspan="3">
<b>Bitte ein (Teil-) Update ausw

_________________
Have Fun!

Torsten


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.