Re: Programmatic Validation in Action

2007-06-11 Thread Caine Lai

I hope this code:

public void setAttribue(String attr)
  {
 this.attribute = attr;
  }

Is a typo?  If not, this is why your attribute is not being set in your
action class.

Also, since you are forwarding to the same page regardless of success,
failure and input... are you sure it is actually failing and returning
INPUT?


On 6/9/07, Matt Luce [EMAIL PROTECTED] wrote:


Has anyone attempted to use programmatic validation in Struts 2?  When I
add an actionError and return INPUT, it properly goes back to the page
with the form, but it does not keep the values that I typed.  Shouldn't
that work?  This is how it worked in Struts 1.


package com.company.action;

import com.opensymphony.xwork2.ActionSupport;


public class ExampleValidateAction extends ActionSupport
{

private string attribute;

public String execute() throws Exception
{

// complicated validation logic.  Too complicated for xml
validation
this.addActionError(Validation Error);
return INPUT;


}

public string getAttribute()
{
   return attribute;
}

public void setAttribue(String attr)
{
   this.attribute = attr;
}

}




Re: Ending session

2007-06-05 Thread Caine Lai

Probably the easiest way to do this would be to have a very short session
timeout period (5minutes?) set on the server.

You could then have a JavaScript function that polls the server every 5
minutes.  Each ajax request made by the JavaScript will reset the session
timer on the server.

On 6/5/07, Mansour [EMAIL PROTECTED] wrote:


I am saving objects in the session. After the browser closes I would
like to clean the remaining junk. How do I achieve this ?


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How does one use lazy loading in Struts 2 with container managed persistence?

2007-06-04 Thread Caine Lai

Thanks Jeromy,

This was exactly what I was looking for.  Very helpful.

I was able to create a transaction in the web tier using a JNDI lookup of
the UserTransaction.  The transaction spans the entire request as needed.

It still troubles me that any problems with the transaction commit will not
be catchable since the response will have already been committed by the time
the transaction is committed.  JBoss Seam looks like it is the only
framework that has solved this problem, but I'm not at all interested in
using JSF.

Does anyone know if the same implementation can be built into a Struts
interceptor?

Thanks,
Caine

On 6/4/07, Jeromy Evans [EMAIL PROTECTED]  wrote:


To investigate this further I created an S2




webapp deployed within a

JBoss 4.2.0 container using EJB3 stateless session beans and JPA entity
beans.

First of all though, if you use JPA in standalone mode you can use the
open session in view pattern as discussed in prior emails.  This
question relates to container managed persistence where you don't have
the same luxury of creating your own EntityManagerFactory within the
webapp.

My short answer is: though is that Struts2 does not introduce any new
limitations.  You can use struts2 within an EJB3 container with CMP and
lazy loading within the JSP the same way you do with with any other
webapp within an EJB3 container.  You have to lookup the PersitanceUnit
in an interceptor as described at [1].

My long answer:

Test scenario;
I created an S2 action that looks up an a remote session bean to find a
list of books. The session been performs a simple EJB-QL query (select
book from Book book)
Each Book is an Entity with a @OneToMany relatinoship to a BookAuthorMap
which in turn has a @ManyToOne to an Author.  ie. effectively a
many-to-many relationship directed from book to author to provide a
genuine lazy-loading opportunity.
My action has a property ListBook getBooks()
My JSP result displays the list of books found, with an inner iterator
to display the list of authors mapped to each book.

Effectively, each inner iteration causes a lazy load of the referenced
map and Author if the entity's not already cached by the EntityManager.
Simple enough?

Here's my summary:
a. as you'd expected, you can't use EJB3 DI within your S2 actions
(@PersistenceContext, @Resource, @EJB)
However, you can use JNDI so there's no reason why these can't be
supported via an explict S2 plugin or interceptor.
Easy options are:
   - write a custom annotation and interceptor as discussed at [2]
   - use a Guice object factory with a JNDI provider to inject
   - use a Spring object factory to do the same thing
   - write a Struts2 EJB3 plugin to recognise @PersistenceContxt,
