Re: Need good tab control for JSP.

2005-10-23 Thread emre akbas
Maybe a pure-javascript solution may work for you:

http://www.dynamicdrive.com/dynamicindex17/tabcontent.htm

--
Emre Akbas

-- Forwarded message --
> From: "Zsolt" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" 
> Date: Sun, 23 Oct 2005 17:54:10 +0200
> Subject: Need good tab control for JSP.
> Hi,
>
> I need a good tab control for JSP. I have tried struts-layout and
> http://209.61.157.8:8080/taglibs/?orgDitchnetTabPaneId=overview.
>
> Struts-layout doesn't seem to work. Ditchnet seems to be very good however
> we cannot switch tomcat-5.5 into servlet mode 2.3.
>
> Can you provide me some alternatives?
>
> Zsolt


Re: Struts and db connections :: best practice

2005-10-14 Thread emre akbas
Larry, I think you are using DAO. Then, I want to ask you how do you deal
with the SQLException's and unclosed connections in your DAO classes if you
are using JDBC as the persistence layer.

Say, you have CustomerDAO and it has a insert method:

public class CustomerDAO {
boolean insert() {
Connection con = getDataSource().getConnection();
.
// an exception occurs here
..
con.close();
}
}


Do you catch this exception in the DAO method or do you throw it outside?
When you throw it outside, the local connection will be unclosed. What do
you to prevent such issues? Thanks in advance.




-- Forwarded message --
From: Larry Meadors <[EMAIL PROTECTED]>
To: Struts Users Mailing List 
Date: Thu, 13 Oct 2005 08:36:47 -0600
Subject: Re: Struts and db connections :: best practice
I would argue that a well-written struts application will *never* (at
least 99.999% of the time) have jdbc code in it.

Larry


On 10/13/05, emre akbas <[EMAIL PROTECTED]> wrote:
> Hi all,
> In a well written struts application, we assume declarative exception
> handling is used. Therefore the code of the action classes will look clean
> and short (and nice) because all the exception handling is done via the
> exception-handler classes outside. My question is about db connection
> management when declarative exception handling is used.
>
> A usual scenario is :
>
> ~~ 
> public class MyAction extends Action {
> ...
> public ActionForward execute( . .. ) {
> ..
> Connection con = getDataSource().getConnection();
>
> // an exception occurs here and the control passes to the
> // exception-handler class, which can never close the connection
> // opened above.
> 
>
> con.close();
> }
> ...
> }
> ~~
>
> What to do in a situation like above? Since the exception-handler could
not
> close the connection opened in the Action class, this will cause the
> connections in the pool to be exhausted. To prevent the situation above,
we
> may :
>
> ~~
> public class MyAction extends Action {
> ...
> public ActionForward execute( . .. ) {
> ..
> Connection con = null;
> try {
> con = getDataSource().getConnection();
>
> // an exception occurs here
> 
>
> } catch(MyAppSpecifiException e) {
> 
> } catch(Exception e) { // IMPORTANT, this line will catch all the
exceptions
> 
> } finally {
> con.close();
> }
>
> }
> ...
> }
>
>
> The scheme above seems to solve the unclosed connection problem but it
does
> not use declarative exception-handling and the code is really messed-up
with
> exception handling statements. It does not look nice, clean and short.
>
> The situation is more complicated when you call a service method within
the
> action and that service method throws an exception.
>
> I would like to hear your points on this issuse. Thanks in advance.
>
>
> --
>
> Emre Akbas
>
>



--
Emre Akbas


Struts and db connections :: best practice

2005-10-13 Thread emre akbas
Hi all,
In a well written struts application, we assume declarative exception
handling is used. Therefore the code of the action classes will look clean
and short (and nice) because all the exception handling is done via the
exception-handler classes outside. My question is about db connection
management when declarative exception handling is used.

A usual scenario is :

~~
public class MyAction extends Action {
...
public ActionForward execute( . .. ) {
..
Connection con = getDataSource().getConnection();

// an exception occurs here and the control passes to the
// exception-handler class, which can never close the connection
// opened above.


con.close();
}
...
}
~~

What to do in a situation like above? Since the exception-handler could not
close the connection opened in the Action class, this will cause the
connections in the pool to be exhausted. To prevent the situation above, we
may :

