Author Login
Post Reply
user Digest 8 Jan 2010 03:16:24 -0000 Issue 8977
Topics (messages 204548 through 204570):
Re: freemarker error in select tag
204548 by: Johannes Geppert
Whats the best way of using Google Inject Annotation in Struts
204549 by: Saeed Iqbal
Path page.logon does not start with a "/" character" Problem
204550 by: Andy T
How to nest Struts Tags
204551 by: RogerV
204567 by: Gabriel Belingueres
Re: struts2 and tables
204552 by: Chris Pratt
204553 by: Chris Pratt
204559 by: Sergio
204561 by: Sergio
204563 by: Chris Pratt
Struts, Tomcat, JNDI, JDBC without use of an ORM Library such as Hibernate
204554 by: Jasvinder S. Bahra
204555 by: Chris Pratt
204556 by: Greg Lindholm
204557 by: Brian Thompson
204560 by: Jasvinder S. Bahra
204562 by: Jasvinder S. Bahra
204564 by: Chris Pratt
204565 by: Jasvinder S. Bahra
Action Approach
204558 by: CRANFORD, CHRIS
204568 by: Gabriel Belingueres
Guice integration
204566 by: Saeed Iqbal
Why do i possibly get this error.
204569 by: Saeed Iqbal
204570 by: Saeed Iqbal
Administrivia:
---------------------------------------------------------------------
To post to the list, e-mail: user@(protected)
To unsubscribe, e-mail: user-digest-unsubscribe@(protected)
For additional commands, e-mail: user-digest-help@(protected)
----------------------------------------------------------------------

Attachment:
user_204548.ezm (zipped)
I use struts2 version 2.1.8.1
and this select tag:
<s:select name="format" list="formate" headerKey="" headerValue=""
label="Formate" cssStyle="width: 150px; float: left"></s:select>
The SelectBox is already filled so I thin the Action is not the Problem.
Gabriel Belingueres-2 wrote:
>
> Please post the S2 version number, the <s:select> tag you are using
> together with the action code to initialize the select list/map.
>
-----
---
web: http://www.jgeppert.com
twitter: http://twitter.com/jogep
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_204549.ezm (zipped)
Attachment:
user_204550.ezm (zipped)Hi All . . .
I am (relatively) new to Tiles and Struts and I'm having a problem
applying my tiles in my struts application correctly.
Originally, I was using Tiles 2.1 but because of technical problems
I decided to not use Tiles 2.1 and go back to the
struts-tiles-1.3.10.jar. In other words just use the Tiles that comes
with Struts 1.3. I added the Tiles Plug-In and changed everything
back from tiles.apache.org . . . to struts.apache.org . . . Now, I'm
getting the "Path page.logon does not start with a "/" character".
I have researched this issue some but have not been able to overcome
this problem.
Relevant source code follows:
If someone could assist me with this issue I'd really appreciate it . . .
Thanks,
Andy
******* struts-config.xml ************
<action path="/logon"
type="struts.Logon"
cancellable="true"
validate="false">
<forward name="ShowLogon" path="page.logon"/>
</action>
******* tiles-defs.xml *****************
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.3//EN"
"http://struts.apache.org/dtds/tiles-config_1_3.dtd">
<tiles-definitions>
<definition name="base.definition" path="/layouts/template.jsp">
<put name="title" value="Tiles tutorial homepage" />
<put name="header" value="/header.jsp" />
<put name="menu" value="/menu.jsp" />
<put name="leftnav" value="/leftnav.jsp" />
<put name="footer" value="/footer.jsp" />
</definition>
<definition name="page.logon" extends="base.definition">
<put name="body" value="/logon.jsp" />
</definition>
</tiles-definitions>