@Resource @EJB in actions and inject them
(my action simply created an InitialContext and looked up the EJB
session bean0

b. As you would expect, the container determines that the transaction is
over when the ejb call ends and the entities become detached from the
EntityManager  So lazy loading is not available in the action (or JSP),
but this was when it occurred to me that this is in no way related to
struts2 - it's the same problem that exists in stand-alone JPA, and the
same problem exists for plain JSP, or plain servlets, struts1 and pretty
much anything else in an EJB container (except perhaps JSF backed by
managed beans, which I don't know anything about).

So the question is not whether struts2 has a limitation - it doesn't.
The question should be how you can extend the transaction down into the
web-tier in an EJB environment.

And the answer is simply to use JDNI to lookup the PersistenceUnit in an
interceptor or filter - the same as you do for stand-alone mode except
using a lookup.  I haven't tried yet, but its described at [1].

Hope that helps,
Jeromy Evans


References:
1.

http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html
2.
http://www.nabble.com/Re:--s2--Struts-Dependency-Injection-and-EJB3---support---or-how-can-i-Do-it--p8512920.html



Caine Lai wrote:
 Hi Jeromy,

 Thanks for your response.  It sounds like your solution works, but it
 doesn't seem like this would integrate with container managed
persistence
 very well.

 It's strange this is so difficult to achieve in the next generation
 struts.  I don't know why JPA/EJB3 is an afterthought.  I really don't
 want
 to abandon Struts 2 at this point since it was exactly what I was
looking
 for except for this one very large issue.

 I'd still be very interested in hearing from anyone that has thought
 about
 or solved this problem of using Struts 2 in a managed environment.

 Thanks,
 Caine


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: [ANN] Starting with Struts2 Book

2007-06-02 Thread Caine Lai

Hmmm... I registered but when I try to download the book I get a window that
tells me I'm trying to access a resource...(can't read anymore cause the
window is not resizable) message.

On 6/1/07, Volkan OZYILMAZ [EMAIL PROTECTED] wrote:


Thank you for this very useful and public ebook :)



On 5/31/07, James Mitchell [EMAIL PROTECTED] wrote:

 Will do!  Hope you can make it.


 --
 James Mitchell



 On May 31, 2007, at 11:41 AM, Ian Roughley wrote:

  No, no paypal account.  You can buy me a beer if I make it to
  apachecon.
 
  James Mitchell wrote:
  Ian,  Nice job!  I don't need the paper copy, but I'd like you to
  get the full price of the book.  Do you have a Paypal account that
  I could donate some funds to?
 
 
  --
  James Mitchell
 
 
 
  On May 29, 2007, at 12:13 PM, Henri Yandell wrote:
 
  The registration system at InfoQ is pretty slow; so I downloaded
  directly from lulu.com.
 
  Great work Ian, I hope it becomes the 'Thinking in Struts2' and is a
  big success.
 
  Hen
 
  On 5/25/07, Ted Husted [EMAIL PROTECTED] wrote:
  Is anyone else having trouble logging into the InfoQ site?
 
  On 5/24/07, Ian Roughley [EMAIL PROTECTED] wrote:
   I am pleased to announce the release of the mini-book
  Starting with
   Struts2 from InfoQ.com.
  
   Starting with Struts2 is aimed at those who are new to
  Strut2, and
   those familiar with MVC frameworks but unfamiliar with
  Struts2.  It
   provides everything you need to know to get up and running using
   Struts2, and can be used as a starting point to explore the more
   intricate features of the Struts2 framework.   Topics include
   architecture and configuration, how to implementing actions, and
   supporting infrastructure such as validation and
  internationalization.
   Also included are productivity tips, providing a practical
  introduction
   on how best to use the framework.
  
   The eBook can be found at http://www.infoq.com/minibooks/
  starting-struts2
  
   /Ian
 
  ---
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
  
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