~~
public class MyAction extends Action {
...
public ActionForward execute( . .. ) {
..
Connection con = null;
try {
con = getDataSource().getConnection();

// an exception occurs here


} catch(MyAppSpecifiException e) {

} catch(Exception e) { // IMPORTANT, this line will catch all the exceptions

} finally {
con.close();
}

}
...
}


The scheme above seems to solve the unclosed connection problem but it does
not use declarative exception-handling and the code is really messed-up with
exception handling statements. It does not look nice, clean and short.

The situation is more complicated when you call a service method within the
action and that service method throws an exception.

I would like to hear your points on this issuse. Thanks in advance.


--

Emre Akbas


how to sustain the sanity of the connection pool

2005-10-11 Thread emre akbas
Hi,
I have some general questions about connection pooling and exception
handling.
Struts suggests that developers use declarative exception handling. In
declarative exception handling, there are almost no "try { } catch() {}"
blocks in the Action classes. Exception occuring in Action classes are
handled by exception handlers outside the Action classes. Everything seems
OK so far.
It is very usual that we open a connection to the database at the beginning
of the Action class and then close it at the end. When an exception occurs,
an exception-handler outside of our Action class (in which the exception is
thrown) handles the exception. Then, what happens to the connection? We
weren't able to close it, so does it continue to allocate a connection from
the pool?
My other question is about the connection pooling itself. Are there any
tools or ideas to monitor the sanity of the connection pool? Are we somehow
able to find the classes where leakage occur?
Thanks in advance.


ActionMessage and bundle choice

2005-09-27 Thread emre akbas
Hi,
We know that ActionMessage class has a field to store the key of the message
but not the bundle name of the key. For (error) messages that are not in the
default message-resources, we can do the trick in the jsp file by giving the
bundle of the key like:

 
 
 

So far so good. But, what we shall do if the ActionMessages contain messages
which have to be resolved from different bundles? Should we write several
 tags with different bundles?


Re: Struts action servlet mapping, getPathInfo() returns null

2005-09-27 Thread emre akbas
Again, thank you very much Laurie.