Attachment:
user_204551.ezm (zipped)
Hi
<s:iterator status="stat" value="config.groupList" >
<s:url id="url1" action="get-ccf-data" method="getParameterList">
<s:param name="displayGroup" value="<what goes here?>"/>
</s:url>
<s:a href="%{url1}"><s:property/></s:a>
</s:iterator>
The iterator is returning a string value on each iteration - what's the
incantation to get the value of <s:property/> into the value parameter of
the param tag?
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_204567.ezm (zipped)The <s:iterator> tag (without the var attribute) push the current item
to the top of the ValueStack.
<s:property/> will get the value from the top of the stack.
IMHO, I think this is a bad coding idiom. I don't like to think too
much where the data came from.
HTH
2010/1/7 RogerV <roger.varley@(protected)>:
>
> Hi
>
> <s:iterator status="stat" value="config.groupList" >
> <s:url id="url1" action="get-ccf-data" method="getParameterList">
> <s:param name="displayGroup" value="<what goes here?>"/>
> </s:url>
> <s:a href="%{url1}"><s:property/></s:a>
> </s:iterator>
>
> The iterator is returning a string value on each iteration - what's the
> incantation to get the value of <s:property/> into the value parameter of
> the param tag?
> --
> View this message in context: http://old.nabble.com/How-to-nest-Struts-Tags-tp27062761p27062761.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment:
user_204552.ezm (zipped)You can refer to the DisplayTag documentation about what collections they
support, there are quite a few. I usually use a
java.util.List of
JavaBean's And yes, you'll have to use JDBC, JPA, Ibatis, Hibernate... to
get that data from the database into a structure that can be displayed.
As for your other question, take a look at the last column in my example,
that's exactly what it does.
(*Chris*)
On Thu, Jan 7, 2010 at 1:05 AM, Sergio
<killing-is-my-business@(protected):
> but i don't understand the data structure to hold the users. When you get
> the ResultSet from mysql, how do you put it into the list? Without using
> hibernate or similar, i've tried with several collections, for example a
> <String >, Map <String><String>. The first string holds the name or user id,
> and the map holds attribute-value pair. No success, i think that is a bad
> solution.
>
> and another question: i need the user id be passed to another action as a
> parameter. I've tried with a s:form and a hidden field, something like
> <input type="hidden" value="<s:property>"> is the idea. It's about an online
> shop, and i'm having problems with:
>
> 1.- listing products from mysql
> 2.- adding products to the cart (from a mysql products list
>
> i'm a little newbie with struts.....
>
> regards
>
> --
> Sergio
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment:
user_204553.ezm (zipped)If all you want to do is display data in a simple HTML table, this is
definitely the way to go. If you need pagination or columnar sorting
support, I'd go with DisplayTag.
(*Chris*)
On Thu, Jan 7, 2010 at 1:39 AM, xerax nono <xrx1001@(protected):
> you can use iterator over a collection.
> see in
>
> http://www.vaannila.com/struts-2/struts-2-example/struts-2-crud-example-1.html
>
> <s:iterator value="userList" status="userStatus">
> 44. <tr
> 45. class="<s:if test="#userStatus.odd == true ">odd</s:if>
> <
> s:else>even</s:else>">
> 46. <td><s:property value="name" /></td>
> 47. <td><s:property value="gender" /></td>
> 48. <td><s:property value="country" /></td>
> 49. <td><s:property value="aboutYou" /></td>
> 50. <td><s:property value="mailingList" /></td>
> 51. <td>
> 52. <s:url id="editURL" action="editUser">
> 53. <s:param name="id" value="%{id}"></s:param>
> 54. </s:url>
> 55. <s:a href="%{editURL}">Edit</s:a>
> 56. </td>
> 57. <td>
> 58. <s:url id="deleteURL" action="deleteUser">
> 59. <s:param name="id" value="%{id}"></s:param>
> 60. </s:url>
> 61. <s:a href="%{deleteURL}">Delete</s:a>
> 62. </td>
>
>
> 2010/1/7 Frans Thamura <frans@(protected)>
>
> > can share how the struts2 work with display tag
> >
> >
> > sorry never use this also, how the display tag work with List when we
> > submit the grid
> >
> > F
> >
> >
> >
> >
> > On Thu, Jan 7, 2010 at 7:00 AM, Chris Pratt <thechrispratt@(protected)>
> > wrote:
> > > We use DisplayTag (http://www.displaytag.org), it works pretty well.
> > > (*Chris*)
> > >
> > > On Wed, Jan 6, 2010 at 3:28 PM, Sergio
> > > <killing-is-my-business@(protected):
> > >
> > >> Hi, people, how can i show a table into a jsp from the struts action?
> > Are
> > >> there a simple method for doing that? I've tried with java collections
> > into
> > >> the action and "property" tag into the jsp with no success.
> > >>
> > >> thanks in advance
> > >>
> > >> --
> > >> Sergio
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: user-unsubscribe@(protected)
> > >> For additional commands, e-mail: user-help@(protected)
> > >>
> > >>
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@(protected)
> > For additional commands, e-mail: user-help@(protected)
> >
> >
>
>
> --
> Serafin Hernandez Blazquez
> 649 81 64 87
>

Attachment:
user_204559.ezm (zipped)Chris Pratt escribió:
> You can refer to the DisplayTag documentation about what collections they
> support, there are quite a few. I usually use a
java.util.List of
> JavaBean's And yes, you'll have to use JDBC, JPA, Ibatis, Hibernate... to
> get that data from the database into a structure that can be displayed.
>
> As for your other question, take a look at the last column in my example,
> that's exactly what it does.
> (*Chris*)
>
> On Thu, Jan 7, 2010 at 1:05 AM, Sergio
> <killing-is-my-business@(protected):
>
>
>> but i don't understand the data structure to hold the users. When you get
>> the ResultSet from mysql, how do you put it into the list? Without using
>> hibernate or similar, i've tried with several collections, for example a
>> <String >, Map <String><String>. The first string holds the name or user id,
>> and the map holds attribute-value pair. No success, i think that is a bad
>> solution.
>>
>> and another question: i need the user id be passed to another action as a
>> parameter. I've tried with a s:form and a hidden field, something like
>> <input type="hidden" value="<s:property>"> is the idea. It's about an online
>> shop, and i'm having problems with:
>>
>> 1.- listing products from mysql
>> 2.- adding products to the cart (from a mysql products list
>>
>> i'm a little newbie with struts.....
>>
>> regards
>>
>> --
>> Sergio
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>>
>
>
wow, i think i got. I'll take a look.
thank you very much
--
Sergio

Attachment:
user_204561.ezm (zipped)Sergio escribió:
> Chris Pratt escribió:
>> You can refer to the DisplayTag documentation about what collections
>> they
>> support, there are quite a few. I usually use a
java.util.List of
>> JavaBean's And yes, you'll have to use JDBC, JPA, Ibatis,
>> Hibernate... to
>> get that data from the database into a structure that can be displayed.
>>
>> As for your other question, take a look at the last column in my
>> example,
>> that's exactly what it does.
>> (*Chris*)
>>
>> On Thu, Jan 7, 2010 at 1:05 AM, Sergio
>> <killing-is-my-business@(protected):
>>
>>
>>> but i don't understand the data structure to hold the users. When
>>> you get
>>> the ResultSet from mysql, how do you put it into the list? Without
>>> using
>>> hibernate or similar, i've tried with several collections, for
>>> example a
>>> <String >, Map <String><String>. The first string holds the name or
>>> user id,
>>> and the map holds attribute-value pair. No success, i think that is
>>> a bad
>>> solution.
>>>
>>> and another question: i need the user id be passed to another action
>>> as a
>>> parameter. I've tried with a s:form and a hidden field, something like
>>> <input type="hidden" value="<s:property>"> is the idea. It's about
>>> an online
>>> shop, and i'm having problems with:
>>>
>>> 1.- listing products from mysql
>>> 2.- adding products to the cart (from a mysql products list
>>>
>>> i'm a little newbie with struts.....
>>>
>>> regards
>>>
>>> --
>>> Sergio
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>> For additional commands, e-mail: user-help@(protected)
>>>
>>>
>>>
>>
>>
> wow, i think i got. I'll take a look.
>
> thank you very much
>
my point is that i have a property which is a String, and i need that
string in two ways: as a literal string and as a parameter to another
action. Using "s:property", something like this:
<table>
<s:iterator value="#session.carrito">
<tr>
<td><s:property />
</td>
<td><s:url id="idResta" value="/Del.action">
<s:param name="politico" value="[0]"></s:param>
</s:url>
<sx:a accesskey="6" href="%{idResta}"
targets="secondaryContent" >Fuera</sx:a>
</td>
</tr>
</s:iterator>
</table>
sessio.carrito is a String ArrayList and iterator works. Each of that
string must be passed to another action, say Action2, like a form with a
hidden field. During Action2 (which delete "politico" from
session.carrito) there's a *
java.lang.ArrayIndexOutOfBoundsException: -1*
I thought that "[0]" helds the actual value, same as "<s:property />".
Into "param" tag i've tried also with value="{ #this }" but i got that
java exception.
Something like:
<s:param name="politico" value="<s:property />"></s:param>
is my literal desire :)
My struts action has private String politico and getters y setters. I'm
not really sure if "politco" is viewed by Action2.
regards
**
--
Sergio

Attachment:
user_204563.ezm (zipped)I'm not positive but you might try:
<s:param name="politico" value="${this}"/>
(*Chris*)
On Thu, Jan 7, 2010 at 4:09 PM, Sergio
<killing-is-my-business@(protected):
> Sergio escribió:
>
> Chris Pratt escribió:
>>
>>> You can refer to the DisplayTag documentation about what collections they
>>> support, there are quite a few. I usually use a
java.util.List of
>>> JavaBean's And yes, you'll have to use JDBC, JPA, Ibatis, Hibernate... to
>>> get that data from the database into a structure that can be displayed.
>>>
>>> As for your other question, take a look at the last column in my example,
>>> that's exactly what it does.
>>> (*Chris*)
>>>
>>> On Thu, Jan 7, 2010 at 1:05 AM, Sergio
>>> <killing-is-my-business@(protected):
>>>
>>>
>>>
>>>> but i don't understand the data structure to hold the users. When you
>>>> get
>>>> the ResultSet from mysql, how do you put it into the list? Without using
>>>> hibernate or similar, i've tried with several collections, for example a
>>>> <String >, Map <String><String>. The first string holds the name or user
>>>> id,
>>>> and the map holds attribute-value pair. No success, i think that is a
>>>> bad
>>>> solution.
>>>>
>>>> and another question: i need the user id be passed to another action as
>>>> a
>>>> parameter. I've tried with a s:form and a hidden field, something like
>>>> <input type="hidden" value="<s:property>"> is the idea. It's about an
>>>> online
>>>> shop, and i'm having problems with:
>>>>
>>>> 1.- listing products from mysql
>>>> 2.- adding products to the cart (from a mysql products list
>>>>
>>>> i'm a little newbie with struts.....
>>>>
>>>> regards
>>>>
>>>> --
>>>> Sergio
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>>> For additional commands, e-mail: user-help@(protected)
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>> wow, i think i got. I'll take a look.
>>
>> thank you very much
>>
>> my point is that i have a property which is a String, and i need that
> string in two ways: as a literal string and as a parameter to another
> action. Using "s:property", something like this:
>
> <table>
> <s:iterator value="#session.carrito">
> <tr>
> <td><s:property />
> </td>
> <td><s:url id="idResta" value="/Del.action">
> <s:param name="politico" value="[0]"></s:param>
> </s:url>
> <sx:a accesskey="6" href="%{idResta}"
> targets="secondaryContent" >Fuera</sx:a>
> </td>
> </tr>
> </s:iterator>
> </table>
>
> sessio.carrito is a String ArrayList and iterator works. Each of that
> string must be passed to another action, say Action2, like a form with a
> hidden field. During Action2 (which delete "politico" from session.carrito)
> there's a *
java.lang.ArrayIndexOutOfBoundsException: -1*
>
> I thought that "[0]" helds the actual value, same as "<s:property />". Into
> "param" tag i've tried also with value="{ #this }" but i got that java
> exception.
>
> Something like:
>
> <s:param name="politico" value="<s:property />"></s:param>
>
> is my literal desire :)
>
> My struts action has private String politico and getters y setters. I'm not
> really sure if "politco" is viewed by Action2.
>
>
> regards
> **
>
> --
> Sergio
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment:
user_204554.ezm (zipped)Does anyone know of any techniques that would allow a Database Access Object
(DAO) to be used from the various actions that make up a Struts application?
I have a DAO which, when instantiated, acquires a data source from the
servlet container (in this case, Apache Tomcat). Thereafter, I can execute
the various methods provided by the object which use the data source to
execute SQL queries/statements, and return usable data in the form of
Strings, Maps, Vectors etc, as appropriate.
Instantiating the DAO in the execute() method of each of my action's
however, seems a little inefficient. Does Struts provide any way to
instantiate the object once and then make it available for the lifetime of
the container (in a way that my Actions can access it)?
Note please that i'm well aware that this is a somewhat non-standard
approach to database interaction. I am intending to investigate Hibernate
(and like) at some point, but for the time being I want to avoid such.
This is the skeleton of the DAO I have in mind...
----------------------------------------------------------------------
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import javax.servlet.*;
public class MyDataAccessObject {
private DataSource dataSource;
private String SQL;
public MyDataAccessObject() throws Exception {
try {
Context init = new InitialContext();
Context ctx = (Context) init.lookup("java:comp/env");
dataSource = (DataSource) ctx.lookup("jdbc/mysqldb");
} catch (NamingException ne) {
throw new Exception("Cannot retrieve
java:comp/env/jdbc/mysqldb", ne);
}
SQL = null;
}
public String getValue(String name) {
Connection dbcon = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String value = null;
try {
dbcon = dataSource.getConnection();
SQL = "SELECT value FROM table WHERE name = ?";
pstmt = dbcon.prepareStatement(SQL);
pstmt.setString(1, name);
rs = pstmt.executeQuery();
while (rs.next()) {
value = rs.getString("value");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
dbcon.close();
dbcon = null;
} catch (SQLException ex) {
log(ex);
} catch (Exception ex) {
log(ex);
} finally {
if (rs != null) {
try { rs.close(); } catch (Exception fe1) { log(fe1); }
rs = null;
}
if (pstmt != null) {
try { pstmt.close(); } catch (Exception fe2) { log(fe2); }
pstmt = null;
}
if (dbcon != null) {
try { dbcon.close(); } catch (Exception fe3) { log(fe3); }
dbcon = null;
}
}
SQL = null;
return value;
}
private void log(...) {
// Handle logging
}
}
----------------------------------------------------------------------
Thanks,
Jazz

Attachment:
user_204555.ezm (zipped)We use Spring (and Spring-LDAP) for that layer. It works great, manages all
our DAO's and their resources, and then injects them into the Actions as
needed.
(*Chris*)
On Thu, Jan 7, 2010 at 10:06 AM, Jasvinder S. Bahra <
bbdl21548@(protected):
> Does anyone know of any techniques that would allow a Database Access
> Object (DAO) to be used from the various actions that make up a Struts
> application?
>
> I have a DAO which, when instantiated, acquires a data source from the
> servlet container (in this case, Apache Tomcat). Thereafter, I can execute
> the various methods provided by the object which use the data source to
> execute SQL queries/statements, and return usable data in the form of
> Strings, Maps, Vectors etc, as appropriate.
>
> Instantiating the DAO in the execute() method of each of my action's
> however, seems a little inefficient. Does Struts provide any way to
> instantiate the object once and then make it available for the lifetime of
> the container (in a way that my Actions can access it)?
>
> Note please that i'm well aware that this is a somewhat non-standard
> approach to database interaction. I am intending to investigate Hibernate
> (and like) at some point, but for the time being I want to avoid such.
>
> This is the skeleton of the DAO I have in mind...
>
> ----------------------------------------------------------------------
> import java.sql.*;
> import javax.sql.*;
> import javax.naming.*;
> import javax.servlet.*;
>
> public class MyDataAccessObject {
>
> private DataSource dataSource;
> private String SQL;
>
> public MyDataAccessObject() throws Exception {
>
> try {
> Context init = new InitialContext();
> Context ctx = (Context) init.lookup("java:comp/env");
> dataSource = (DataSource) ctx.lookup("jdbc/mysqldb");
> } catch (NamingException ne) {
> throw new Exception("Cannot retrieve java:comp/env/jdbc/mysqldb",
> ne);
> }
>
> SQL = null;
> }
>
> public String getValue(String name) {
>
> Connection dbcon = null;
> PreparedStatement pstmt = null;
> ResultSet rs = null;
>
> String value = null;
>
> try {
> dbcon = dataSource.getConnection();
>
> SQL = "SELECT value FROM table WHERE name = ?";
>
> pstmt = dbcon.prepareStatement(SQL);
> pstmt.setString(1, name);
>
> rs = pstmt.executeQuery();
> while (rs.next()) {
> value = rs.getString("value");
> }
>
> rs.close();
> rs = null;
>
> pstmt.close();
> pstmt = null;
>
> dbcon.close();
> dbcon = null;
> } catch (SQLException ex) {
> log(ex);
> } catch (Exception ex) {
> log(ex);
> } finally {
> if (rs != null) {
> try { rs.close(); } catch (Exception fe1) { log(fe1); }
> rs = null;
> }
>
> if (pstmt != null) {
> try { pstmt.close(); } catch (Exception fe2) { log(fe2); }
> pstmt = null;
> }
>
> if (dbcon != null) {
> try { dbcon.close(); } catch (Exception fe3) { log(fe3); }
> dbcon = null;
> }
> }
>
> SQL = null;
> return value;
> }
>
> private void log(...) {
> // Handle logging
> }
> }
> ----------------------------------------------------------------------
>
> Thanks,
>
> Jazz
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment:
user_204556.ezm (zipped)>
> Instantiating the DAO in the execute() method of each of my action's
> however, seems a little inefficient. Does Struts provide any way to
> instantiate the object once and then make it available for the lifetime of
> the container (in a way that my Actions can access it)?
>
So want your DAO's to be singletons?
You would have to make them Thread-safe (or synchronize and kill
performance), beware that database connections are not thread-safe.
Doesn't really sound like a good plan to me.
If you just have one DAO of each type (singletons) then you need to
ensure they are thread-safe and you need to either handle the
acquire/release of database connections within each method or pass in
the connection. Neither is a great design, the first make you
duplicate fragile difficult to test code in every DAO the second
exposes database connections in the DAO methods. It's hard to write
DAO's as singletons and get them right, much easier to use a new one
each time as if they have no state then instantiating them is cheap
(where writing thread safe code is hard, hard to write, hard to test).
The preferred method is use a DI facility (like Guice or Spring) and
instantiate a new DAO each time and inject the database connection
into it and inject the DAO into the Struts action. This make it easy
to write, easy to test and you don't have to expose database
connections and handling logic to the actions.

Attachment:
user_204557.ezm (zipped)I'll echo the Spring suggestion. It simplifies Action-level programming by
quite a bit.
On the flip side, it requires some extra XML configuration, but IMO it's a
good tradeoff.
-Brian
On Thu, Jan 7, 2010 at 12:18 PM, Chris Pratt <thechrispratt@(protected):
> We use Spring (and Spring-LDAP) for that layer. It works great, manages
> all
> our DAO's and their resources, and then injects them into the Actions as
> needed.
> (*Chris*)
>
> On Thu, Jan 7, 2010 at 10:06 AM, Jasvinder S. Bahra <
> bbdl21548@(protected):
>
> > Does anyone know of any techniques that would allow a Database Access
> > Object (DAO) to be used from the various actions that make up a Struts
> > application?
> >
> > I have a DAO which, when instantiated, acquires a data source from the
> > servlet container (in this case, Apache Tomcat). Thereafter, I can
> execute
> > the various methods provided by the object which use the data source to
> > execute SQL queries/statements, and return usable data in the form of
> > Strings, Maps, Vectors etc, as appropriate.
> >
> > Instantiating the DAO in the execute() method of each of my action's
> > however, seems a little inefficient. Does Struts provide any way to
> > instantiate the object once and then make it available for the lifetime
> of
> > the container (in a way that my Actions can access it)?
> >
> > Note please that i'm well aware that this is a somewhat non-standard
> > approach to database interaction. I am intending to investigate
> Hibernate
> > (and like) at some point, but for the time being I want to avoid such.
> >
> > This is the skeleton of the DAO I have in mind...
> >
> > ----------------------------------------------------------------------
> > import java.sql.*;
> > import javax.sql.*;
> > import javax.naming.*;
> > import javax.servlet.*;
> >
> > public class MyDataAccessObject {
> >
> > private DataSource dataSource;
> > private String SQL;
> >
> > public MyDataAccessObject() throws Exception {
> >
> > try {
> > Context init = new InitialContext();
> > Context ctx = (Context) init.lookup("java:comp/env");
> > dataSource = (DataSource) ctx.lookup("jdbc/mysqldb");
> > } catch (NamingException ne) {
> > throw new Exception("Cannot retrieve
> java:comp/env/jdbc/mysqldb",
> > ne);
> > }
> >
> > SQL = null;
> > }
> >
> > public String getValue(String name) {
> >
> > Connection dbcon = null;
> > PreparedStatement pstmt = null;
> > ResultSet rs = null;
> >
> > String value = null;
> >
> > try {
> > dbcon = dataSource.getConnection();
> >
> > SQL = "SELECT value FROM table WHERE name = ?";
> >
> > pstmt = dbcon.prepareStatement(SQL);
> > pstmt.setString(1, name);
> >
> > rs = pstmt.executeQuery();
> > while (rs.next()) {
> > value = rs.getString("value");
> > }
> >
> > rs.close();
> > rs = null;
> >
> > pstmt.close();
> > pstmt = null;
> >
> > dbcon.close();
> > dbcon = null;
> > } catch (SQLException ex) {
> > log(ex);
> > } catch (Exception ex) {
> > log(ex);
> > } finally {
> > if (rs != null) {
> > try { rs.close(); } catch (Exception fe1) { log(fe1); }
> > rs = null;
> > }
> >
> > if (pstmt != null) {
> > try { pstmt.close(); } catch (Exception fe2) { log(fe2); }
> > pstmt = null;
> > }
> >
> > if (dbcon != null) {
> > try { dbcon.close(); } catch (Exception fe3) { log(fe3); }
> > dbcon = null;
> > }
> > }
> >
> > SQL = null;
> > return value;
> > }
> >
> > private void log(...) {
> > // Handle logging
> > }
> > }
> > ----------------------------------------------------------------------
> >
> > Thanks,
> >
> > Jazz
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@(protected)
> > For additional commands, e-mail: user-help@(protected)
> >
> >
>

Attachment:
user_204560.ezm (zipped)> We use Spring (and Spring-LDAP) for that layer. It works great, manages
> all
> our DAO's and their resources, and then injects them into the Actions as
> needed.
Chris,
At the moment, i'm trying to reaquaint myself with the ins and out of Struts
(I haven't touched it for several years), so I dont (yet) want to introduce
any additional libraries.
I'm sure its possible to do what I need without them.
Thanks for the suggestion anyway.
Jazz

Attachment:
user_204562.ezm (zipped)> So want your DAO's to be singletons?
> You would have to make them Thread-safe (or synchronize and kill
> performance), beware that database connections are not thread-safe.
Please note that i'm using using the database connection pooling
facilities provided by the Servlet Container (Apache Tomcat). As long as
the DAO aquires the database connection through a JNDI datasource, the
Servlet Container will take care of the thread and connection management
issues.
> The preferred method is use a DI facility (like Guice or Spring) and
> instantiate a new DAO each time and inject the database connection
> into it and inject the DAO into the Struts action.
I'd prefer to avoid the use of additional libraries for the time being
which is why I haven't taken advantage of the libraries that you
mentioned.
I'm more than happy to remove the acquiring of the datasource code from
the DAO's constructor, and add a method to allow an instantiated version
of the class to be assigned a data source. However, I would need a way of
acquiring the datasource and assigning it to the DAO *without* using any
additional libraries.
Any ideas?
Thanks for the response.
Jazz

Attachment:
user_204564.ezm (zipped)Good luck, and let us know how it goes.
(*Chris*)
On Thu, Jan 7, 2010 at 3:44 PM, Jasvinder S. Bahra <
bbdl21548@(protected):
> We use Spring (and Spring-LDAP) for that layer. It works great, manages
>> all
>> our DAO's and their resources, and then injects them into the Actions as
>> needed.
>>
>
> Chris,
>
> At the moment, i'm trying to reaquaint myself with the ins and out of
> Struts (I haven't touched it for several years), so I dont (yet) want to
> introduce any additional libraries.
>
> I'm sure its possible to do what I need without them.
>
> Thanks for the suggestion anyway.
>
>
> Jazz
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment:
user_204565.ezm (zipped)> I'll echo the Spring suggestion. It simplifies Action-level programming
> by
> quite a bit.
>
> On the flip side, it requires some extra XML configuration, but IMO it's a
> good tradeoff.
Spring seems to be quite popular here. I'm somewhat reluctant because
Spring provides a lot more than just Database Injection - and for the time
being, DI is all I really want.
If I cant find what I want, I guess i'll have to bite the bullet and jump
into it.
Thanks for the response.
Jazz

Attachment:
user_204558.ezm (zipped)All -
I am working on an action that takes a set of input and forwards the
user to a web page that contains a form with a layout as follows:
Active Primary
Catalog1 [ ] [ ]
Catalog2 [ ] [ ]
Catalog3 [ ] [ ]
In order to to capture the changes to the checkbox values for both
active and primary for each catalog entry listed, what is the best
approach for mapping this back into the action so that I can update my
hibernate model objects.
Thanks
Chris

Attachment:
user_204568.ezm (zipped)I think the answer would depend of what your model objects look like.
If your Catalog object have 2 boolean variables (active and primary)
then holding a Map<CatalogPrimaryKey,Catalog> on your action (session
scoped) is a straightforward solution. (name your checkbox
"catalogMap[pk].active" and "catalogMap[pk].primary")
If this is not the case, then your action could hold 2
Map<CatalogPrimaryKey,Boolean> activeMap and primaryMap, and naming
your checkboxes like "activeMap[key]" will do.
2010/1/7 CRANFORD, CHRIS <Chris.Cranford@(protected)>:
> All -
>
> I am working on an action that takes a set of input and forwards the
> user to a web page that contains a form with a layout as follows:
>
> Active Primary
> Catalog1 [ ] [ ]
> Catalog2 [ ] [ ]
> Catalog3 [ ] [ ]
>
> In order to to capture the changes to the checkbox values for both
> active and primary for each catalog entry listed, what is the best
> approach for mapping this back into the action so that I can update my
> hibernate model objects.
>
> Thanks
> Chris
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment:
user_204566.ezm (zipped)Can anyone tell me how to best integrate guice with struts please.
--
Saeed Iqbal
Independant Consultant
J2EE - Application Architect / Developer

Attachment:
user_204569.ezm (zipped)
Attachment:
user_204570.ezm (zipped)