--
--
Volkan OZYILMAZ
Volko
http://www.volko.biz
--



Re: How does one use lazy loading in Struts 2 with container managed persistence?

2007-06-02 Thread Caine Lai

No one?  This seems like a major design flaw in Struts 2, if there is no way
to use lazy loading in Struts 2 using JPA.

I've read something online that describes it may be possible to write a
custom interceptor that can scan for annotations and inject the persistence
context into a struts action.  But without framework support for JPA (built
in), how can Struts 2 ever be taken seriously?  Isn't EJB3 and JPA the
current standard spec?

I'm not at all interested in using Spring either.  And quite fankly I
shouldn't be forced to use Spring purely for the Open Session in View
pattern.

Thoughts?

On 6/1/07, Caine Lai [EMAIL PROTECTED] wrote:


I'm using EJB3 stateless session beans/JPA/JTA to manage my data access.
But I can't figure out how one would use lazy loading in this scenario since
any transaction opened in the EJB layer will already be committed prior to
rendering the view.

Any tips?

I'm familiar with Open Session in View when using hibernate, but it's
not quite the same when I'm using container managed transactions and
dependency injection in EJB3.  Or is it?  Would I still open a hibernate
session within the view and close it after the view is rendered in this
scenario?

Thanks for any pointers.



Re: How does one use lazy loading in Struts 2 with container managed persistence?

2007-06-02 Thread Caine Lai

Hi Jeromy,

Thanks for your response.  It sounds like your solution works, but it
doesn't seem like this would integrate with container managed persistence
very well.

It's strange this is so difficult to achieve in the next generation
struts.  I don't know why JPA/EJB3 is an afterthought.  I really don't want
to abandon Struts 2 at this point since it was exactly what I was looking
for except for this one very large issue.

I'd still be very interested in hearing from anyone that has thought about
or solved this problem of using Struts 2 in a managed environment.

Thanks,
Caine

On 6/2/07, Jeromy Evans [EMAIL PROTECTED] wrote:


Hi Caine,

I use JPA. I place the EntityManagerFactory into the application context
so it can be accessed by an S2 interceptor.
The S2 interceptor creates an EntityManager for each request as per the
open session in view pattern and so lazy loading can be used where
appropriate.
This doesn't qualify as CPM though which is what you asked for. I
haven't tried using S2 with an EJB container yet.

There's no need to use spring.

cheers,
Jeromy Evans

Caine Lai wrote:
 No one?  This seems like a major design flaw in Struts 2, if there is
 no way
 to use lazy loading in Struts 2 using JPA.

 I've read something online that describes it may be possible to write a
 custom interceptor that can scan for annotations and inject the
 persistence
 context into a struts action.  But without framework support for JPA
 (built
 in), how can Struts 2 ever be taken seriously?  Isn't EJB3 and JPA the
 current standard spec?

 I'm not at all interested in using Spring either.  And quite fankly I
 shouldn't be forced to use Spring purely for the Open Session in View
 pattern.

 Thoughts?

 On 6/1/07, Caine Lai [EMAIL PROTECTED] wrote:

 I'm using EJB3 stateless session beans/JPA/JTA to manage my data
access.
 But I can't figure out how one would use lazy loading in this
 scenario since
 any transaction opened in the EJB layer will already be committed
 prior to
 rendering the view.

 Any tips?

 I'm familiar with Open Session in View when using hibernate, but it's
 not quite the same when I'm using container managed transactions and
 dependency injection in EJB3.  Or is it?  Would I still open a
hibernate
 session within the view and close it after the view is rendered in this
 scenario?

 Thanks for any pointers.


 

 No virus found in this incoming message.
 Checked by AVG Free Edition.
 Version: 7.5.472 / Virus Database: 269.8.7 - Release Date: 2/06/2007
12:00 AM



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




How does one use lazy loading in Struts 2 with container managed persistence?

2007-06-01 Thread Caine Lai