I couldn't understand how ** wildcard mapping could work with suffix mapping
(*.do). I have tried, in web.xml, *.do/** but tomcat said "invalid
url-pattern". If I manage to get ** wilcard mapping work with *.do, I will
be able to correctly process a request like
http://localhost:8080/myapp/server.do/chapter1/1.html

Also, I've tried *.do** , tomcat did accept this but this time, it expected
me to write ** at the end of all URL's. That is, it didn't work as a
wildcard mapping.

And in struts-config.xml, I modified my action as " 
To: user@struts.apache.org
Date: Mon, 26 Sep 2005 14:31:10 -0400
Subject: Re: user Digest 25 Sep 2005 21:39:29 - Issue 6130
emre akbas wrote:
> Now, I have another problem. We have written our Struts application using
> prefix mappings, i.e "*.do". In order to use DownloadAction with **
mapping,
> we should migrate to suffix mapping, i.e. "/do/*" . Is there an easy way
of
> migrating a whole Struts application from prefix mapping to suffix
mapping?
> Or, is it possible that both mappings exists in web.xml ? (Sorry, if these
> are weird questions.)

[Note: '*.do' is a suffix, /do/* is a prefix (pre- -> previous); just to
reduce any confusion for people following along ;-)]

Actually, I think wildcard mappings *should* work with suffix mapping
too, though I've never tried it. But you can define both types of
mapping in web.xml, so long as you pick a prefix your application
doesn't already use. In other words, as long as you don't already have
linkes that start /do/... then adding a /do/* mapping is fine.

Migrating your whole app from one mapping style to the other wouldn't be
super hard -- just find anywhere you have an explicit .do and update
appropriately. However, I wouldn't recommend trying that if this is the
only driver. If what you have works, keep it ;-)

L.


Re: user Digest 25 Sep 2005 21:39:29 -0000 Issue 6130

2005-09-26 Thread emre akbas
Thank you Laurie. That is exactly what I am looking for. I had looked at the
documentation on wildcard mappings but I couldn't notice the ** mapping.
Thank you again.

Now, I have another problem. We have written our Struts application using
prefix mappings, i.e "*.do". In order to use DownloadAction with ** mapping,
we should migrate to suffix mapping, i.e. "/do/*" . Is there an easy way of
migrating a whole Struts application from prefix mapping to suffix mapping?
Or, is it possible that both mappings exists in web.xml ? (Sorry, if these
are weird questions.)

From: Laurie Harper <[EMAIL PROTECTED]>
> To: user@struts.apache.org
> Date: Sat, 24 Sep 2005 16:38:12 -0400
> Subject: Re: Struts action servlet mapping, getPathInfo() returns null
> Did you look at the documentation on wildcard mappings yet? If you use
> /do/admin/** it'll match arbitrarily 'deep' URLs.
>
> L.
>
> emre akbas wrote:
> > Thank you Dave. I'm afraid predefined mapping schemes like
> /do/admin/*/*"
> > and "/do/admin/*/*/* won't work for me since I want to implement a
> generic
> > file server. I cannot know the length of the URL nor its number of
> tokens
> > separated with "/". Actually, I have written such a fileserver using
> plain
> > old servlets. Since I don't want to mix servlets and Struts actions in
> my
> > Struts application, I'm looking for a way to implement this fileserver
> with
> > a DownloadAction class. But it seems to me that even if I use suffix
> > mapping, there is no way of getting the rest of the URL after the
> action's
> > name, in a generic manner.
> >
> > -- Forwarded message --
> >
> >>From: Dave Newton <[EMAIL PROTECTED]>
> >>To: Struts Users Mailing List 
> >>Date: Fri, 23 Sep 2005 17:53:56 -0400
> >>Subject: Re: user Digest 23 Sep 2005 19:04:19 - Issue 6127
> >>emre akbas wrote:
> >>
> >>
> >>>Dave, of course I know the URL is avaliable from HttpServletRequest. I
> >>
> >>think
> >>
> >>>you didn't read my previous e-mails on the topic.
> >>>
> >>>I couldn't find a way to get the remaining part of the URL after the
> >>>action's name. That is, to get /chapter1/1.html in
> >>>http://localhost:8080/action.do/chapter1/1.html
> >>>
> >>>request.getPathInfo() always returns null.
> >>>
> >>>
> >>
> >>I'm actually a little surprised your Action is firing at all if you're
> >>doing *.do mapping and passing in something that doesn't end with *.do.
> >>
> >>If you use /do/* mapping and pass in something that isn't "actively"
> >>being mapped (i.e., mapping from "/do/chapter1/1.html" to an Action) I'm
> >>not sure I'd expect Struts to handle this.
> >>
> >>Now, if you do something like a wildcard mapping and define how you want
> >>that to work (i.e., mapping from "/do/download/*/*" to an Action) you'll
> >>probably get further--I'd look in to that.
> >>
> >>For instance, I created a generic CRUD action class that mapped
> >>"/do/admin/*/*" and "/do/admin/*/*/*" and stripped out chunks to get
> >>table names, commands, and ids.
> >>
> >>Also check out ActionMapping.getPath():
> >>
> >>"Return context-relative path of the submitted request, starting with a
> >>slash ("/") character, and omitting any filename extension if extension
> >>mapping is being used."
> >>
> >>Dave
> >>
> >>
> >>
> >>
>


Re: Struts action servlet mapping, getPathInfo() returns null

2005-09-24 Thread emre akbas
Thank you Dave. I'm afraid predefined mapping schemes like /do/admin/*/*"
and "/do/admin/*/*/* won't work for me since I want to implement a generic
file server. I cannot know the length of the URL nor its number of tokens
separated with "/". Actually, I have written such a fileserver using plain
old servlets. Since I don't want to mix servlets and Struts actions in my
Struts application, I'm looking for a way to implement this fileserver with
a DownloadAction class. But it seems to me that even if I use suffix
mapping, there is no way of getting the rest of the URL after the action's
name, in a generic manner.

