more template:include/ questions

2001-06-11 Thread Jim Richards


One of the problems I'm having with template:include/ and probably
more with the XML nature of JSP is that html:XXX form elements
have to be within html:form/html:form tags, and no in an include
used by template:include/.

I have common components that different forms use, but have to do
either a cut-n-paste(tm) or use %@ include ... % instead?

Any thoughts?


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: template:put and get

2001-06-10 Thread Jim Richards


I decided to do the second option, it works quite well. I don't like the
idea of putting the while html:img/ tag into the template:put/ because
that'd make the template file confusing for someone trying to maintain it
(the image tag would never appear in the source for the included file, the
developer could spend ages trying to work out what's going on)

JR but replace the page= with the template:get/. Trouble is you can't nest 
JR tags. One options is to do the html without the jsp, and have

JR img src=%= request.getContextPath() %/media/h_modify.gif width=315 
height=23 border=0/

JR but that doesn't look great, but I can't think of anything else. The 
template:put/
JR seems to hide the content away somewhere away in the request, and I don't want to
JR create 20 little html/jsp pages for the different headers that I have.

JR Any ideas?

You can place whole html:img tag to the template:put tag as its
content and cut content and direct attributes.

--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



template:put and get

2001-06-09 Thread Jim Richards


I've got a situation where I want to include a header file with

template:insert template=/share/inc_header.jsp
template:put name=header_image content=/media/h_modify.gif direct=true/
/template:insert

and then in the header file have

html:img page=/media/h_modify.gif width=315 height=23 border=0/

but replace the page= with the template:get/. Trouble is you can't nest 
tags. One options is to do the html without the jsp, and have

img src=%= request.getContextPath() %/media/h_modify.gif width=315 
height=23 border=0/

but that doesn't look great, but I can't think of anything else. The template:put/
seems to hide the content away somewhere away in the request, and I don't want to
create 20 little html/jsp pages for the different headers that I have.

Any ideas?



--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: JSP expressions inside custom tags

2001-06-08 Thread Jim Richards


try

html:link href=%= \/\ + name + \/index.jsp\ %

You need to have the %= % present the whole string, not just the single part.


At 10:56 AM 8/06/01 +0200, you wrote:
Hi!

I am evaluating struts for a new project. One problem I wasn't able to solve
was the integration of JSP expressions inside the attributes of
custom tags.

My code looks like this:

logic:iterate id=pelement name=MyBean property=pelements
 % String name = ((PElement)pelement).getName(); %
 html:link href=/%= name %/index.jsp
   ^^^ Here is my problem!
bean:write name=pelement property=longname/
 /html:linkbr /
/logic:iterate

The links always contain the %= name % string instead of the evaluated
expression. I tried it with different quoting techniques but without luck.

What is the correct solution here?

TIA,
Erich
 
--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: New Windows, Struts, IE 5 and sessions dying

2001-06-01 Thread Jim Richards

At 07:04 PM 1/06/01 +1200, you wrote:
Summary: Any known bugs and workarounds with Multiple Windows in IE5,
Servlet Sessions and Struts 1.0b1?

A few things to note. Have a look to see if the redirect is forcing :80 (port 80)
onto the end of the URL, this can cause the session get lost in the ether.
Upgrade to struts-b2 and it'll go away.

Another thing to note is that on NT you can have each IE run in a separate process,
which gives it its own set of cookies, which will also loose the session value.

I think it's probably the first one though, as you'd be using html:rewrite / to 
generate
the URL for the javascript, and up until struts-b2 it would add the port into the 
address
and confuse the browser. This happens in Netscape Navigator as well.


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: Potential Security Flaw in Struts MVC

2001-05-31 Thread Jim Richards


 In the case at hand, nothing stops your user from logging on (so your
 security checks won't catch anything) and then hand typing a URL with
 query string parameters that maliciously or accidentally try to change
 things in the system.  If the user is successful at doing this, it's shame
 on the app developer for listening to request parameters that you
 shouldn't.

This is a good point. I'm finding my Actions and Forms have bucketloads
(and that's the technical term for it) of 

User user;
if ((user = (User) request.getSession().getAttribute(user) == null)
return mapping.getMapping(index);

and on, and on and on. I'd like to try and find a good way to simplify this
as best that I can. (This example is required if the session times out,
other examples appear when a browser auto-fills in a URL and the
user submits it without the form fields. etc. Very bad karma in that
case.)

 Of course, you need to take other defensive measures as well (like using
 the transaction control support to avoid accidental or malicious resubmits
 of the same data).

I've seen this in the example application, is there any documentation on
using it (as best as possible).

Thanks.


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: Potential Security Flaw in Struts MVC

2001-05-31 Thread Jim Richards

At 11:53 PM 30/05/01 -0700, you wrote:
A good way of removing the bucketloads :-} from your Action classes is to
subclass ActionServlet and implement processActionPerform to do the logon
check.

It's not just for login though, that was the example I used, every action that
generates a form needs to do this. Mostly it is checking against URL
hacking.



--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: subclassing ActionServlet?

2001-05-24 Thread Jim Richards


I made a sub-class of ActionServlet an overloaded the initXXX()
method that created the connecion pool. I did this because
my database manager beans needed access to the connection
pool parameters.

The other choice is to use something like a singleton or factory
bean pattery that generates the objects (or returns an instance
to an already created one) as you need it. The down side is
it may not have the initialisation parameters it needs.

[EMAIL PROTECTED] wrote:
 
 Hello struts-users,
 
 My webapp needs bunch of beans that should be available
 all the time and accessible from all JSP pages, so I guess I
 have to create the beans at the startup time and set them to
 the application context.
 
 How should I do this? My candidates are,
 
 1) create a subclass of ActionServlet and do it there,
 2) create a subclass of Servlet (unrelated to ActionServlet)
 and do it there.
 
 Which is better, or are there any other standard ways?
 I don't see any examples that use subclasses of ActionServlet,
 and I am wondering if there are some reasons not to.
 
 Thanks in advance,
 
 - kazumi



Re: Possible to access Init Params from JSP??

2001-05-24 Thread Jim Richards



George Craig wrote:
 Yes you can. Here is how to do it:
 
 %=
 application.getInitParameter(SOME_KEY)
 %

Does this actually work? I've had report that in Tomcat and JRUN,
it doesn't seem to return the values. Has anyone used it?



Re: Architecture for a form-wizzard

2001-05-23 Thread Jim Richards


I`m building a site that uses a application form that spans over several
pages. How should I design this application?
1. With formBeans for every page
2. One formBean for the entire application form

What I find I am doing is building a separate form bean for each page
that just represents the data for that page, and having a bean in the
session the represents the data for all the pages within that transaction.

The each form has a pre-action which populates the form from the
session bean, and a post-action which sets data back into the
session bean. The post-action then forwards onto the next
pre-action for the next form.

So something like

PreForm1Action - form1.jsp - PostForm1Action - PreForm2Action - form2.jsp - 
PostForm2Action

this seems to work okay for now.


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: is it a bug of CheckboxTag

2001-05-14 Thread Jim Richards


Set the value to true in the ActionForm reset() method.

Another thing is that you shouldn't call .jsp pages directly. They
should always be called through an Action first. From the exmaple,
the subscription page is called through (I think) editSubscription.do
to populate the form, and then forward to the .jsp page.

At the top of the .jsp page you can then put something like
(and this is from memory, so I'm not sure of the exact 
syntax)

logic:notExists name=editSubscriptionForm
logic:forward forward=editSubscription/
/logic:notExists


JeanX wrote:
 
 Jim Richards wrote at 2001-05-15 14:48:00,
 JeanX wrote:
  If I uncheck a checkbox, there is no corresponding parameter pair in request.
  So I can not get the right status of certain form.
  How to resolve it ?
 
 In you ActionForm reset method you need to set all the checkbox values
 to false, as reset() is called before the form is populated.
 
 That way, the only values that get sent are the ones that need to be
 set to true, and the ActionForm is correctly set.
 
 So if I wanna some checkbox default true,
 How can I do?



Re: FW: Design Error? Bean repopulation...

2001-05-10 Thread Jim Richards


I had this problem, and worked out a solution that seemed workable.
The main thing to remember with the html:xxx/ tags is the
the name part should always be the name of the form bean, and
the property be relative to that, otherwise the BeanUtils won't
be able to repopulate the form.

I tend to store my collections in SortedMap's and use the
primary key of the database table as the index into the
SortedMap (This means, each bean has a getId() which is an integer,
and the Bean has the comparable interface to sort them). Then when
I do the iterate, I iterate over the keys of the map and return just
the Map.Entry values. Then when I do the html:xxx/ I have
something like (this if from memory, based on your code, it might
take a few hacks to get right, I think you'll need a useBean for
the retailerForm, can remember)

logic:iterate id=entry collection=%= 
retailerForm.getRetailers().getEntries().iterator() %

html:text name=retailerForm property=%= retailerBean[\ + 
((Map.Entry) entry).getKey()) + \] %/

%!-- or, if the bean identity id id, and so we use getId)( --%

html:text name=retailerForm property=%= retailerBean[\ + 
((RetailerBean) ((Map.Entry) entry).getValue())).getId() + \] %/

/logic:iterate

I use this method all the time, it works great.

Here's another message with a copy of the code I use

http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg07627.html

 - I have a number of beans held in a Vector.
 - In my ActionForm I have a two getters for this vector - one returns the
 vector and one returns elements of the vector - so something like this:
 
 public RetailerBean getRetailerBean( int index )
 {
 return (RetailerBean)retailers.elementAt( index );
 }
 
 and
 
 public Vector getRetailers()
 {
 return retailers;
 }
 
 This works fine to populate using the following type of iterate tag:
 
 logic:iterate id=retailer name=retailerForm property=retailers
 tr
 tdhtml:checkbox name=retailer property=delete//td
 tdhtml:text name=retailer property=name//td
 /a/td--
 /tr
 /logic:iterate
 
 However, it doesn't repopulate the beans when I do a submit.  This is
 because the generated html is something like:
 
 input type=checkbox name=delete
 
 rather than:
 
 input type=checkbox name=retailer[0].delete
 input type=checkbox name=retailer[1].delete
 
 which would allow my beans to be repopulated.
 
 The outcome of this is that I have to create arrays for all properties of my
 beans in my ActionForm and take the values from there.  This seems like
 bodge-heaven and not at all object-oriented.
 
 If the form can be populated directly from the beans then surely it should
 work the other way too.



Re: Initialization of Request-Scoped Objects

2001-05-10 Thread Jim Richards


No.

What I do (antd I think it this is from the example app as well, maybe
subscription.jsp) is to put at the beginning of the .jsp file (this is
from memory, don't have the code handy)

logic:notPresent name=yourFormBean
logic:forward forward=editFormCode/
/logic:notPresent

Where editFormCode is set up as a forward in the struct-config.xml file.

This way, if the form bean has not been set up, it forwards the code
through the form bean.

This technique is useful for things like checking a user bean has been 
set in the session as well.

 Jeff Trent wrote:
 
 When myAction.do is called, I have a chance within reset() to initialize my 
request-scoped objects.  However, if myAction.jsp is called instead then I can't seem 
to find a way to get initialized.  Are there any methods called in my Action class 
when the
 .jsp file is invoked instead of the .do file?




Re: Philosophical question(s) related to STRUTS

2001-05-10 Thread Jim Richards


As a profession developer I have taken to learning how to use Struts
for several reasons (besides being Java, and thus way cool).

It's free. It doesn't cost me anything to develop or deploy.

Open Source. If the development team die in a freak accident
from caffeine overdose at something like JavaOne then I can
continue to apply my own patches to it. If Oracle disappeared
tomorrow (or Cisco?) then who is going to apply patches, provide
support and have further releases?

if you end up developing your own framework, that's great
but why re-invent the wheel? Does it matter if it doesn't become
sanctioned? Your own framework won't become sanctioned? I developed
my own framework when Turbine was being developed and
discovered that amount of work it took was huge. I could have
adopted Turbine an done all the development with that (I
didn't because Turbine is huge and I was starting out with
JavaServlets, and the best way I learn is to do it myself.)



 1) Is SunMicro going to be supporting STRUTS from a financial and/or
 marketing standpoint ?
 I only saw one tiny, tiny mention of STRUTS in the JAVAONE outline of
 presentations I just got in the mail.
 That bothers me.
 
 2) If the answer to #1 is unknown, will JSP/Java serverside professional
 developers take the time to learn STRUTS and employee it in their web
 applications ?
 
 3) If the answer to #1 is unknown, will corporations and consulting firms
 decide to committ to STRUTS in lieu of their own frameworks and methodology
 ?
 
 I am wading thru the one-inch thick documentation and I must say I am really
 impressed with the work done so far.
 However, as a consultant, I must be concerned about spending too much time
 with this if it is not going to become a popular or sanctioned approach in
 the webdev marketplace.
 
 Thoughts / feedback anyone ?



Re: Forward to an Action

2001-05-08 Thread Jim Richards


Try 

forward name=success  path=/viewCategory.do/

instead of 

   forward name=success  path=/viewCategory/


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: Struts and DAO pattern. Expensive?

2001-05-07 Thread Jim Richards


 I need to confess I'm lost. The PetStore approach sounds cleaner in some
 sence, but also sounds too repetite in other, and mostly, sounds way to
 expensive (or it isn't?).

Struts uses a connection pool. So when you do a getConnection() you're
actually pulling one out from a pool of shared connection objects, so
there is no real problem with generating a new connection.

In my application I have manager objects will deal with data beans, and
these managers have methods that all look the same (open connection, select
data, build bean, close up, return). Yes it's a lot of cut and paste. I'd
prefer to have used EJBs but the project size doesn't warrant such expense
(time and effort, not money).



Re: pleae help..submit button only allows 1 parameter to be sent with the request

2001-05-02 Thread Jim Richards


Do you have multiple submit buttons, and your action treats the data differently?

You can use hidden fields, so that all the data is sent with the form
fields. Then your action can determine which fields to use based
on the valud of the submit button.

If you have the same input field name and different values then you
can either use some funky JavaScript to set the hidden fields
values, or give them different names. This second option may break
your form beans though.

At 11:36 AM 2/05/01 +0200, Dudley Butt@i-Commerce wrote:
I want to be able to send more than one parameter when the submit button is
clicked.
currently i have this...

   html:submit property=action value=Add  --- I want more
parameters to be sentis this possible?
   bean:message key=button.submit/
   /html:submit

thanx
 
--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: Why isn't ActionsErrors throwable?

2001-04-26 Thread Jim Richards


Because exceptions are slow, and can only handle one error
at a time. The design as it is, allows for multiple action
errors to be returned to a page for display.

Exceptions should be for catastrophic errors that cause
the system to barf. Having a blank password doesn't really
fit within that framework.

 The question is: Why doesn't ActionErrors extends
 Throwable? Does it make sense to make a change in the
 framework class org.apache.struts.action.ActionErrors
 and make it throwable?



Re: struts at webappcabaret

2001-04-26 Thread Jim Richards


Michael Mok wrote:
 The servlet engine to use is Tomcat 3.1.

Tomcat 3.1 has lots of buggies in it, you're better off
using a 3.2.x version or go straight to a 4.0, although
I think 4.0 is still in beta.



RE: why does struts use forward instead of redirect

2001-04-25 Thread Jim Richards


In your code you can, I don't think there is a run-time parameter between them
because it would affect code quite drastically if you switched from forwards
to redirects.

At 08:40 AM 25/04/01 +0100, you wrote:
Can you switch between the two, i.e. make struts use redirect?

At 11:13 PM 24/04/01 -0400, you wrote: 
Anyone know why struts uses forward instead of redirect?

A redirect sends a request back to the browser, thus generating another
connection between the client and server. Forward keeps it internal
to the server, which also means you can re-use the request object.

--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: why does struts use forward instead of redirect

2001-04-24 Thread Jim Richards


At 11:13 PM 24/04/01 -0400, you wrote: 
Anyone know why struts uses forward instead of redirect?

A redirect sends a request back to the browser, thus generating another
connection between the client and server. Forward keeps it internal
to the server, which also means you can re-use the request object.


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: help with JavaScript and text box.

2001-04-09 Thread Jim Richards


Try

document.requisition['requisitionLines.requiredOnDate'].value = "the new 
value";

Alex Colic wrote:
 
 Hi, I have a text box mapped to a bean via:
 
 html:text property="requisitionLines.requiredOnDate" size="10" /
 
 My form is called requisition.
 
 If I try to set the value of the text box via JavaScript I have to access
 the box via
 form.object or requisition.requsitionLine.requiredOnDate.
 
 JavaScript can't find the box due to the numerous '.'.
 
 Is there a way around this to access the box. Any help is appreciated.
 
 Regards
 
 Alex



Re: servlet context attribute?

2001-04-07 Thread Jim Richards



"Young, Wayne" wrote:
 
 Ok, that gets me closer.  I created the servlet  put the following code in
 the init() method.
 
 // Store the lookup service in the servlet context
LookupService lookupService = new LookupService();
getServletContext().setAttribute("LookupService",lookupService);
 
 I need to get access to this attribute in a class that has nothing to do
 with servlets. Is there a method call I can make?

Not really no, you might want to look up the definition of the
single design pattern. I don't have the references here, but the
basic idea is to not create the object as you done about but have

LookupService lookupService = LookupService.getInstance();

and then

public class LookupService {

private static LookupService instance = null;

public LookupService getInstance() {
if (instance == null)
instance = new LookupService();

return instance;
}
}

so you can grab the objcet any where and be assured there is
only one instance that you are sharing. You of course then need
to make sure that the methods are synchroni(s|z)ed.



Re: Newbie datasource Q

2001-03-27 Thread Jim Richards


What specific operation are you trying to do? Since you don't have autocommit
set to true, you may be having transaction problems.

I found it helpful to create a Test.java file with the same operations
as creating the datasource (with the same parameters), a connection and 
doing a sample select statement. It helped to confirm where errors
might be happening.

JOEL VOGT wrote:

 later on in a servlet I have
 
 javax.sql.DataSource dataSource = servlet.findDataSource(null);
 con = dataSource.getConnection();
 
 When I try to use this however, I get an java.sql exception :
 'no data found'



never ending iterate tag questions

2001-03-24 Thread Jim Richards


I've now got the logic:iterate ... tag to work, but I'm confused about how it
works with the collection attribute. I've seen examples for people where they
have

logic:iterate id="bean" collection="%= someObject.getValues() %"
... do something with bean ...
/logiv:interate

but the documentation


http://jakarta.apache.org/struts/api/org/apache/struts/taglib/logic/package-summary.html#package_description

indicates that it should be used thus:

logic:iterate id="bean" collection="% someObject.getValues() %"
... do something with bean ...
/logiv:interate

The difference here being the "=" inside the scriptlet for the collection attribute.
When I don't have the "=" as the documentation suggests, I get

Unable to convert a String to java.lang.Object for attribute collectio

and if I do use the "=", which seem to be the correct way, looking at the generated
Java code, I get the correct response.






--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: Confusion : Usage of Struts

2001-03-21 Thread Jim Richards

What happens to javascript
validations? Where do we fit them in the comlete
picture? 
They don't happen at the moment. Part of the Struts 1.1 plan is to look
at some forms of
autogeneration of JavaScript validation. A few people have implemented
their own system
for this.

Who takes care of whether
is it a normal application or struts application. does the container do
this ? 
There is no real difference, struts is normal ;-) When the web container
is set up it
need to know that a path ending in .do is part of struts, as are .jsp
pages.

If we have to code the
struts-jsp and a corresponding bean for every form then where is the
convenience ? Are we not trading one problem with
another.
I'm not sure what you mean, but there is some shortcut
methods you can handle with
the form input/output part. If you read the taglib documentation you'll
see examples
of this.

Under what circumstances
do I need to extend ActionServlet and use that ?

When you need something that it doesn't provide. For example
I extend ActionServlet to
implement setting up singleton objects for database access.

I have a gut feeling that
struts application will be slow as it involves one extra component at the
server side for every single GUI developed ? 
Milliseconds slower ;-)

Can some body who is
deeply involved with struts development reply.

I'n not that deeply involved, but they are valid questions.


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html




RE: Alternative Frameworks - continued

2001-03-21 Thread Jim Richards

At 10:25 PM 20/03/01 -0800, you wrote:
Eric,
Have you looked into ASP.net vs ...?

The main problem there is that a lot of the development tools are
beta, and finding an ISP that will host it is also difficult. It will
be at least 12 months before it has settled down.


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: PostgreSQL problems.

2001-03-17 Thread Jim Richards


I've finally got the problem sorted out. It was rather obscure, but I think
I could have only solved it because of the "Joy of Open Source(tm)".

When I built my postgresql.jar file, I only put .class files into it, not realising
there were some error_xx.properties file to be put in as well. I was getting
an error during ActionServlet loading because there are documented "not supported"
errors that would throw an SQLException, but since the error_xx.properties was not
there an extra NullPointerException was being thrown (because the ResourceBundle
was null, because there were no .proerties file) and this rippled through the system
and broke init().

I've rebuilt my postgresql.jar file and the system loads, I can access the database
and we'll all live happily ever after.


At 11:30 PM 14/03/01 +1100, Jim Richards wrote:
At 01:28 PM 14/03/01 +0100, you wrote:
We are currently using PostgreSQL as a database in a productive system together
with struts. We tried with Interbase before, but ran into many many
difficulties. So we switched to PostgreSQL and everything went well from then
on. 

What specific kind of problems do you have?

See

   http://nagoya.betaversion.org/bugzilla/show_bug.cgi?id=827

--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



PostgreSQL problems.

2001-03-14 Thread Jim Richards


I'm still getting problems with PostgreSQL (documented previously several
times). Has anyone used it successfully as a database.

Yes, I've got the settings correct, the JDBC string correct, lots of other
things. I really need someone who actually has it working to put their
hand up and say "yes, it does work, this is how I did it."

Thanks.


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: PostgreSQL problems.

2001-03-14 Thread Jim Richards

At 01:28 PM 14/03/01 +0100, you wrote:
We are currently using PostgreSQL as a database in a productive system together
with struts. We tried with Interbase before, but ran into many many
difficulties. So we switched to PostgreSQL and everything went well from then
on. 

What specific kind of problems do you have?

See

http://nagoya.betaversion.org/bugzilla/show_bug.cgi?id=827


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: PostgreSQL problems.

2001-03-14 Thread Jim Richards

At 01:51 PM 14/03/01 +0100, you wrote:
This does not sound at all like a PostgreSQL problem.

Doesn't the error also show up, when you remove the datasource section?

No. That's the catch, it loads and runs if there's no datasource
section in the struts-config.xml file (although you need to comment
out the database code, or not access it).


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: Business Object Bean Persistence Strategies

2001-03-08 Thread Jim Richards


My approach is to have:

JSP - Struts Form/Action  - Business Rules  - Database

The busines rules are set up as singleton object on servlet
startup. I've subclassed the ActionServlet and overloaded
the datasource init method, there I set up the four business
rule classes and put them into application scope, on
creation the business classes get their datasource reference.

The objects I pass around are data beans that model the database
closely (similar to entity EJBs). 

So for logon, I have a User() object where I set the
user_id and password from the logon form, then the action
class will call User user = UserManager.logon(User user)
which will either find the user and return a fully filled
user object or throw and exception (I might change that though).

UserManager has other methods for logoff, update and create. So the
action code doesn't need to send the dataconnection because
that ties the Action too closely to the data store (what happens
if the authentication changes to LDAP or unix password/username
or database password/username?).

It also means I can reuse the business rules for another project
that might not be struts based. (But whay would I do that ;-)


Michael McCallister wrote:
 
 What strategies or patterns do people use to manage persistence of business
 object data in a Struts application when there is no EJB layer and there is
 a desire to keep the business objects as independent of the web portion of
 the application as possible?  Do you use the Struts DataSource and pass
 either it or a Connection as a parameter to bean methods that take
 responsibility for managing persistence?  Do you follow the J2EE blueprint
 and create separate Data Access Objects to support persistence?  Are you
 using an open-source framework to manage persistence?  This seems like a
 common problem, but I haven't seen much talk about common solutions.
 
 Mike



Database pooling code

2001-03-07 Thread Jim Richards


Has anyone got the database pooling code/DataSource to work or specifically
had it fail?

I've been having problems (documented previously) and I've read about a few others
who can't seem to get the pooling to work as well, and I want to get an idea
of specifically where the problem might lie in order to fix it.





You are the simulacrum of my dreams
 and the signifier of my desires

Mr Grumpy ... come and visit his home!
http://www.cyber4.org/members/grumpy/index.html



Re: startup problems

2001-02-28 Thread Jim Richards


I've now got the beta-1 build and it works fine with the PostgreSQL driver,
which I'm very happy about.

Mosy things seem to be working fine, I've got my own ActionServlet extending
the base one, overloaded the initDataSources() method so I can create my
own database singleton objects for reference within each Action, to access
the database.

All is well. For now.

I think what might be useful for me now is getting some time together to
read all the new documentation again.

Jim Richards wrote:
 
 I'm sure earlier today when I started with the new version I didn't get the load 
error, and
 something I've done has freaked it out. But as you'll see I haven't done that much 
to
 freak it out.



Re: Stupd question about Struts and EJB.

2001-02-27 Thread Jim Richards


EJBs come in two flavours (as opposed to flavors), session beans and entity
beans.
Session beans represent business logic and rules, entity beans represent a
row in the database.

The model that you'd use is to have Actions do the basic processing of form
elements into data beans (just regular beans, nothing special), but no business
rules.
The Action then calls a session bean with the data bean to do something 
(eg. usdate user details in the database). The session bean connects to the
database with an entity bean (or more than one depending on the database
structure).

Visually, you'd have

JSP =  Action  =  Session Bean= Entity Bean  = Database

Hope that helps.


At 06:37 AM 27/02/01 -0500, you wrote: 

 I am in the process of convincing my company to go with MVC and Struts. As
 with any thing new, people are sometimes resistant 
 to change. One of the opposition questions I am getting is, how will this
 work with EJB(problem is I don't know too much about EJB currently).  Do the
 EJB's references just go in the Form and Action Bean and every thing else
 behaves the same? Are there any obvious points that I can bring up on the
 subject? 
 Any help on this subject would be much appreciated!
  
 Thanks, Cameron Ingram



--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: more than one formclass for a one jsp ?

2001-02-24 Thread Jim Richards

At 07:37 AM 23/02/01 -0500, you wrote: 


 Hi, 

 I wanted to have more than one form class for   a  one jsp file.  Because in
 my one jsp file,  i have a information of 4 tables. So i want to transfer the
 information to 4  formclasses?  Is it possible?


If what I think you are doing is wanting to have the four form classes
handle all the data from a form in one go, no I don't think so. A form can
only have one action attribute, so there's no way to split the data appart.

You can have four forms within the jsp page, and each one has it's own action, 
but only one can be used at a time. You won't be able to submit to all four at
once.


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: database locks.. (OT)

2001-02-20 Thread Jim Richards


The usual thing to check for are: Are you using the
database conneciton pool? Are you closing your database
connection? Do use you transactions at all? Do you commit your
work? Do you have autocommit turned on?

Anand Raman wrote:
 I am trying to implement a multi page form and in some scenario the
 application is hanging because of a database lock which is not going
 away after some DML.



Re: startup problems

2001-02-17 Thread Jim Richards


I'm sure earlier today when I started with the new version I didn't get the load 
error, and
something I've done has freaked it out. But as you'll see I haven't done that much to
freak it out.

I think I'm onto something now. I commented out the database connection
code I had:

data-sources
data-source
autoCommit="false"
description="Cyberlancers Data Source Configuration"
driverClass="org.postgresql.Driver"
maxCount="10"
minCount="1"
user="grumpy"
password="grumpy"
url="jdbc:postgresql://dbase.home.cyber4.org/cyberlancers"
/
/data-sources

And now it doesn't get the error. Which is really odd because the startup comment
with Tomcat indicated it loaded without a problem. The database is running, and
the postgresql driver is in the CLASSPATH of tomcat.

New org.apache.struts.util.GenericDataSource
Set org.apache.struts.util.GenericDataSource properties
Call 
org.apache.struts.action.ActionServlet.addDataSource(org.apache.struts.action.DATA_SOURCE,
 GenericDataSource[activeCount=0, autoCommit=false, closed=false, 
description=Cyberlancers Data Source Configuration, driverClass=org.postgresql.Driver, 
loginTimeout=0, maxCount=10, minCount=1, password=grumpy, readOnly=false, 
url=jdbc:postgresql://dbase.home.cyber4.org/cyberlancers, useCount=0, user=grumpy])
Pop org.apache.struts.util.GenericDataSource

The url and username/password works with the JDBC test that come with PostgreSQL 7.0.3 
that
I'm using, and other simple tests that I've done.



You are the simulacrum of my dreams
 and the signifier of my desires

Mr Grumpy ... come and visit his home!
http://www.cyber4.org/members/grumpy/index.html



Re: AW: JDBC Connection Pooling

2001-02-15 Thread Jim Richards


I'm trying to do the same thing here, but I'm not sure on a few
of the details.

I've got a servlet called DatabaseContainer, which will handle all
the database connections and populating Beans to send back
to the Actions.

What I can't work out is, once I've get the DataSource, how does the
Action know about the DatabaseContainer? At the moment I've
got 

getServletContext().setAttribute("DatabaseContainer", this);

and so in the Action, I can call

DatabaseContainer database = (DatabaseContainer) 
servlet.getServletContext().getAttribute("DatabaseContainer");

But this doesn't seem right. Since Craig doesn't like singleton objects
hanging around, and I don't feel like I want to extend ActionServlet,
this seems like the only way (since getServlet() is depreciated in the
2.2 spec).

Any ideas?


 The problem I'm facing is a bit diffrent as I want to access the
 Connection Pool from a servlet that is started upon startup
 of the servlet engine (similar to the struts example application).
 In order to be able to access the DataSource, I tried to subclass
 the ActionServlet class and to access the data source that way.
 However, my servlet engine (Tomcat 3.2.1) complains that it is unable
 to start this new Action servlet...

 Any ideas how to solve this problem?

There are three things you will need to do:

* Make sure that both the Struts controller servlet and your own
  servlet are marked load-on-startup.

* Use values for the load-on-startup attribute that cause the
  Struts controller servlet to be initialized first (for example, use a
  "1" as the value for the controller servlet, and "2" for yours).
  I'm not positive that Tomcat 3.2 respects this, but it is supposed to.

* The Struts controller servlet makes the data source it initializes
  available as a servlet context attribute, as well as available via a
  method call.  You can therefore grab it by calling:

DataSource ds = (javax.sql.DataSource)
  getServletContext().getAttribute(Action.DATA_SOURCE_KEY);

  in any other servlet (or JSP page) that is part of the same web app.



--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: Help with Exception

2001-02-15 Thread Jim Richards


  Sorry about not cutting out the previous messages, but the
  discussion is sort-of relevant to what I'm having problems with.
  I'm getting
 
  javax.servlet.ServletException: Cannot find ActionMappings or 
ActionFormBeans collection
 
  I can run the example, and I can run a test page with nothing but
  a few tags (eg: html:html) but no forms/beans/etc. And I get the
  above error. I've checked struts-config.xml.
 
  I can only think I've missed something.
 
 
 Have you configured the controller servlet to be load-on-startup?  If you do not 
do this, none of
 the servlet context attributes created by the controller servlet (including the two 
mentioned in the
 exception) will have been created if the first request you submit is to a JSP page.
 
 If that's not the issue, what servlet container are you running on.  Some have 
problems with
 load-on-startup -- check the installation documentation for platform specific 
details.

Yes, sorry. I'm using Tomcat 3.2.1 on Solaris, with J2SE 1.3. I have load-on-startup
set to 1 (and my database container set to 2). I get an odd error when Tomcat starts
in that it says (and this is from memory, don't have the extact message here) it
can't load servlet: action. Now I assume this is the action servlet that is the
struts one in the web.xml. But, it was a cut and paste job with modifications
from the example web.xml, so I'd expect it to work. The servlet mapping seems
correct.



Re: EJB references

2000-12-06 Thread Jim Richards


You probably need to create a helper class that does all this work, 
keeps the references as public variables and create it as a singleton in
the init of the servlet, and store it as an application wide variable
so you can access it easily and have references to all the session beans.

I can't remember the deal though with synchronisation and EJBs, you
had better check on that as there will be a high possibility of 
multiple threads (servlets) accessing it at the same time.

At 08:37 AM 6/12/00 -0800, you wrote:
Hi Jim and Alex,

I think both of you understood me wrong. I am not planning to access EJBs
from JSP pages at all. I will have a lot of session EJBs to manipulate
Entity EJBs. But, the suggested approach accessing them from servlets was:

[snip ...]
--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: EJB references

2000-12-05 Thread Jim Richards


I'll be using ELB's for my application when I start building it
in a few weeks time (still in the design stage). I expect to
be using only EJBs from a action servlet, that are session
beans, and those session beans use entity beans. From previous
work I found there was too much overhead using the entity beans
directly in the generation of a html page, and you rarely
needed that direct conncetion to the database anyway.

As for the references, I'm not sure what you mean. I'll be putting
things like the JNDI and connection information into to web.xml
as startup parameters.

"Boulatian, Misak" wrote:
 
 Hi all,
 
 The application we design is quite large. I am still trying to figure out
 the question on EJB references. From the Craig Mcc.'s comment I could put
 those in one startup servlet. Is it a viable solution? I am going to have
 many session references. Where am I going to store those references (in
 servlet context)? How can I make those available to action classes? Or I can
 put only the handle in the servlet context and call lookup in every action
 class (any scalability problems with this approach?). I cannot believe that
 none of you worked in large applications and will not be using EJBs for
 business logic and did not go over this kind of issue.
 
 I appreciate response,
 Misak Boulatian



Re: Question about errors tag

2000-12-05 Thread Jim Richards


[big snip ...]

 Is there another way to accomplish the same thing, without tacking the error
 on to the redirect URL?

Probably not, no. I can't see where you'd store the errors. In the session
would cause problems with synchronisation, and on the redirect URL
could cause buffer problems (with more then 1024 bytes of errors).

You could store it in the session, if you used a unique identifier
to store them, and pass that identifier through to the redirected
URL.

I'd think you need to look at *why* you don't want the action URL
displayed in the first place. You could always be sneaky and use a
hidden frame to force the URL to always be the same.



Re: Nesting form inside ifParameterEquals

2000-12-05 Thread Jim Richards


You can use java script. I posted a message about this 
to the struts-dev mailing list a few days ago. I don't
have the email, but you can find it in the mail archives,
which I don't have a reference for either.



 Nikolaus Rumm wrote:
 
 Hello,
 
 what I wanted to do is...
 
 struts:ifParameterEquals name="action" value="create"
struts:form action="/html/user/storeUser.do?action=create" name="userForm" 
type="com.kephera.scivent.client.participant.UserForm"
 /struts:ifParameterEquals
 struts:ifParameterEquals name="action" value="edit"
struts:form action="/html/user/storeUser.do?action=edit" name="userForm" 
type="com.kephera.scivent.client.participant.UserForm"
 /struts:ifParameterEquals
 
 However, under struts 0.5 the tag's body and thus the form tag is not evaluated, but 
the whole page is skipped. Is there a way to dynamically alter the action of a 
struts:form tag ?
 
 Regards
 
 Nikolaus



Re: Article on JavaWorld

2000-12-05 Thread Jim Richards


If you're prepared to be patient, I need both of these, and
can work on them but I won't be able to start unitl January
on the development of it.

The AutoBean idea (as an idea) is something I use already
in Cold Fusion, and have done before in PL/SQL.

The client side validator, as I posted before I have a good
JavaScript validation library I can use, and am happy
for it to be included.


"Craig R. McClanahan" wrote:
 The "AutoBean" concept has been requested several times, often in the guise of
 "beans with dynamic properties" so that you don't have to create a form bean
 with individual getters and setters.  I'd like to explore this concept in depth
 in Struts 1.1, which will give us time to make sure that a complete and coherent
 set of support for such beans can be included (for example, all the custom tags
 that know how to extract bean properties should now how to extract them from an
 AutoBean, without the page developer having to do anything).
 
 The "Validator" concept is interesting.  Besides the server-side format checking
 that is being done here, I would also like to see the option for the form tags
 to generate client-side JavaScript code (if requested) to check as many things
 like this as you can on the client side, to improve the user experience.



Re: Submitting forms to alternate actions

2000-12-04 Thread Jim Richards


With JavaScript you can specify the form action, so you'd have 
something like:

form name="aForm" action="defaultAction.do" onSubmit="return 
checkSubmit(this);"
input type="submit" name="button1" value="use default action"
input type="submit" name="button2" value="use other action" 
onClick="document.aForm.action='otherAction.do';"
/form

You can also mess around with the form onSubmit action, but I was
having trouble trying to determine which button was clicked through
that method. This seemed a lot cleaner.


Steven Peterson wrote:
 
 Hi all:
 
 I have used struts to set up a simple application.  My problem comes up
 when I want to submit a form to different actions, depending on which
 button the user presses.  If the contents of the form were not
 important, I could simply GET a different URL (each mapped to a
 different action) for each button.  However, when I need the contents of
 the form so that the form must be POSTed, then I am stuck --  as far as
 I can tell, there is only one url that a form can be posted to.   Is
 there a way to override the form's coded post action based on which
 button is pressed?
 
 - Steve
 
 --
 Steven Peterson, President
 Frontier Productions, Inc.
 310 Wesley Drive
 Chapel Hill, NC 27516
 http://www.frontierproductions.net
 Tel: 919-942-1386
 Fax: 919-933-2677



Re: book ideas

2000-11-30 Thread Jim Richards


I'd prefer (and this is personal preference only) more on the development of
models and application frameworks then actual introduction code.

Coverage of PostgreSQL as well (it has transaction, which are quite
crucial to the EJBs, otherwise you get MySQL's serialised table locking
which is not great).

Use of EJBs through the MVC framework. Where to use session
beans (both types) and when to use entity beans (ie. should
entity beans be attached to the session object (no, not really)
but only accessed through the session beans, and the session beans
return ordinary Java Beans to the servlet.

Security context in relation to attaching a profile to the 
whole application.

Not a reprint of the documentation that comes with any of the main
downloads, as this just duplicates content and kills more trees.

Other EJB/J2EE containers (eg. Enhydra/Jonas).

Wait till Tomcat 4.0 is stable and Struts 1.0, otherwise you'll
have major dead space in the book.

(Although a paper book will always be somewhat out of date)

If you focus on frameworks/ideas/concepts rather then deep
examples you'll find the book lasts a lot longer, which is
why Knuth's books are still valid resources today but my
Java 1.0 Beta2 books are wasted space.


At 10:59 AM 30/11/00 +0100, you wrote:
Hi Everybody,

I'm (already) working in a book in JSP and Tag Libraries development for New
Riders Publishing.
The idea of the book is:

- An introduction on Servlets and JSP
- Deep in Tag coding
- Design and Architectural issues (major challenges when designing web apps
with Servlets, JSP, Pet Shop Model 2 approach, Struts Model 2 approach, the
role of tags in process encapsulation and reuse, how tags affect system
design and how the Servlet/JSP architecture responds to that, etc.). EJBs
are treated as subsidiary (calm down!) since it's too broad a subject and
very well covered in many other books.
- Deep in Struts (a couple of chapters to discuss the model, the usage
scenarios and of course the taglibs)
- Jakarta Taglibs (a broad coverage)
- Commercial taglibs (the commercial case)
- Appendixes on TOMCAT (I focus in TOMCAT), MySQL, Caucho Resin and Jrun
(examples are provided also on these), jBoss
- Many, many, MANY examples on everything.

Questions are:

1. What do you think of this coverage ?

2. What would you like to see on paper ? My sources on the design issues are
a number of articles (for instance that one from Jason Hunter questioning
JSP), some reference books and the lists (not to mention experience, of
course). 

3. On the side of Struts, what do you like to see there ? What do you think
is not yet said or well said about Struts ? 

4. And on the design issues on Servlet/JSP architecture(s) ?

Thank you all for your attention on this,

Wellington Silva
UN/FAO


   
 
--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Re: HttpSession.getAttribute() missing?

2000-11-27 Thread Jim Richards


Then you've got the wrong .jar file in your classpath, or earlier
in your classpath.

You can either edit your CLASSPATH environment variable setting,
or remove the offending .jar file from your system. You'll then
need to include the correct .jar file (depends on your server
setup) that includes the latest classes.

What server are you using?

 The HttpSession it's going after is in the Jswdk version 1.0.1.Could it mean 
putValue() instead?



Re: need some explanations

2000-11-23 Thread Jim Richards


It's really only for an example. It you want real
object persistence, you'll need to develop your
owne layer. Something like EJB's will make this much,
much easier. Or some direct JDBC code perhaps.

Vilavanh Messien wrote:
 
 I analyzed the struts example in order to develop my own small application.
 Unfortunatelaty, I don't really understand how the user's information are
 saved
 in the "database.xml" file.
 The DatabaseServlet must write the information in the "database.xml" when
 the destroy() method
 is called.
 My question is how to make the destroy() method perform ?
 
 How can I do to pass some arguments to the DatabaseServlet ?
 
 Thanks
 
 Vilavanh



Re: Struts + Design Philosophy

2000-11-21 Thread Jim Richards


 users. What I am asking is, will STRUTS gracefully support a 2 stage
 approach to forms - 1 stage to construct and fill in values, and a second
 one to gather responses and process ?

This is something I am looking at, have a look at the
simple JavaScript validation page I posted yesterday
(well, yesterday my time).

I think we can improve on the ActionForm.validate()
style of doing things.





Re: thought on design

2000-11-21 Thread Jim Richards


 In 1.0, the validation model for the server side has been significantly enhanced.  
The
 idea of auto-generating JavaScript validation code for the things you can check on 
the
 client side is attractive, but won't make Struts 1.0 (unless someone really hurries
 and creates it :-).

Hmm ... I am using a nightly build from about a week ago,
I'll have to dig into it to see how this enhanced validation
works (or is it not in there yet).

 I would caution you that, even if you implement client-side JavaScript validations,
 your server side logic should not rely on them.  After all, the user can easily turn
 off JavaScript, and/or write an application that simulates a browser's interactions
 with the server but tries to bypass your edits.

The client side validation is only for simple things,
that validate() would do, such as checking for number
format, empty strings, valida credit card number, post
code and so on. The action bean would still need to check
that, say a credit card was valid (rather then just a number).

 Also, I couldn't work out how to get the request attributes
 to be sticky between the next and previous pages (think CGI.pm
 and it's param() functions). It's probably something to do
 with the response, but I don't have the docs handy.
 
 
 Sticky checkboxes have been fixed in 1.0 by adding a reset() method to the ActionForm
 class.  You should reset any boolean properties to false in the reset() method, which
 is called before the property populator -- which will set the checkbox back to true 
if
 it was indeed checked.

Hmm, I was thinking more about text fields and so on
between multipage forms, not rebuilding the current
form with the previous data.

 I will take a look at your example, but there is a subtle philosophical issue that 
has
 affected the way ActionForm beans are specified in Struts.
 
 Basically, an ActionForm is part of the presentation layer, not the model layer.
 Their primary purpose is to encapsulate the current set of inputs that a user last
 entered -- whether or not they are valid -- so that you can create an error page that
 faithfully represents what *was* entered, and points out what needs to be changed
 (just like GUI apps do).  Otherwise, you're going to force the user to have to
 re-enter some of the fields, and that will not make you a popular person with your
 user community.

I suppose what I'd like is rather then having validate()
being called, when each property has it's setXXX method
called, the setXXX method does the simple validation, and
throws a ProperyVetoException with the error message
text as part of the Exception. Then if a try block
cathces this, stacks up the error messages and calls
the page again with these errors. It seems that from
what I've seen, most validate() methods are the same.









Re: Pages being cached

2000-11-21 Thread Jim Richards


(This has been cross posted to tomcat-user, as it seems to be a
tomcat issue rather then a struts issue.)

I have found that this behaviour is *not* replicated when using 
Tomcat's built in HTTP server. I need to do some deep
experimentation, and install tomcat-3.2b8 as well.

I'll let you all know how it goes.

 I'm getting weird behaviour with my struts code, and with the example
 application.

Once during testing I noticed that pages seemed to be served at random..
Then I shut down httpd and then shut down tomcat.
Thereafter I restarted tomcat and then restarted htttpd.
Then everything worked.

So I've concluded that when I want to restart tomcat, I've to
first stop httpd, then tomcat, then start tomcat and then start httpd.

I'm not sure if I should restart tomcat when I just want to restart httpd.

I have to restart Tomcat and Apache to get anything to work. It doesn't
help. Once my application has compiled the three pages it has in it,
(that is viewed them) it starts freaking out. Going through the documentation
doesn't seem a problem, so long as that's all I do. It happens with the
example application, with everything.


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html



Pages being cached

2000-11-18 Thread Jim Richards


I'm getting weird behaviour with my struts code, and with the example
application.

Currently I've got Tomcat 3.2b6 running, with the latest nightly build of 
struts (17-11-2000, that's the 17th November, 2000) and the examples,
documentation and test data all run. (Which I must say, took a very
long time to get a configuration other then a standard install right.)

JDK 1.3, Solaris7 ... all the latest patches.

(On a side note, I don't think tomcat loads .war files unless then are
in the $TOMCAT/webapps directory and the AutoLoad interceptor
is turned on.)

I have virtual hosts set up, and contexts usually set as something sensible
(usually /context). I've got Apache web server and mod_jk.

I've found that after loading about 2 or 3 pages from the example, or my
own (three page) application, pages start coming out of order, just 
by clicking on links or submitting forms. The weirdest behaviour is when
I might be viewing the documentation on one virtual host and context, and a
page from my example application (on a different virtual host and context)
will appear in its place. Or the example application will appear instead
of my application.

It's not the browser because I have the cache set to zero, and for it to
compare the document on the network to local every time.

Anyone seen similar?


--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html