I'm using EJB3 stateless session beans/JPA/JTA to manage my data access.
But I can't figure out how one would use lazy loading in this scenario since
any transaction opened in the EJB layer will already be committed prior to
rendering the view.

Any tips?

I'm familiar with Open Session in View when using hibernate, but it's not
quite the same when I'm using container managed transactions and dependency
injection in EJB3.  Or is it?  Would I still open a hibernate session within
the view and close it after the view is rendered in this scenario?

Thanks for any pointers.


Re: How to forward to an unknown view in Struts 2?

2007-05-23 Thread Caine Lai

Sorry for taking so long to get back to everyone on this.  This is a side
project of mine and things have been hectic with the day job keeping me from
this.

After doing some experimentation, I've found that your solution below does
work Musachy.  It just won't access a property in the request attributes as
I was trying to do.  At least it wouldn't do it the way I was doing it. =)

Setting a property in my Struts action class is working perfectly now.
Thanks to everyone that responded.

On 5/10/07, Musachy Barroso [EMAIL PROTECTED] wrote:


%{expr} won't work (yet). I modified EditPersonAction on showcase to this:

@Result(name=list, value=${next}, type=ServletRedirectResult.class)
public class EditPersonAction extends ActionSupport {

...

public String getNext() {
return listPeople.action;
  }

public String execute() throws Exception {
persons.addAll(personManager.getPeople());
return list;
  }

..
}

and it works as expected. Did you configured the initParam actionPackages
in
your web.xml, like?:

filter
filter-namestruts/filter-name
filter-classorg.apache.struts2.dispatcher.FilterDispatcher
/filter-class
init-param
param-nameactionPackages/param-name
param-valueorg.apache.struts2.showcase.person/param-value
/init-param
/filter


musachy

On 5/9/07, Dave Newton [EMAIL PROTECTED] wrote:

 --- Caine Lai [EMAIL PROTECTED] wrote:
  @Result(name=Action.SUCCESS,
  value=/resources/${resource}.ftl,
  type=FreemarkerResult.class)
  Am I missing something?

 Did you try using OGNL syntax, like %{resource}.ftl?

 d.


 __
 Do You Yahoo!?
 Tired of spam?  Yahoo! Mail has the best spam protection around
 http://mail.yahoo.com

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




--
Hey you! Would you help me to carry the stone? Pink Floyd



Re: difference between html:submit and input type=submit

2007-05-23 Thread Caine Lai

Just an FYI to those that care.  I for one, hate using Struts specific tags
in my view layer.  I've never figured out what the benefit is from straying
from standardized HTML tags, especially when they are not needed.  So I use
regular HTML forms, controls and buttons.

The only requirement to getting this to work properly, is setting the name
attribute on your tags, as this is what Struts uses to popular bean
properties (at least in my experience).  Someone correct me if I'm wrong.

Here is an example form that works in Struts without having to use the
Struts tags:

form method=post action=[EMAIL PROTECTED] action=login /]
 label for=username[EMAIL PROTECTED] name=i18n.input.username /]: 
/label
 input type=text name=username id=username
maxlength=${USERNAME_MAX_LENGTH} value=${username!} tabindex=1 /br
/
 label for=password[EMAIL PROTECTED] name=i18n.input.password /]: 
/label
 input type=password name=password id=password
maxlength=${PASSWORD_MAX_LENGTH} value=${password!} tabindex=2 /br
/
 input type=submit name=submit id=submit value=Login
tabindex=3 /
/form

I'm using Freemarker for my views which is why you see funny tags and
expression syntax.  But you could just as easily use JSP as well.

Cheers,
C

On 5/23/07, Dave Newton [EMAIL PROTECTED] wrote:


--- Alin Tomoiaga [EMAIL PROTECTED] wrote:
 Besides the fact that we should try and handle all
 our tags in a uniform manner and plan for future
 changes, is there an extra feature that
 html:submit  brings over  input type=submit ?