-- Forwarded message --
> From: Dave Newton <[EMAIL PROTECTED]>
> To: Struts Users Mailing List 
> Date: Fri, 23 Sep 2005 17:53:56 -0400
> Subject: Re: user Digest 23 Sep 2005 19:04:19 - Issue 6127
> emre akbas wrote:
>
> >Dave, of course I know the URL is avaliable from HttpServletRequest. I
> think
> >you didn't read my previous e-mails on the topic.
> >
> >I couldn't find a way to get the remaining part of the URL after the
> >action's name. That is, to get /chapter1/1.html in
> >http://localhost:8080/action.do/chapter1/1.html
> >
> >request.getPathInfo() always returns null.
> >
> >
> I'm actually a little surprised your Action is firing at all if you're
> doing *.do mapping and passing in something that doesn't end with *.do.
>
> If you use /do/* mapping and pass in something that isn't "actively"
> being mapped (i.e., mapping from "/do/chapter1/1.html" to an Action) I'm
> not sure I'd expect Struts to handle this.
>
> Now, if you do something like a wildcard mapping and define how you want
> that to work (i.e., mapping from "/do/download/*/*" to an Action) you'll
> probably get further--I'd look in to that.
>
> For instance, I created a generic CRUD action class that mapped
> "/do/admin/*/*" and "/do/admin/*/*/*" and stripped out chunks to get
> table names, commands, and ids.
>
> Also check out ActionMapping.getPath():
>
> "Return context-relative path of the submitted request, starting with a
> slash ("/") character, and omitting any filename extension if extension
> mapping is being used."
>
> Dave
>
>
>
>
>
> -- Forwarded message --
> From: T West <[EMAIL PROTECTED]>
> To: Struts Users Mailing List , Michael Jouravlev
> <[EMAIL PROTECTED]>
> Date: Fri, 23 Sep 2005 16:39:16 -0500
> Subject: Re: AW: [Solved]Cannot find ActionMappings or ActionFormBeans
> Okay, thanks to everyone for all of their help. My problem was my
> directory structure. I googled around to find some examples, and found
> this page: http://www.jguru.com/faq/view.jsp?EID=531027
> I had my JSP pages in the same directory as my struts-config.xml file.
> So, I made a DatabaseRetrieval directory where I could put my JSP
> pages, made a WEB-INF directory inside of the DatabaseRetrieval
> directory, modified the web.xml to reflect that it was now
> /WEB-INF/struts-config.xml and then tried recompiling. It worked!
> Thanks again.
>
> On 9/23/05, Michael Jouravlev <[EMAIL PROTECTED]> wrote:
> > It is not important where you are. Your WAR file structure is
> > important, though.
> >
> > If you cannot explain where your struts-config.xml file is located,
> > then maybe you would prefer to search the net first. Look for
> > something like "(Java OR J2EE OR Struts) web application (directory OR
> > file) (packaging OR structure)".
> >
> > Michael.
> >
> > On 9/23/05, T West <[EMAIL PROTECTED]> wrote:
> > > I'm not sure if I explained myself correctly, but when I make my war
> > > file, I'm inside of the WEB-INF directory, so that everything that is
> > > packaged is the WEB-INF directory. When I open up the war, it's just
> > > all the files and directories that were in the WEB-INF directory.
> > >
> > > On 9/23/05, Dave Newton <[EMAIL PROTECTED]> wrote:
> > > > T West wrote:
> > > >
> > > > > I'm packaging my WEB-INF directory, so that when the war is
> expanded,
> > > > > it's opening up the WEB-INF directory.
> > > > >
> > > > >
> > > > Huh?
> > > >
> > > > So, where is your struts file? Michael's saying that you probably
> don't
> > > > have it in the right place, namely, under WEB-INF. The WEB-INF must
> be
> > > > part of the param-value.
> > > >
&g

Re: user Digest 23 Sep 2005 19:04:19 -0000 Issue 6127

2005-09-23 Thread emre akbas
Dave, of course I know the URL is avaliable from HttpServletRequest. I think
you didn't read my previous e-mails on the topic.

I couldn't find a way to get the remaining part of the URL after the
action's name. That is, to get /chapter1/1.html in
http://localhost:8080/action.do/chapter1/1.html

request.getPathInfo() always returns null.

-- Forwarded message --
> From: Dave Newton <[EMAIL PROTECTED]>
> To: Struts Users Mailing List 
> Date: Fri, 23 Sep 2005 11:34:38 -0400
> Subject: Re: Struts action servlet mapping, getPathInfo() returns null
> emre akbas wrote:
>
> >Sorry, but I don't think that you've understand my question. I wan to get
> >the full URL of the request in my action class. None of the examples in
> the
> >wiki page you posted addresses this issue.
> >
> >
> The URL of the request is available from the HttpServletRequest object.
> See the JavaDocs.
>
> Dave
>
>
>
>
>


Re: Struts action servlet mapping, getPathInfo() returns null

2005-09-23 Thread emre akbas
No problem.

I don't want to pass the filename as a request parameter as you suggested
since this way my server cannot serve html file properly. Say I have two
files: 1.html and 1.jpg and assume that 1.jpg is used within 1.html

When I request 1.html using your suggested method, the image 1.jpg will not
display in 1.html. That is my problem. If I manage to make
http://myhost:8080/myapp/server.do/chapter1/images/1.html work, this scheme
will request 1.jpg automatically and correctly from my server. At the end,
1.html will be displayed correctly with 1.jpg in it.

Am I clear enough?

On 9/23/05, Murray Collingwood <[EMAIL PROTECTED]> wrote:
>
> Sorry Emre
>
> From your first paragraph it sounds as though you want to be able to
> download a file
> using an action class. Why not modify your URL a little to do just that,
> http://myhost:8080/myapp/server.do?file=/chapter1/images/1.jpg
>
> Perhaps you could explain the reasons why the above won't work, this will
> help us
> understand the problem better.
>
> Kind regards
> mc
>
>
> On 23 Sep 2005 at 15:15, emre akbas wrote:
>
> >
> > Sorry, but I don't think that you've understand my question. I wan to
> get the full URL of the
> > request in my action class. None of the examples in the wiki page you
> posted
> addresses this
> > issue.
> >
> > On 9/23/05, Murray Collingwood <[EMAIL PROTECTED] > wrote:
> > Same questions same answers...
> >
> > http://wiki.apache.org/struts/StrutsFileDownload
> >
> > Kind regards
> > mc
> >
> >
> > On 23 Sep 2005 at 11:41, emre akbas wrote:
> >
> > > Hi,
> > > I want to do sth like the following:
> > > When a user clicks the link:
> > > http://myhost:8080/myapp/server.do/chapter1/images/1.jpg I want to get
> the
> > > "/chapter1/images/1.jpg" part of the request and then serve the
> requested
> > > file. "server.do" is a downloadaction.
> > > As Laurie Harper stated in one of his previous emails, prefix mapping,
> i.e.
> > > *.do, is not suitable to do this. He suggested to me that I use suffix
> > > mapping which is sth. like /do/* . I have tried suffix mapping but no
> > > success. request.getPathInfo() returns null.
> > > All I want to do is to get the request.getPathInfo(), or the full URL
> of the
> > > request, within a downloadaction class.
> > > Thanks in advance.
> > >
> >
> >
> >
> > FOCUS Computing
> > Mob: 0415 24 26 24
> > [EMAIL PROTECTED]
> > http://www.focus-computing.com.au
> >
> >
> >
> > --
> > No virus found in this outgoing message.
> > Checked by AVG Anti-Virus.
> > Version: 7.0.344 / Virus Database: 267.11.4/109 - Release Date:
> 21/09/2005
> >
> >
> >
>
>
>
> FOCUS Computing
> Mob: 0415 24 26 24
> [EMAIL PROTECTED]
> http://www.focus-computing.com.au
>
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.344 / Virus Database: 267.11.4/109 - Release Date: 21/09/2005
>
>


Re: Struts action servlet mapping, getPathInfo() returns null

2005-09-23 Thread emre akbas
Sorry, but I don't think that you've understand my question. I wan to get
the full URL of the request in my action class. None of the examples in the
wiki page you posted addresses this issue.

On 9/23/05, Murray Collingwood <[EMAIL PROTECTED]> wrote:
>
> Same questions same answers...
>
> http://wiki.apache.org/struts/StrutsFileDownload
>
> Kind regards
> mc
>
>
> On 23 Sep 2005 at 11:41, emre akbas wrote:
>
> > Hi,
> > I want to do sth like the following:
> > When a user clicks the link:
> > http://myhost:8080/myapp/server.do/chapter1/images/1.jpg I want to get
> the
> > "/chapter1/images/1.jpg" part of the request and then serve the
> requested
> > file. "server.do" is a downloadaction.
> > As Laurie Harper stated in one of his previous emails, prefix mapping,
> i.e.
> > *.do, is not suitable to do this. He suggested to me that I use suffix
> > mapping which is sth. like /do/* . I have tried suffix mapping but no
> > success. request.getPathInfo() returns null.
> > All I want to do is to get the request.getPathInfo(), or the full URL of
> the
> > request, within a downloadaction class.
> > Thanks in advance.
> >
>
>
>
> FOCUS Computing
> Mob: 0415 24 26 24
> [EMAIL PROTECTED]
> http://www.focus-computing.com.au
>
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.344 / Virus Database: 267.11.4/109 - Release Date: 21/09/2005
>
>


Re: Storing DataSource and ServletContext in the service layer

2005-09-23 Thread emre akbas
Yes, to me too, getting datasource and then connection and passing this
connection object to the service layer does not seem to be a good pattern. I
said, by storing the datasource and servletcontext statically in the service
layer may make life easier.
I want to know various opinions about this topic. Thanks.

On 9/23/05, Lixin Chu <[EMAIL PROTECTED]> wrote:
>
> i think if you use Spring Framework or something similar, you might not
> > need to do this by yourself.
>
>  action class accessing DB does not seem to be a good pattern.
>
>
>


Struts action servlet mapping, getPathInfo() returns null

2005-09-23 Thread emre akbas
Hi,
I want to do sth like the following:
When a user clicks the link:
http://myhost:8080/myapp/server.do/chapter1/images/1.jpg I want to get the
"/chapter1/images/1.jpg" part of the request and then serve the requested
file. "server.do" is a downloadaction.
As Laurie Harper stated in one of his previous emails, prefix mapping, i.e.
*.do, is not suitable to do this. He suggested to me that I use suffix
mapping which is sth. like /do/* . I have tried suffix mapping but no
success. request.getPathInfo() returns null.
All I want to do is to get the request.getPathInfo(), or the full URL of the
request, within a downloadaction class.
Thanks in advance.


Storing DataSource and ServletContext in the service layer

2005-09-23 Thread emre akbas
Hi all,
I sometimes need to access the datasource within the service layer and by
default only Action classes have access to it. In order to solve this issue,
I plan to write a plugin which will get the datasource and the
servletcontext at startup and store them in the service layer as static
variables. Thus, I will be able to access to datasource and servletcontext
within my service methods.
Is this a good practice? Are there any known incoveniences?


downloadaction, flexible url mapping, file server

2005-09-18 Thread emre akbas
Hi, 
I want to implement a "secure file server" using Struts. By "secure" I mean, 
when a file is requested by a user, a "checkAccess" method will be called 
and it would check if the user has right to access that file (datasource 
will be used for this check) If checkAccess return true the file will be 
sent to the user. This scenario is very well suited to the logic of 
DownloadAction BUT my fileserver has to work with html files containing 
images. When you request an html file containing images, the browser will 
automatically request that images from the server. For this to work i should 
pass the filename in a regular URL like in "
http://localhost:8080/myfileserver/try.html"; . I think this has to be like 
this, I cannot pass the filename as a request parameter like in "
http://localhost:8080/myfileserver?filename=try.html"; since this way images 
will not be requested properly.
My problem is I cannot construct an url mapping in web.xml such that when 
user clicks this link: "http://localhost:8080/myfileserver.do/try.html"; I 
should be able to obtain the "try.html" part. But the default Struts action 
servlet mapping which is "*.do" does not allow this. I tried "*.do/*" but no 
way. 
How can I find a mapping such that request.getPathInfo() would not return 
"null" for me. 
Thanks in advance.


Validation :: best practice?

2005-09-09 Thread emre akbas
Hi, 
I want to know what the state-of-the-art practices about Struts validation 
are. It is well-known that there are some problems in automatic validation. 
Here is a good article: 
http://www.reumann.net/struts/articles/request_lists.jsp Are the ideas in 
this article obsolete? 
As far as I understand, the best practice is calling the validate() method 
manually. This requires that we write ... validate="false" ... in the 
action-mapping definition. However, if we do this, we cannot use javascript 
(client-size) validation. I want to use javascript validation. What are the 
possible solutions? 
Thank you in advance.