Exactly what I told you the first time.

Did you look at the link I provided that gives you a
list of (all, but only pay attention to the
Struts-specific ones!) attributes that
html:submit.../ uses?

http://struts.apache.org/1.2.9/userGuide/struts-html.html#submit

altKey, bundle, indexed, titleKey, and property are
all Struts-specific (I think)... largely message- and
ActionForm-related stuff.

d.






It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: [S2] Freemarker vs struts taglibs

2007-05-18 Thread Caine Lai

I have been using Freemarker with Struts 2 for my latest project and I'm
loving it.  The syntax is a gazillion times (yes, exactly that many) better
than JSP in my opinion.

As far as differences in the tags, there isn't any.  You can do the same
thing using the Freemarker Struts tags as you can using the JSP Struts tags.

Just to be clear, you choose to use either JSP or Freemarker.  And then you
use the tag syntax for that view language.

On 5/17/07, Musachy Barroso [EMAIL PROTECTED] wrote:


FreeMarker is a template engine, with it's own syntax. JSP tags can be
used
in FreeMarker, adding some configuration. In the case of Struts tags, no
configuration is required, and you can use them like you would in JSP
except
a few differences, see this for details:

http://struts.apache.org/2.x/docs/freemarker.html

musachy

On 5/17/07, Jordi Rubio Moreno [EMAIL PROTECTED] wrote:

 Hi,

 I'm a bit confused. I need to decide if I'll use Freemarker or Struts
 taglibs, and I don't know the differences between both. E.g. what's the
 difference between s:iterator and @s.iterator, s:url and @s.url,
 etc etc...

 I have seen all the tutorials and examples I have found working with
 taglibs, but people says WebWork and Struts 2's choice is Freemarker...

 Please, help me to understand why taglibs or Freemarker :)

 Thanks a lot!

 Cheers!




--
Hey you! Would you help me to carry the stone? Pink Floyd



How to forward to an unknown view in Struts 2?

2007-05-09 Thread Caine Lai

Does anyone know how I can forward to a .jsp file based on a dynamic
attribute (request parameter)?

I want to write a Struts 2 action that will forward the user to a .jsp
dynamically.  The flow works like so:

1. A request is made for 'resourceLocator.action?resource=common'.
2. The resourceLocator.action class takes the 'resource' request parameter
and forwards the user to 'common.jsp'.

I'm not able to figure out how this is done in Struts 2, since all actions
only return a String result which must be mapped.  I'm trying to avoid
having to map all my resources in this action.

Thanks!


Re: How to forward to an unknown view in Struts 2?

2007-05-09 Thread Caine Lai

Thanks Musachy,

But how would one do this if they were using Struts 2 annotations to map
their action classes?  Is it possible?  Or am I stuck with using XML for
this one action?

Thanks,
Caine

On 5/9/07, Musachy Barroso [EMAIL PROTECTED] wrote:


You can use OGNL expressions in the result path, just make sure that you
use
${expression}, instead of %{expression}, like

action ...
result${forwardTo}/result
/action

musachy

On 5/9/07, Caine Lai [EMAIL PROTECTED] wrote:

 Does anyone know how I can forward to a .jsp file based on a dynamic
 attribute (request parameter)?

 I want to write a Struts 2 action that will forward the user to a .jsp
 dynamically.  The flow works like so:

 1. A request is made for 'resourceLocator.action?resource=common'.
 2. The resourceLocator.action class takes the 'resource' request
parameter
 and forwards the user to 'common.jsp'.

 I'm not able to figure out how this is done in Struts 2, since all
actions
 only return a String result which must be mapped.  I'm trying to avoid
 having to map all my resources in this action.

 Thanks!




--
Hey you! Would you help me to carry the stone? Pink Floyd



Re: How to forward to an unknown view in Struts 2?

2007-05-09 Thread Caine Lai

Thanks again for your help.  So perhaps I'm not understanding how to get
this to work.  In my action I have this mapping:

@Result(name=Action.SUCCESS, value=/resources/${resource}.ftl, type=
FreemarkerResult.class)

And in my execute method I have:

request.setAttribute(resource, myPage);

The action is trying to forward to /resources/.ftl.  Which tells me it is
not resolving ${resource}.

Am I missing something?

Thanks,
Caine

On 5/9/07, Musachy Barroso [EMAIL PROTECTED] wrote:


I haven't tried myself but the annotations for results should work just
like regular xml-configured results.

musachy

On 5/9/07, Caine Lai [EMAIL PROTECTED] wrote:

 Thanks Musachy,

 But how would one do this if they were using Struts 2 annotations to map
 their action classes?  Is it possible?  Or am I stuck with using XML for
 this one action?

 Thanks,
 Caine

 On 5/9/07, Musachy Barroso [EMAIL PROTECTED] wrote:
 
  You can use OGNL expressions in the result path, just make sure that
you
  use
  ${expression}, instead of %{expression}, like
 
  action ...
  result${forwardTo}/result
  /action
 
  musachy
 
  On 5/9/07, Caine Lai [EMAIL PROTECTED] wrote:
  
   Does anyone know how I can forward to a .jsp file based on a dynamic
   attribute (request parameter)?
  
   I want to write a Struts 2 action that will forward the user to a
.jsp
   dynamically.  The flow works like so:
  
   1. A request is made for 'resourceLocator.action?resource=common'.
   2. The resourceLocator.action class takes the 'resource' request
  parameter
   and forwards the user to 'common.jsp'.
  
   I'm not able to figure out how this is done in Struts 2, since all
  actions
   only return a String result which must be mapped.  I'm trying to
avoid
   having to map all my resources in this action.
  
   Thanks!
  
 
 
 
  --
  Hey you! Would you help me to carry the stone? Pink Floyd
 




--
Hey you! Would you help me to carry the stone? Pink Floyd



Struts 2 StringLengthFieldValidator maxLength attr is a String!?

2007-05-07 Thread Caine Lai

So what's up with the Struts 2 StringLengthFieldValidator's maxLength
property being a String?  This completely screws up my ability to define the
field length in an int constant.  Does anyone have a workaround for this?

Thanks.


Re: Struts 2 StringLengthFieldValidator maxLength attr is a String!?

2007-05-07 Thread Caine Lai

Yes, the Struts API is fine.

It's the struts annotations that specify a String value.  Since I'm using
annotations to set my validators, I have to use a String to specify field
length, which seems silly to me.

http://struts.apache.org/2.0.6/struts2-core/apidocs/com/opensymphony/xwork2/validator/annotations/StringLengthFieldValidator.html#maxLength()

On 5/7/07, Dave Newton [EMAIL PROTECTED] wrote:


--- Caine Lai [EMAIL PROTECTED] wrote:
 So what's up with the Struts 2
 StringLengthFieldValidator's maxLength
 property being a String?

What?


http://struts.apache.org/2.0.6/struts2-core/apidocs/com/opensymphony/xwork2/validator/validators/StringLengthFieldValidator.html#setMaxLength(int)

What version are you referring to?

d.


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




How do I access Struts 2 action errors in request from Freemarker view.

2007-04-24 Thread Caine Lai

I'm trying to figure out a way to access the Struts 2 action messages in a
Freemarker template.  I copied the following code from the Struts template
directory, into my Freemarker view, but the action errors do not show up,
which tells me I must not be using the correct variable.

[#if (actionErrors?exists  actionErrors?size  0)]
   ul
   [#list actionErrors as error]
   lispan class=errorMessage${error}/span/li
   [/#list]
   /ul
[/#if]


I've also tried Request.actionErrors, but this doesn't work either.

Does anyone have an idea how I can get access to these?  I need to be able
to customize the output of these messages.  I know there is a way to
override the Struts 2 default template, but I need to combine actionErrors
and actionMessages in a single template.

Thanks for any help.