RE: data injection attack

2012-07-04 Thread Marcus Bond
You could implement a class that delegates to your bean but only exposes 
setters and getters that are appropriate, so in the case of the id then you 
could let the user view it (getter) but not allow the setter.

A perhaps even better approach would be to devise a proxying mechanism (perhaps 
configured via annotations) and have a security layer be responsible for which 
methods can be called - this not only would prevent url parameters being set 
but also prevent restricted fields of any object being updated.

Marcus.



-Original Message-
From: J. Garcia [mailto:jogaco...@gmail.com] 
Sent: 04 July 2012 14:49
To: Struts Users Mailing List; lukasz.len...@gmail.com
Subject: Re: data injection attack

My action would have:

public void setMyBean( MyBean myBean) {...}

and I would like to avoid an injection on myBean.field3. This field could be 
the owner id for instance!

On Wed, Jul 4, 2012 at 3:34 PM, Łukasz Lenart
wrote:

> Another way is to use AnnotationParameterFilterIntereptor (name 
> contains typo) and @Allowed and @Blocked annotations
>
>
> Regards
> --
> Łukasz
> mobile +48 606 323 122 http://www.lenart.org.pl/ Warszawa JUG 
> conference - Confitura http://confitura.pl/
>
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: fetching a static variable's value from within a JSP page

2012-06-20 Thread Marcus Bond
Is it possible that in your example code there are lines referencing
property instanceCount where they should reference helloCount?

-Original Message-
From: Sam Cyrus [mailto:haminto...@yahoo.com] 
Sent: 20 June 2012 17:24
To: Struts send question
Subject: fetching a static variable's value from within a JSP page

Hi,

I am trying to follow the tutorial Hello World for Struts2. In the part
"Using Struts 2 Tags" it uses s:property to fetch the value for the
helloCount variable inside a paragraph tag but doing as the example shows,
doesn't get any value and the place is empty in HelloWorld.jsp. The lines
below from this jsp shows my different trials and when it works. I would
like to know the reason:




It is possible to fetch the static helloCount outside paragraph tags:
 

Inside paragraph tags the static helloCount preceded by @-prefix
returnsempty times!

Inside paragraph tags the static helloCount without @-prefix returns
  empty times!

By assigning the static value to an instance variable inside the
execute method  works well inside
p-tags

 Still strange! The DAY-OF-WEEK is static but possible to fetch
inside p-tags:  as
expected 

Best regards
/// Sam Cyrus

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: Advice needed: Offline Struts App

2012-03-15 Thread Marcus Bond
Do you mean that they wish to have it running locally or that they want to see 
a native UI application rather than a browser application?
If it is the first scenario then why not simply give them a zipped up tomcat 
server with the web-app already deployed and either a script to run it or ask 
them to install it as a service. If you really need an installer then create 
one to do the same thing.

In the latter case then you're going to need a lot of code, firstly for the UI 
and secondly to get all the data from UI components on to your actions. You 
would probably do better to just use your model and service layers from the web 
app ignoring the Struts side of things altogether. If you really need something 
in the future that would be relatively pain free to have both web app and 
desktop versions then perhaps take a look at Eclipse RCP and RAP.. whether the 
reality lives up to the dream though is an exercise for the reader :)
M

-Original Message-
From: Christian Grobmeier [mailto:grobme...@gmail.com] 
Sent: 15 March 2012 15:26
To: Struts Users Mailing List
Subject: Advice needed: Offline Struts App

Hi,

yes I know Struts 2 is a web framework. But recently somebody told me he would 
love to see a desktop version of my app instead of a cloud based version. I 
think this would be great for me too. Now I am considering different ways... 
not sure, probably somebody here already did the same in the past.

I mean, many of the interceptors are probably not necessary in a desktop app. 
My Action are there - I could use them straightaway without interceptors (or 
some other great features of Struts).
Basically I would just need to replace my HTML/JS frontend with something else, 
probably JavaFX.

Anybody around who had a similar job with S2 in the past?

Cheers
Christian

--
http://www.grobmeier.de
https://www.timeandbill.de

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: [OT] Searching for data access framework.

2011-12-05 Thread Marcus Bond
Perhaps Apache Shiro may be something you could utilise... you would
implement an LDAP 'realm' or a SQL realm that knows how to lookup
credentials and access privileges etc.
In their lingo "A Realm is essentially a security-specific DAO "  and out of
the box they provide a JDBC realm with suggested schema and, whilst I
haven't used it, they also have org.apache.shiro.realm.ldap.JndiLdapRealm
(abstract class available too if not quite what you're after) so you may be
able to save yourself a heap of implementation.

http://shiro.apache.org/realm.html
http://shiro.apache.org

I have used this framework as part of a Spring based web app using a custom
realm to authenticate users stored in CouchDB and also implemented a JPA  /
Hibernate realm (DAO), it's easy enough to get to grips with, active and
helpful mailing list and it seems to be catching on..

Cheers,
Marcus

-Original Message-
From: Balwinder [mailto:balwinder@gmail.com] 
Sent: 05 December 2011 17:13
To: Struts Users Mailing List
Subject: Re: [OT] Searching for data access framework.

Hi Wes,

What I need is something like, if I want to access data from a database, i
can use SQL, but if i change the source to LDAP then the access mechanism
will change from SQL to LDAP specifics, now if the same data goes to flat
file than again my mechanism will change, so all I need is some framework
that if when source is changed its access mechanism should remain same. Hope
this explains what I am looking for.

Regards,
Balwinder Kumar

On 12/5/2011 10:35 PM, Wes Wannemacher wrote:
> I am not sure if I understand your question correctly, but the first 
> thing that comes to mind -
>
> http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObj
> ect.html
>
> I would say to combine a disciplined approach of separation with a 
> domain model layer, a business logic (transactional) layer and then 
> IoC with Spring...
>
> If you were looking for more detail than that, we'll need some more 
> details on your problem.
>
> -Wes
>
> On Mon, Dec 5, 2011 at 12:02 PM, Balwinder
wrote:
>> Hi All,
>>
>> Can anyone suggest me a framework that can abstract the data call and 
>> its source, if there exists any? Example if I want to authenticate a 
>> user then my query shall not depend upon the data source, it could be 
>> any LDAP server, database or any file in a file system or anything else.
>>
>> Thanks in advance.
>>
>> Regards,
>> Balwinder Kumar
>>
>> -
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>
>


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: To create new session without invalidating existing one

2011-09-29 Thread Marcus Bond
What is the reason for the new session? Doesn't sound a great plan.
Anyway you're going to have a problem as this isn't how browsers expect to 
work, that said Chrome allows incognito browsing so that might work but it 
isn’t generally the expected behaviour.

If the same application is being accessed from the same browser (Firefox, 
Chrome, IE etc.) once a session is created then that is the same session unless 
you destroy it. Your browser has a cookie with the jsessionid and that cookie 
is for the site from that browser across all windows not per browser window.
Marcus.

-Original Message-
From: Velmurugan M [mailto:velmurug...@gmail.com] 
Sent: 29 September 2011 09:23
To: Struts Users Mailing List
Subject: Re: To create new session without invalidating existing one


-Original Message-
From: Brian Thompson 
Date: Thu, 29 Sep 2011 01:26:48
To: Struts Users Mailing List
Reply-To: "Struts Users Mailing List" 
Subject: Re: To create new session without invalidating existing one

Well, first I'd suggest dropping the requirement for launching the new browser 
window.  It's a pretty user-hostile way to program a site.  "Hey, why'd my Back 
button stop working?  Sigh, call IT again."

That said, you could try launching the popup window with a URL on a different 
subdomain.  That should keep the sessions separate from each other.

Failing that, you'll have to build in some logic to manage two sessions with 
different keys for the session IDs.

Regardless, I don't think it's really a Struts-level issue.

Brian



On Thu, Sep 29, 2011 at 1:02 AM, Ganesh  wrote:

> Hello all,
>
> We have a requirement to launch a new browser window with new session 
> but the exisiting session with parent browser should not be disturbed. 
> We tried couple of methods the new session is created but the existing 
> session is modified. Could some one throw me light on this.
>
> Regards
> Ganesh
>
>



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Modularisation of project web artifacts

2011-09-06 Thread Marcus Bond
Has anyone here much experience of separating out actions and associated
jsp's into their own projects (cvs , git whatever) and incorporating these
as artifacts into a larger project (aka the app)?

 

I want to be able to separate out my JSPs into a number of projects which
could be packaged into jars as maven artifacts (un-compiled is fine) and
then using a project maven build file draw these jsp out of their respective
jar files and add to the WEB-INF/whateverpath/ directory of the web-app
build. It looks at first glance like Overlays in Maven could do the trick
but does this approach work in Eclipse when developing too?

 

Anyone have any food for thought on this? Are there any other alternatives
such as deploying jsp in jar files (pre-compilation and corresponding
web.xml path mapping is a non starter)?

 

Cheers,

Marcus 



Persistence backed form validation

2011-09-02 Thread Marcus Bond
Hi, does anyone know of a validation method in struts that can use your JPA
(or other usage agnostic) annotations to validate the values on form fields?
For example, if I have specified a max length on an entity property and a
mandatory option on another then when updating / creating that entity via a
struts action it would be handy to have these already defined constraints
taken into account.

 

I know Empire-DB from the incubator achieves this with its Struts2 extension
but is something similar available for JPA? Ideally I would like to add the
data validation directly on the entity model (or DTOs where required) so
that I can validate consistently regardless of whether the data changes come
from a Struts action, a web service or a remote call. As apps progress and
we have web forms, web services, updates from mobile apps etc. adding
duplicated validation using different methodologies becomes a real chore. I
would be happy to 'pollute' my entity model with validation annotations if
the annotations could be utilised by a range of frameworks.

 

Cheers,

Marcus



RE: How to implement EJB 3.0, JPA, Hibernate and Struts 2 in one application?

2011-08-15 Thread Marcus Bond
Have never tried this out with ejb since it isn't isn't my thing but just
the same as a spring / struts (or any other framework) app your service
layer would be called from your struts actions such that struts isn't likely
to know about or care about the fact that the service  classes are ejb,
spring beans or anything.

Sooo.. each technology you mention has different purposes in your app and
should work together fine, Struts will provide your controllers and  the
actions will reference an ejb service layer with some ejbs using JPA via an
injected entity manager for which the underlying implementation for JPA
would be hibernate.. job done.

In answer to your second question, afaik Seam may be worth a look if you're
after ejb webapps..

 Marcus

-Original Message-
From: maurizio.cucchi...@gmail.com [mailto:maurizio.cucchi...@gmail.com] On
Behalf Of Maurizio Cucchiara
Sent: 15 August 2011 10:28
To: Struts Users Mailing List
Subject: Re: How to implement EJB 3.0, JPA, Hibernate and Struts 2 in one
application?

I think this is a good starting point: http://s.apache.org/jpa Maurizio
Cucchiara



On 15 August 2011 07:05, Coolemma  wrote:
> EJB 3.0, JPA, Hibernate and Struts 2

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: how to make onchange in s:select to submit a form and call a specific method in one action class

2011-08-11 Thread Marcus Bond
You could always make your own tag as an extension to the standard struts 
select tag adding attributes onChangeAction and onChangeTarget and let your new 
tag render an appropriate bit of javascript to make an ajax call to the server 
and then populate the results into the target item.. such a set of tags in your 
jsp may look like

< myTagLib:select name="region"  onchangeAction="countiesForRegion" 
onChangeTarget=" county"   />
< myTagLib:select name="county"   />

This would be a handy feature in a new struts tag to be fair, perhaps an 
...

Marcus

-Original Message-
From: Christian Grobmeier [mailto:grobme...@gmail.com] 
Sent: 11 August 2011 16:41
To: Struts Users Mailing List; em...@encs.concordia.ca
Subject: Re: how to make onchange in s:select to submit a form and call a 
specific method in one action class

> Or someone could provide more info will "sj:select" help satisfy the 
> following requirement?
>
> (1) 
> (2) 
> (3) 
>
> Actually, I prefer not to use complex javascript code to do change 
> select1,
> select2 is updated, change select2, and select3 is updated.

No chance without javascript. There is no struts on board functionality 
providing that feature.

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: Where to put non action associated data

2011-08-01 Thread Marcus Bond
Thanks for the feedback.. my first thought was to use interceptors but I
decided against this since in principle I mainly use interceptors for stuff
like setting up ThreadLocals for the request, auditing requests and for
access control etc. but not for business logic. Action chaining also entered
my mind but I have never used it.

Dave is right in that I didn't really want my actions or business services
to know about other 'plugins' so whilst the search is carried out in a
service with results returned to the action the service or the action
wouldn't know about additional ebay / google stuff. As far as I can see, I
either register these plugins with the business service and make calls to
them when necessary or I fire an event. The first of these options would
require my service to know about the possibility of plugins and to call each
of those present, the second allows anything in the system to respond to the
event. In this case I'm thinking that registering with the service may be
better - code would be more obvious, debugging easier and there's one place
to handle exceptions etc.

Despite the above, tweaking the view template chosen may not be so easy but
in reality it probably wouldn't be too much trouble to put something on the
stack as part of the action to tell the view which external results to
show.. I'll come back to that :)

Again, cheers for the ideas,
Marcus.  

-Original Message-
From: Dave Newton [mailto:davelnew...@gmail.com] 
Sent: 01 August 2011 14:39
To: Struts Users Mailing List
Subject: Re: Where to put non action associated data

Yep, a service is the canonical solution--my impression was that the OP was
trying to avoid *any* knowledge of the additional search stuff, but
composing capabilities via services sure seems like the easiest thing to do.

Dave

On Mon, Aug 1, 2011 at 9:32 AM, Aaron Brown 
wrote:
> If I were coding the search part, I'd probably place the secondary 
> piece inside a searching business service. Your action would 
> instantiate a search business service and ask it to get search results 
> based on a query string. The business service would do that and also 
> (based on whatever business logic you like) would do whatever extra 
> things were appropriate. The action never knows or cares about it, and 
> your low-level data access piece doesn't know either. It's the service 
> layer's job to understand the complexities and related activities that 
> go with the basic requests from the Action.
>
> My two cents.
>
>  - Aaron
>
> On Sun, Jul 31, 2011 at 12:50 PM, Marcus Bond 
wrote:
>> Hi,
>>
>>
>>
>> Say I have a form where user can carry out a product search which 
>> hits an action and returns a list of results - easy.. however in 
>> response to the user changing their search criteria I want to also 
>> generate some search terms which would be passed through to Ebay, 
>> google ads etc.. but not within my action which is designed with one 
>> purpose in mind - to search my db (the action doesn't know about 
>> google ads, ebay, AWS or any other thing that comes along). Gut 
>> reaction here is to fire an event (say product changed) and have some 
>> listeners do the work of generating the relevant google / ebay stuff and
storing this in the users session.
>>
>>
>>
>> Firstly, is this how most of you would go about it?
>>
>>
>>
>> Secondly in terms of the view side of things, whilst normally my 
>> action would simply return 'success' I may want to tweak the view 
>> depending upon which external source returned the best results 
>> (currently I use tiles but I don't think I can or should dynamically 
>> switch the result after my action has processed).. How would you 
>> tackle this? By adding logic to the tile / template jsp or some other
means?
>>
>>
>>
>> Can any of you share experiences of using Struts in apps like this 
>> and how you tackled similar scenarios or if maybe another framework is
more suited?
>> You'll have to bear with me here since all my work thus far has had 
>> no need to collaborate data from multiple sources in one page.
>>
>>
>>
>> Regards and thanks in advance,
>>
>> Marcus
>>
>>
>
>
>
> --
> Aaron Brown : aa...@thebrownproject.com
>
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Where to put non action associated data

2011-07-31 Thread Marcus Bond
Hi,

 

Say I have a form where user can carry out a product search which hits an
action and returns a list of results - easy.. however in response to the
user changing their search criteria I want to also generate some search
terms which would be passed through to Ebay, google ads etc.. but not within
my action which is designed with one purpose in mind - to search my db (the
action doesn't know about google ads, ebay, AWS or any other thing that
comes along). Gut reaction here is to fire an event (say product changed)
and have some listeners do the work of generating the relevant google / ebay
stuff and storing this in the users session.

 

Firstly, is this how most of you would go about it?

 

Secondly in terms of the view side of things, whilst normally my action
would simply return 'success' I may want to tweak the view depending upon
which external source returned the best results (currently I use tiles but I
don't think I can or should dynamically switch the result after my action
has processed).. How would you tackle this? By adding logic to the tile /
template jsp or some other means?

 

Can any of you share experiences of using Struts in apps like this and how
you tackled similar scenarios or if maybe another framework is more suited?
You'll have to bear with me here since all my work thus far has had no need
to collaborate data from multiple sources in one page.

 

Regards and thanks in advance,

Marcus 



RE: Multi Devices and Multilanguage

2011-06-30 Thread Marcus Bond
I had a similar idea of using an interceptor to alter the result code a
while ago and decided that it was a non-starter mainly because every action
would need another mapping for each platform you determined was worthy of
treating differently. I need to sort something out imminently and the
current way I'm trying is to use a different namespace for the mobile
version e.g. /m and alter the declared stylesheets based on the user agent
(using tiles this is easy, presumably sitemesh could handle this too). For
this I am in the process of developing a 'device profile' with some helper
methods such as isIPhone(), isBlackberry() isSmall, isTablet yada yada.. all
the details are yet to be finalised. Essentially I concluded that devices
can be categorised in families so it's unlikely that you would treat
completely differently either versions of the iPhone or a htc desire. The
html would remain the same although you may tweak the stylesheet. Again,
using tiles any extreme cases can be handled since depending upon the device
profile you can alter the jsp you would include in the template if
stylesheets alone cannot give you the required effect.

Time will tell whether or not this approach works ok or not.. Would be good
to hear of other peoples experiences with tackling this issue.
M
  

-Original Message-
From: Zoran Avtarovski [mailto:zo...@sparecreative.com] 
Sent: 30 June 2011 07:31
To: Struts Users Mailing List; Frans Thamura
Subject: Re: Multi Devices and Multilanguage

We use a custom sitemesh decorator for each targeted platform and also a
custom struts theme for each.

This way we use the same core jsp files across the application. By keeping
the JSP functionality simple we find it works really well.

I hate to be the one who breaks it to you but you'll have to do some work
arounds. For example we have a number of key navigation pages which are
quite different for each of the platforms (mobile, tablet, web) and as such
require more work. The action classes have to know the targeted platform to
setup the appropriate data objects.

As for multi-lingual development we use a database backed localised text
system. We've had no issues with it. Having said that we are about to start
on an Arabic language version, which should be a lot of fun ;). Same
principle as above applies, use the S2 localised text wherever possible and
be prepared to create some custom CSS and decorator files for non-latin
based languages.

Z.




On 30/06/11 1:28 AM, "Frans Thamura"  wrote:

>hi all
>
>we want to create a multi devices rendering for our apps, which we use 
>struts2, for mobile, tablet and web common, we use jquery mobile, i 
>like the JQM beta1.
>
>and we also want to make web with multi language
>
>anyone can share the strategy which we can start to make this
>
>F



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Dynamic text

2011-05-31 Thread Marcus Bond

Thanks Jason,



Will be fine as normally it will just be a property to return not a 
method call.. The glaringly obvious error in hindsight was having left 
the 'get' part on the property name..


Doh!


On 31/05/2011 19:56, Jason Pyeron wrote:


--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-   -
- Jason Pyeron  PD Inc. http://www.pdinc.us -
- Principal Consultant  10 West 24th Street #100-
- +1 (443) 269-1555 x333Baltimore, Maryland 21218   -
-   -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.




-Original Message-----
From: Marcus Bond [mailto:mar...@marcusbond.me.uk]
Sent: Tuesday, May 31, 2011 14:41
To: Struts Users Mailing List
Subject: Re: Dynamic text

Thanks for the link but still not quite what I'm looking
for.. I've made a simple example below, however note that I
am not extending ActionSupport in any of my actions:

Action has method (could return different value than 'goodbye')

public String getMyKey() {
  return "goodbye";
  }


resource file has keys:
hello=Hello There!
goodbye=See you later!

page has tags:
  This works fineNope  

Try:, it works for me with your example.

If you want to call a method you should:


Nope


  This returns nothing
  This returns nothingThis returns
nothing






On 31/05/2011 15:38, Jason Pyeron wrote:

-Original Message-
From: Marcus Bond
Sent: Tuesday, May 31, 2011 10:26
To: Struts Users Mailing List
Subject: Dynamic text

Hi,

I want to use some view objects in my action that will contain
resource keys and then show these using s:text to resolve

the key to

it's translation.. Is this type of thing supported? I know

a lot of

tags moan if you try and use any ${foo.bar} type arguments

Have you taken a look at
http://struts.apache.org/2.x/docs/localization.html
yet?

If so could you please post a specific problem?

-Jason


--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-   -
- Jason Pyeron  PD Inc. http://www.pdinc.us -
- Principal Consultant  10 West 24th Street #100-
- +1 (443) 269-1555 x333Baltimore, Maryland 21218   -
-   -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.






-

To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org





-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org






-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Dynamic text

2011-05-31 Thread Marcus Bond
Thanks for the link but still not quite what I'm looking for.. I've made 
a simple example below, however note that I am not extending 
ActionSupport in any of my actions:


Action has method (could return different value than 'goodbye')

public String getMyKey() {
return "goodbye";
}


resource file has keys:
hello=Hello There!
goodbye=See you later!

page has tags:
 This works fine 
 Nope 
 Nope 


 This returns nothing 
 This returns nothing 
 This returns nothing 






On 31/05/2011 15:38, Jason Pyeron wrote:

-----Original Message-
From: Marcus Bond
Sent: Tuesday, May 31, 2011 10:26
To: Struts Users Mailing List
Subject: Dynamic text

Hi,

I want to use some view objects in my action that will
contain resource keys and then show these using s:text to
resolve the key to it's translation.. Is this type of thing
supported? I know a lot of tags moan if you try and use any
${foo.bar} type arguments

Have you taken a look at http://struts.apache.org/2.x/docs/localization.html
yet?

If so could you please post a specific problem?

-Jason


--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-   -
- Jason Pyeron  PD Inc. http://www.pdinc.us -
- Principal Consultant  10 West 24th Street #100-
- +1 (443) 269-1555 x333Baltimore, Maryland 21218   -
-   -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.




-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org






-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Dynamic text

2011-05-31 Thread Marcus Bond

Hi,

I want to use some view objects in my action that will contain resource 
keys and then show these using s:text to resolve the key to it's 
translation.. Is this type of thing supported? I know a lot of tags moan 
if you try and use any ${foo.bar} type arguments


Cheers,
Marcus


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: RedirectAction Help!

2011-05-13 Thread Marcus Bond
I was having similar issues recently using an older version of struts2 
(can't remember which unfortunately) and I upgraded to 2.2.3  which 
seems to work fine..


fyi the first example I have is below where selectedUserId is set on the 
action I redirect to with the value from user.getId passed as the value 
so the url ends up as /listUsers?selectedUserId=69





 

listUsers

${user.id}









This is the same as yours pretty much.. I presume you've double checked 
that there is a value set for yourForm when you then do the redirect?


Perhaps it's worth debugging through the code or trying it out with a 
newer struts version?




On 13/05/2011 18:05, tdmcgin...@gmail.com wrote:

Eric,

I have never used pastebin before but I created my project files out 
there and here is the link:


http://pastebin.com/u/tdmcginley

The problem is getting from startInformation.jsp begin button to 
questions with the formid.


In event I list the URL's that I start with and what they look like.

I appreciate any assistance I can get to get this working.

Teresa

On May 13, 2011 8:12am, Eric Lentz  wrote:

> I'll take any suggestions to get this working.





Your code snippet lacks important details that would help me answer your



question. Use pastebin or a like service and include a minimal running



example and then perhaps I can help.







-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: RedirectAction Help!

2011-05-13 Thread Marcus Bond
I have a few examples of this working fine, will post this evening when 
I'm home


M

On 13/05/2011 13:57, tdmcgin...@gmail.com wrote:

I didn't think I could send parameters with the chain?

I am really trying to pass the an id from one action to another. I'll 
take any suggestions to get this working.


Teresa


On May 13, 2011 6:48am, jagdeep singh  
wrote:

Use result type chain for example



"HelloWorld"






On Fri, May 13, 2011 at 4:39 PM, Teresa McGinley 
tdmcgin...@gmail.com>wrote:





> I'm using Tomcat.



>



> Sent from my iPod



>



> On May 12, 2011, at 6:08 PM, Jeffrey Black jeffrey.bl...@yahoo.com>



> wrote:



>



> > Hi Teresa.



> >



> > By "container" I meant Tomcat, Jetty, et al.



> >



> > Are you leveraging Spring for DI needs?



> >



> > Best,



> >



> > jb



> >



> > Sent from my iPad



> > Follow me on Twitter @jeffblack360



> >



> >



> > On May 12, 2011, at 12:10 PM, tdmcgin...@gmail.com wrote:



> >



> >> Jeff,



> >>



> >> I am running struts 2.2.1



> >>



> >> I also created this with Spring 3.0, although I am not sure I need



> spring.



> >>



> >> Teresa



> >>


> >> On May 11, 2011 11:32pm, Jeffrey Black jeffrey.bl...@yahoo.com> 
wrote:



> >>> Teresa,



> >>



> >>



> >>



> >>> FWIW, I have apps that utilize redirectAction (ie



> ServletActionRedirectResult) without issue.



> >>



> >>



> >>



> >>> Just curious, what version of Struts2 are you running and what



> container are you using?



> >>



> >>



> >>



> >>> Best,



> >>



> >>



> >>



> >>> jb



> >>



> >>



> >>



> >>



> >>



> >>> 



> >>



> >>> From: Teresa McGinley tdmcgin...@gmail.com>



> >>



> >>> To: user@struts.apache.org



> >>



> >>> Sent: Tuesday, May 10, 2011 6:01 PM



> >>



> >>> Subject: RedirectAction Help!



> >>



> >>



> >>


> >>> I am trying to send an id from one action to another and it 
seems to be



> >>


> >>> sending a null. Please assist and I am really at my wits end 
with this.



> >>



> >>> How do I get the formId from the Listing to the QuestionListing?



> >>



> >>



> >>


> >>> startInformation has a yourForm=41, when I click the Begin 
button I get



> the



> >>



> >>> redirect to Questions.action with a null formId as shown...



> >>



> >>



> >>



> >>> http://localhost:8080/IUNSurvey/survey/Questions.action?formId=



> >>



> >>



> >>



> >>> startInformation.jsp has a button that calls redirect:



> >>



> >>



> >>



> >>



> >>



> >>> ...



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>> struts.xml



> >>



> >>



> >>



> >>



> >>



> >>



> >>> "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"



> >>



> >>> "http://struts.apache.org/dtds/struts-2.0.dtd";>



> >>



> >>



> >>



> >>



> >>



> >>



> >>> prod -->



> >>



> >>



> >>



> >>



> >>



> >>



> >>> method="display">



> >>



> >>> /views/survey/Listing.jsp



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>> name="success">/views/survey/startInformation.jsp



> >>



> >>



> >>



> >>



> >>



> >>



> >>> method="beginQuestions">



> >>



> >>



> >>



> >>> Questions



> >>



> >>> true



> >>



> >>> ${yourForm}



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>> /views/survey/Questions.jsp



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>



> >>> exerpt from Listing.java



> >>



> >>



> >>



> >>> public String execute() {



> >>



> >>> selectedForm = services.getFormsById(yourForm);



> >>



> >>> return SUCCESS;



> >>



> >>> }



> >>



> >>



> >>



> >>> public String display() {



> >>



> >>> forms = services.getForms();



> >>



> >>> return NONE;



> >>



> >>> }



> >>



> >>



> >>



> >>> public String beginQuestions() {



> >>



> >>> return "redirect";



> >>



> >>> }



> >>



> >>



> >>



> >>> /**



> >>



> >>> * @return the yourForm



> >>



> >>> */



> >>



> >>> public Long getYourForm() {



> >>



> >>> return yourForm;



> >>



> >>> }



> >>



> >>



> >>



> >>



> >>



> >>> exerpt from QuestionListing.java



> >>



> >>



> >>



> >>> I have a getter/setter for formId



> >>



> >>



> >>



> >>> public String execute() {



> >>



> >>> currentQuestion = (services.getQuestionsByForm(getFormId()));



> >>



> >>> return SUCCESS;



> >>



> >>> }



> >>



> >>



> >>



> >>> public String display() {



> >>



> >>> setCurrentQuestion(services.getQuestionsByForm(getFormId()));



> >>



> >>> return NONE;



> >>



> >>> }



> >>



> >>> public void setFormId(Long formId) {



> >>



> >>> this.formId = formId;



> >>



> >>> }



> >>



> >>



> >>



> >>> public Long getFormId() {



> >>



> >>> return formId;



> >>



> >>> }



> >


> > 
-

Re: Strange behaviour with Spring

2011-05-10 Thread Marcus Bond
Just in case anyone can benefit from the insight, it turned out to be a 
configuration option and unfortunately that property isn't mentioned in 
the default properties file. (perhaps it could be added?)


In spite of configuring the struts properties for spring like below 
(properties as found in the default struts properties file)

struts.objectFactory=spring
struts.objectFactory.spring.autoWire=name
struts.objectFactory.spring.useClassCache=true

It turns out that even when configured in this way the 
StrutsSpringObjectFactory doesn't enforce it and can still load by type 
(only if there is a single bean of the relevant type as per behaviour of 
autowire by type) when trying to resolve constructors unless the 
following property is also set..


#This must be set to true when autowiring by name to prevent the 
StrutsSpringObjectFactory autowiring by type!

struts.objectFactory.spring.autoWire.alwaysRespect=true

Problem solved, cheers,
M.

On 09/05/2011 17:29, Andrew Lee wrote:

Ok, I didn't see you aren't actually referencing the string bean in your
action. That won't help
On 9 May 2011 17:23, "Andrew Lee"  wrote:

He's not using it as a java bean. Spring beans can be immutable.

Is it because when spring wires up your action it considers it to be a
parameter as you have get and set methods? So it appends it to the url. If
you inject t string bean via constructor injection and not via setter
injection and remove the getters and setters ,does that work?
On 9 May 2011 16:54, "Chris Pratt"  wrote:

Even if Spring considers it valid, that doesn't mean that other packages
will be able to treat immutable, non-JavaBeans as JavaBeans.
(*Chris*)

On Mon, May 9, 2011 at 3:39 AM, Marcus  wrote:


You can if you want to use a String as a Spring bean, it's a different
issue as to whether or not it is considered best practice or whether

there

are alternatives. You can find examples on the SpringSource forum if you
want, commented upon by Springy folk. It is perfectly valid to do so..

Sorry to sound off here but could input to the topic be constrained to

why

it might be that Struts somehow messes up the redirect by picking this

bean

up even though there are no references to it an any of the struts action
beans or in the struts.xml.. I think we can infer from this that if any
context file, regardless of purpose (related to Struts, data access or

any

other whatever) declared a String as a bean this will mess struts

redirects

up.. which is something that shouldn't happen.




On 09/05/2011 11:16, Ilya Kazakevich wrote:


Not sure you can use primitive wrappers and strings as spring beans.

For

example autowiring does not work for them.
Try the following:

1) inject literal directly
Instead of

method

getMyProperty


Ilya Kazakevich,
Developer
JetBrains Inc
http://www.jetbrains.com
"Develop with pleasure!"

-Original Message-
From: Marcus [mailto:mar...@marcusbond.co.uk]
Sent: Monday, May 09, 2011 11:27 AM
To: user@struts.apache.org
Subject: Re: Strange behaviour with Spring

Not sure what you mean, the bean I'm referring to is a Spring bean not

a

JavaBean (two unrelated concepts).. there is no requirement when using
the Spring framework to not create Spring beans of type String.

Regardless, this doesn't help explain why the String is being picked up
by the Struts framework and set on the redirect when there is nothing

in

the configuration to indicate it should..

On 09/05/2011 07:13, Chris Pratt wrote:


You can't create beans that implement java.lang.String, it's immutable
and
doesn't follow the bean spec.
(*Chris*)

On Sun, May 8, 2011 at 2:11 PM, Marcus Bond


wrote:


Hi,

I'm using Struts 2.2.3 and have observed some bizarre behavior when
using
Spring to provide my actions.. In order to simplify this and prove

the

problem I have created a project with a single static html file, and

a

single action in struts.xml which references a bean in my spring

context

file.

What basically happens is that if I declare a bean in my spring

context

(bean unrelated toany struts action) that is of class

java.lang.String

(as I
do for a log4j filepath) then when I perform a redirect in an action
mapping
this gets appended to the end of the url as the anchor.

If I navigate to http://localhost:8080/My App/simpleRedirect
the result is a reirect to the 'simple' action but note the url

struts

has
redirected to:




http://localhost:8080/MyApp/simple#this%20is%20a%20java.lang.String%20bean%2

0in%20my%20spring%20context


For some reason the

org.apache.struts2.dispatcher.ServletRedirectResult

class is being instantiated by with the anchor and location

constructor

args
set to the value of my spring bean by the StrutsSpringObjectFactory

If I remove the String bean from the spring contect then the url

behaves

as
normal, redirecting to:

http://localhost:8080/MyApp/simple

Have been s

Strange behaviour with Spring

2011-05-08 Thread Marcus Bond

Hi,

I'm using Struts 2.2.3 and have observed some bizarre behavior when 
using Spring to provide my actions.. In order to simplify this and prove 
the problem I have created a project with a single static html file, and 
a single action in struts.xml which references a bean in my spring 
context file.


What basically happens is that if I declare a bean in my spring context 
(bean unrelated toany struts action) that is of class java.lang.String 
(as I do for a log4j filepath) then when I perform a redirect in an 
action mapping this gets appended to the end of the url as the anchor.


If I navigate to http://localhost:8080/My App/simpleRedirect
the result is a reirect to the 'simple' action but note the url struts 
has redirected to:

http://localhost:8080/MyApp/simple#this%20is%20a%20java.lang.String%20bean%20in%20my%20spring%20context

For some reason the org.apache.struts2.dispatcher.ServletRedirectResult 
class is being instantiated by with the anchor and location constructor 
args set to the value of my spring bean by the StrutsSpringObjectFactory


If I remove the String bean from the spring contect then the url behaves 
as normal, redirecting to:

http://localhost:8080/MyApp/simple

Have been scratching my head trying to find where this behaviour is 
happening but have run out of time.. is this a known issue?


Files content:
*Spring context file:*


http://www.springframework.org/schema/beans";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:aop="http://www.springframework.org/schema/aop";
xmlns:tx="http://www.springframework.org/schema/tx";
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd";>











*Struts file:*

http://struts.apache.org/dtds/struts-2.0.dtd";>




index.html




simple




*Java class uk.co.marcusbond.action.SimpleAction*
package uk.co.marcusbond.action;

public class SimpleAction  {

public String execute() {
return "success";
}
}




Re: Parameter manipulation

2010-12-17 Thread Marcus Bond
David, didn't your original post say that this is an action that loads 
an object to display it rather than to modify it? In which case I'm not 
sure why you even need to use Preparable (as I'm guessing it's during 
prepare that the instance is initialised which makes it available for 
struts to populate during the second params setting). At a guess you're 
setting an id in the initial params phase which then is used to load the 
instance? Why not just load it during execute (or whatever other method 
is being called by the action mapping) so it isn't there for any params 
to be applied earlier?


Regards,
Marcus

On 17/12/2010 20:02, Altenhof, David Aron wrote:

One approach I've through of is to create an interceptor that would parse 
through your -validation.xml (assuming one uses them) and then only allow 
parameters that have an associated validator. This would actually serve two 
goals: 1) Preventing parameter fiddling 2) Mandating the wise practice of 
validating all incoming data.

Now if I could only find a few spare cycles to work on it...

-David

-Original Message-
From: Chris Pratt [mailto:thechrispr...@gmail.com]
Sent: Friday, December 17, 2010 1:08 PM
To: Struts Users Mailing List
Subject: Re: Parameter manipulation

Maybe if the OP moves the bean creation out of the prepare() method (so the 
bean isn't available during parameter injection) and then retrieves it at the 
start of validate() or execute() that might solve the problem.
   (*Chris*)

On Fri, Dec 17, 2010 at 10:05 AM, Chris Prattwrote:


If the bean already exists, struts doesn't have to set it.  It just
has to modify the retrieved bean.
   (*Chris*)


On Fri, Dec 17, 2010 at 9:48 AM,  wrote:


I agree S2 will create the bean (if null) but it can't set a property
that is private and has no accessible setter method.

P.S. What am I missing here?

Scott

On Fri, Dec 17, 2010 at 11:45 AM, Maurizio Cucchiara<
maurizio.cucchi...@gmail.com>  wrote:


This happens because bean is null, otherwise struts will populate.

2010/12/17:

Guys --

If the action has no setter and the property is private, S2 will
not populate it.

Scott

On Fri, Dec 17, 2010 at 11:10 AM, Maurizio Cucchiara<
maurizio.cucchi...@gmail.com>  wrote:


David,
I get your point.

Scott is right, you could overwrite PI or maybe write your
custom interceptor (though I think you should consider to file
an issue on JIRA).
Maybe it would use java annotations to hide/expose fields, or
alternately it could behave as you supposed (expose only field
with write accessors).




2010/12/17 Altenhof, David Aron:

The model objects are initialized in prepare() ... other
techniques

just

aren't as practical for our application.

I'm just going to keep doing lots of whitelisting with

ParameterNameAware...

-David



-Original Message-
From: Steven Yang [mailto:kenshin...@gmail.com]
Sent: Friday, December 17, 2010 1:10 AM
To: Struts Users Mailing List
Subject: Re: Parameter manipulation

is your user object initialized when the param interceptor is run?

here i might be wrong, but what i know is if your object is

initialized

then Struts or OGNL will call getUser().setEmail(...) otherwise

create a

new

User then setEmail then setUser then the second case should fail
for

you

again, i might be wrong on the behavior

On Thu, Dec 16, 2010 at 12:39 AM, Altenhof, David Aron
wrote:


I've been getting more and more concerned about the
possibility of parameter manipulation attacks with Struts2.
I've started doing

strict

whitelists using the ParameterNameAware interface on all of
my

forms

pages.

However, today I tried to code a "display-only" page that
shows information about a particular user. I thought that by
simply

creating

a getter and no setter, it would be impossible to inject

parameters.

For example, my action only contains the following getter for
a

JPA

model object:

public User getUser() {
return user;
}

However, by sending a simple query parameter, it is *still*

possible

to change values in user. For example, you can send:




http://localhost:8080/MySite/userdisplay.action?user.email=newemail
@ad

dress.com

... and it works. The email will become newem...@address.com

Is there any way to shut this down other than whitelisting
every single action in your site using ParameterNameAware?
(Or simply

never

put model objects on your stack?) This is getting frustrating!

-David




-

To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org





-

To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org





--
Maurizio Cucchiara


- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-ma

Re: Interceptor attempt

2010-11-11 Thread Marcus Bond
Generally knowledge of success / failure will be via exception throw / 
catch - you will expect certain exceptions under certain conditions and 
report an appropriate error to the user.


As for tutorial, a while ago I found a book download.. apparently a 
search in Google for "free practical apache struts2" will produce a 
handy link.. The book seems to do an ok job all around the Struts2 
landscape and introduces Spring and hibernate too.. Can't say I've 
followed it word for word  but I have used it for the odd tidbit of 
information here and there.

Marcus


On 11/11/2010 16:20, Altenhof, David Aron wrote:

No problem,  but we're starting to veer off topic here.

Of course, you'll delegate the data access to service or dao's, but ultimately 
your Action is going to have to know if the transaction commit succeeded if 
it's going to send an appropriate response (success/error) to the user. I'm 
sure Spring must give your action access to this through some kind of injection 
or AOP, but that's for another day.

BTY, does anyone have a favorite Struts2/Spring/Hibernate integration tutorial 
that they've tested with a recent versions of the frameworks. I've tried a 
couple with limited success.

-David



-Original Message-
From: Marcus Bond [mailto:mar...@marcusbond.me.uk]
Sent: Thursday, November 11, 2010 11:01 AM
To: user@struts.apache.org
Subject: Re: Interceptor attempt

Sorry to jump the thread David..

Looks like the ThreadLocal (unique per thread) session using HibernateUtil or 
equivalent would be the better bet. I'd question why you need direct access to 
the session from within your actions anyway as you're likely to be calling 
methods on some service class to do any updating / querying anyway and to be 
simply using the action class to 'control' where to go next, so it is in these 
service classes that you will be trying to get hold of the session and current 
transaction.
Assuming you're not requiring new transactions (equivalent of 
propagation="REQUIRES_NEW" in Spring AOP) for the work that goes on in your 
action then your interceptor could simply initiate a current transaction and then in a 
finally block commit or rollback as required (i.e when detecting errors) before rendering 
the view.

Once you're done with having a go at this then I'd say, depending upon the 
complexity of your app, to let Spring do the mundane work for you - injecting 
the required service beans into your Actions and declaring the transactional 
stuff so your code can simply worry about the business logic and application 
flow and not the intricacies of getting hold of sessions and beginning / ending 
transactions etc.

Regards,
Marcus.

On 11/11/2010 14:33, Altenhof, David Aron wrote:

Greg-

Thanks for bumping my memory on when the page gets rendered. I remember reading 
that somewhere, but forgot when writing this. Committing the transaction in the 
action for save/delete seems to be the way to go.

Regarding ThreadLocal, I'm a bit new to Java and still struggling a bit with 
the concept. You can simply simply call a 
sf.getCurrentSession().beginTransaction(); to begin and  
sf.getCurrentSession().getTransaction().commit(); to commit it from anywhere in 
your app?

Thanks,

David



-Original Message-
From: Greg Lindholm [mailto:greg.lindh...@gmail.com]
Sent: Wednesday, November 10, 2010 5:15 PM
To: Struts Users Mailing List
Subject: Re: Interceptor attempt

(Sorry - premature post)

Hi David,

I've written a couple of these so let me give you some advice:

Create an Interface "HibernateAware" that your actions will implement if they 
want a Hibernate Session and Transaction injected.

public interface HibernateAware
{
   void setSession(Session session);
   void setTransaction(Transaction tx); }

Next, you only want to create a Session and Transaction if the Action
implements HibernateAware,

Object action = invocation.getAction(); if (action instanceof
HibernateAware) {
HibernateAware ha = (HibernateAware) action;
ha.setSession(...)
ha.setTransaction(...)
   ...
}
else
{
return invocation.invoke();
}


Next and a bigger issue;  I think it is a really bad idea to do the commit in 
the interceptor.  If the commit fails it is too late to tell the user or do 
anything about it since your result and response has already been rendered.  
You need to understand how the interceptor stack works, but the key point is 
the first interceptor or action that returns a result string causes the result 
to be processed and the response (jsp page) to be rendered before the 
interceptor stack starts to unwind. SO if the commit fails, it's too late in 
the interceptor to do anything about it, you have already rendered the 
everything is OK page to the user.

What I do is to commit the transaction in the Action then if it fails I can 
return a FAILURE result.

Now if you

Re: Interceptor attempt

2010-11-11 Thread Marcus Bond

Sorry to jump the thread David..

Looks like the ThreadLocal (unique per thread) session using 
HibernateUtil or equivalent would be the better bet. I'd question why 
you need direct access to the session from within your actions anyway as 
you're likely to be calling methods on some service class to do any 
updating / querying anyway and to be simply using the action class to 
'control' where to go next, so it is in these service classes that you 
will be trying to get hold of the session and current transaction. 
Assuming you're not requiring new transactions (equivalent of 
propagation="REQUIRES_NEW" in Spring AOP) for the work that goes on in 
your action then your interceptor could simply initiate a current 
transaction and then in a finally block commit or rollback as required 
(i.e when detecting errors) before rendering the view.


Once you're done with having a go at this then I'd say, depending upon 
the complexity of your app, to let Spring do the mundane work for you - 
injecting the required service beans into your Actions and declaring the 
transactional stuff so your code can simply worry about the business 
logic and application flow and not the intricacies of getting hold of 
sessions and beginning / ending transactions etc.


Regards,
Marcus.

On 11/11/2010 14:33, Altenhof, David Aron wrote:

Greg-

Thanks for bumping my memory on when the page gets rendered. I remember reading 
that somewhere, but forgot when writing this. Committing the transaction in the 
action for save/delete seems to be the way to go.

Regarding ThreadLocal, I'm a bit new to Java and still struggling a bit with 
the concept. You can simply simply call a 
sf.getCurrentSession().beginTransaction(); to begin and  
sf.getCurrentSession().getTransaction().commit(); to commit it from anywhere in 
your app?

Thanks,

David



-Original Message-
From: Greg Lindholm [mailto:greg.lindh...@gmail.com]
Sent: Wednesday, November 10, 2010 5:15 PM
To: Struts Users Mailing List
Subject: Re: Interceptor attempt

(Sorry - premature post)

Hi David,

I've written a couple of these so let me give you some advice:

Create an Interface "HibernateAware" that your actions will implement if they 
want a Hibernate Session and Transaction injected.

public interface HibernateAware
{
  void setSession(Session session);
  void setTransaction(Transaction tx);
}

Next, you only want to create a Session and Transaction if the Action 
implements HibernateAware,

Object action = invocation.getAction();
if (action instanceof HibernateAware)
{
   HibernateAware ha = (HibernateAware) action;
   ha.setSession(...)
   ha.setTransaction(...)
  ...
}
else
{
return invocation.invoke();
}


Next and a bigger issue;  I think it is a really bad idea to do the commit in 
the interceptor.  If the commit fails it is too late to tell the user or do 
anything about it since your result and response has already been rendered.  
You need to understand how the interceptor stack works, but the key point is 
the first interceptor or action that returns a result string causes the result 
to be processed and the response (jsp page) to be rendered before the 
interceptor stack starts to unwind. SO if the commit fails, it's too late in 
the interceptor to do anything about it, you have already rendered the 
everything is OK page to the user.

What I do is to commit the transaction in the Action then if it fails I can 
return a FAILURE result.

Now if you need a Transaction open in order to allow lazy loading while 
rendering the jsp page what I will do is begin a second transaction.

Then in the interceptor I will Rollback the transaction and close the session 
since nothing in the page rendering should modify any entities.

Next; your interceptor needs to close the session.

Your option instead of storing the session in the action is to store it and the 
transaction in ThreadLocal storage. In fact if you copied your HIbernateUtil 
from many of the examples it may already be storing the session in ThreadLocal 
storage as this is very common.

One thing you need to be aware of regarding ThreadLocal storage and web 
servers; most web servers use a thread pool for executing requests and once 
your request is finished the thread gets put back into the pool for use on a 
future request.  This can be a problem if you don't properly clean up all 
ThreadLocal storage, for example if you leave a session open and in ThreadLocal 
storage when the thread gets re-used for the next request it will already have 
a session in it and it will be reused.  This usually happens when an exception 
occurs and the session doesn't get closed so chances are the session is corrupt 
or dead which will cause this later request to fail unexpectedly.

I would put the call to invocation.action() in a try block with a finally block 
that closes the session and cleans up any other THreadLocal stuff you have so 
it doesn't pollute the thread pool.




On Wed, Nov 10, 2010 at 4:44 PM, Greg Lindholm  w

Modifying action mapping per device type

2010-01-30 Thread Marcus Bond

Hi,

I am wanting to implement a site such that some actions may have a 
different mapping depending upon the device used (e.g. regular browser / 
mobile device etc.) but what I don't want to do is have to litter my 
actions with this type of logic. It could be at the result mapping level 
(i.e. in struts.xml) such that say a result of success would map to a 
jsp of somePage.jsp for regular browsers and somePageMobile.jsp for a 
mobile device (there will be more complications to this as I'd like to 
be able to have fine grained control based on the user agent so there 
may be many versions of a jsp such as somePageWinMobile6_5_htc.jsp).


There are  couple of ways I can think of to do this, but they're ugly:
- JSP level logic to render the page differently - dont want it, I'd 
rather individual jsp's for each supported device (or family) as this 
allows developers who are working on targeting a site to a specific 
device to concentrate on that device.
- Tiles template level logic - again not ideal as I would like to be 
able to use specific templates for device types.


Better but not perfect would be some sort of post action result 
modifying interceptor such that in the struts.xml I could define a 
number of different result mappings such as success, success_winmob, 
success_blackberry_storm and have the result string that has been 
returned from the action (success) modified by some sort of interceptor 
(e.g. appending the suffix prior to struts mapping it off to a view)  - 
the filter itself could be configured as to whether or not to alter 
result strings based on the action and the user device. - Is it possible 
to modify the result string post action but prior to struts resolving 
the mapping? And if so would I have access to the the name of the action?


Any suggestions here are greatly appreciated!
Web technologies being used are Struts2, Tiles2 and JSP.

Regards,
Marcus

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Modifying action mapping per device type

2010-01-30 Thread Marcus Bond

Hi Wes, thanks for the post.

I like the idea of being able to decorate screens differently depending 
on device without changing much existing code and I can see a use to 
this for example for pages being given a different footer to provide 
device specific links or adding side menus for devices with enough 
screen space. (The main focus of my web pages are application GUI rather 
than content). I do intend to look into sitemesh but I know nothing 
about it as yet. However, what sitemesh (I don't think anyway) cannot do 
is for example, for an old blackberry that does not support html tables 
very well, allow me to render a list of results in a business card style 
layout instead of a four column table - if it can then I'd be glad to 
know how and investigate it's use further as it would solve some of  the 
problems I encounter.



Wes Wannemacher wrote:

I admit that I haven't read the whole thread, so flame me if you
covered the answer already, but...

Have you looked at Sitemesh? I would suggest look at creating
different decorators for each of the devices you want to support, then
code your undecorated JSPs so that they can be decorated based on the
device accessing it. Sitemesh has a ton of different ways you can pick
the decorator, so I would imagine you'd be able to find a way to
abstract the decorator picking logic outside of your business logic.
Then, the advantage of the decorator pattern is that you can code your
UI screens and business logic once and just have the screens decorated
differently based on the abstracted decorator picking logic. (As a
bonus, you can add new decorators for new devices without changing
much)

-Wes

  



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Modifying action mapping per device type

2010-01-29 Thread Marcus Bond
This could work ok, especially if there were a configuration file such 
that the jsp to forward to could be specified on a per action/result 
basis, which would prevent having to duplicate jsp files unnecesarily. I 
would consider this, but unfortunately I am mostly using a result type 
of "tiles" to hand over to Tiles2 for view generation. In theory I could 
modify the tiles handler to support this..


I'll have to dig into Tiles code and maybe some struts code and see what 
can be done.


Gabriel Belingueres wrote:

Another direction would be to try implementing your own Result type:

   
   index
   

Then the result would check the device type the user is accessing the
application with, and you can try searching first for a:
index_brand_model.jsp, and if not found search for:
index_brand.jsp, then
index.jsp

When you find the right JSP page, just forward to it like the
ServletDispatcherResult do.

(I'm sure Convention plugin must have something like this already working.)

2010/1/29 Marcus Bond :
  

Interesting, I hadn't thought of that. However a problem I see here with
this approach is that it implies that there would be different versions or a
different mapping for every view whereas in reality, if a page looks / works
fine on say iphone, htc, windows mobile but doesn't on an old blackberry
then I want to be able to create a tweaked page for one device, but all
others would use the same page and mapping.

Gabriel Belingueres wrote:


How about using different packages/namespaces for the views?


   
   /bb/index.jsp
   



   
   /wm/index.jsp
   



2010/1/28 Marcus Bond :

  

Hi,

I am wanting to implement a site such that some actions may have a
different
mapping depending upon the device used (e.g. regular browser / mobile
device
etc.) but what I don't want to do is have to litter my actions with this
type of logic. It could be at the result mapping level (i.e. in
struts.xml)
such that say a result of success would map to a jsp of somePage.jsp for
regular browsers and somePageMobile.jsp for a mobile device (there will
be
more complications to this as I'd like to be able to have fine grained
control based on the user agent so there may be many versions of a jsp
such
as somePageWinMobile6_5_htc.jsp).

There are  couple of ways I can think of to do this, but they're ugly:
- JSP level logic to render the page differently - dont want it, I'd
rather
individual jsp's for each supported device (or family) as this allows
developers who are working on targeting a site to a specific device to
concentrate on that device.
- Tiles template level logic - again not ideal as I would like to be able
to
use specific templates for device types.

Better but not perfect would be some sort of post action result modifying
interceptor such that in the struts.xml I could define a number of
different
result mappings such as success, success_winmob, success_blackberry_storm
and have the result string that has been returned from the action
(success)
modified by some sort of interceptor (e.g. appending the suffix prior to
struts mapping it off to a view)  - the filter itself could be configured
as
to whether or not to alter result strings based on the action and the
user
device. - Is it possible to modify the result string post action but
prior
to struts resolving the mapping? And if so would I have access to the the
name of the action?

Any suggestions here are greatly appreciated!
Web technologies being used are Struts2, Tiles2 and JSP.

Regards,
Marcus

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org





-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



__ NOD32 4817 (20100129) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com




  

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org





-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



__ NOD32 4818 (20100129) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com



  



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Modifying action mapping per device type

2010-01-29 Thread Marcus Bond
Seems reasonable, however for me the problem here is that if you put 
getDevice() in a base class with common functionality then for every 
device type that may be returned you will have to create a copy of the 
jsp and this may need maintenance in time (or assuming it is the same 
jsp then maybe Ant could do copy it as part of the build). Whilst you 
could override getDevice in actions where you know the views are common 
(e.g. the same value is returned), your action (controller layer) would 
now contain code related to the view layer which for me is not ideal.


For example a doLogin action should do just that - log in a user, so 
either the user is logged in (return success) or there was a problem 
(return input). Once this has been tested it can be stored in cvs and 
left well alone, perhaps reused in multiple projects etc. Likewise being 
able to reuse exisiting actions without having to introduce a base class 
or modify them to implement an interface is preferred.


What I'm looking for is a solution where the actions are device unaware 
and it is up to the view and view mapping layer to sort this out. Where 
possible I'd like to reuse the same view (and path to it) and only 
handle cases where there is actually a different view for some devices.


Greg Lindholm wrote:

I've got the same situation and plan on handling by making the the
result location dynamic by adding a ${device} to the path.

   
   /${device}/index.jsp
   

In my actions I will have a getDevice() which will return a string
(e.g. "iPhone" or "blackberry" etc.) based on the User-Agent or
x-wap-profile.  I will use an interceptor that reads the user-agent
etc and determines the device type and injects that into my actions.


On Fri, Jan 29, 2010 at 5:57 AM, Marcus Bond  wrote:
  

Thanks for the info Andy, the interceptor seems an appropriate thing
although it does mean there are multiple mappings in struts.xml. This seems
at least a way that allows a site to grow in terms of new views without
impacting upon the application code or exisiting views.

Thinking about it this could be made generic with a little design such that
this result modification could be defined in (yet) another xml file, all it
would really need in my case (as there are not any security checks to do and
it is just a mapping) is to know for each action / result pair an
alternative result to return.

New class (say UserAgentResultListener) and a config file something along
the lines of that shown below, perhaps allowing use of regular expressions
for user agents..


  
 
 *blackberry*
 success_blackberry

 
 mobile6*
 success_windowsmobile

 
 foo
 bar

  


I can imagine others have had to do something similar in terms of delivering
different views to the same action depending upon user agent so it would be
good to get some community involvement.. I'd happily code it up.

Marcus

Andrew Sykes wrote:


There are  couple of ways I can think of to do this, but they're ugly:
- JSP level logic to render the page differently - dont want it, I'd
rather individual jsp's for each supported device (or family) as this
allows developers who are working on targeting a site to a specific
device to concentrate on that device.
- Tiles template level logic - again not ideal as I would like to be
able to use specific templates for device types.



As you rightly say, this is a maintenance nightmare.


  

Better but not perfect would be some sort of post action result
modifying interceptor such that in the struts.xml I could define a
number of different result mappings such as success, success_winmob,
success_blackberry_storm and have the result string that has been
returned from the action (success) modified by some sort of interceptor
(e.g. appending the suffix prior to struts mapping it off to a view)  -
the filter itself could be configured as to whether or not to alter
result strings based on the action and the user device. - Is it possible
to modify the result string post action but prior to struts resolving
the mapping? And if so would I have access to the the name of the action?




You can attach PreResultListeners[1] onto interceptor & action stack
executions. These execute after an action is executed, but before the
result is rendered. At this point, you are free to reach in and fiddle
with the action's returned result code. You can get the action's name if
you require, and manipulate the action in any way - it can be fetched from
the ActionInvocation.

I've used this feature in the past to perform a final "security
checkpoint" on any item being pulled from a database - the
PreResultListener examines the action (by reflection or otherwise) to find
the object, and checks the user is allowed to retrieve it.

Your idea is probably the sanest way to do it. Write an interceptor[2]
that g

Re: Modifying action mapping per device type

2010-01-29 Thread Marcus Bond
Thanks for the info Andy, the interceptor seems an appropriate thing 
although it does mean there are multiple mappings in struts.xml. This 
seems at least a way that allows a site to grow in terms of new views 
without impacting upon the application code or exisiting views.


Thinking about it this could be made generic with a little design such 
that this result modification could be defined in (yet) another xml 
file, all it would really need in my case (as there are not any security 
checks to do and it is just a mapping) is to know for each action / 
result pair an alternative result to return.


New class (say UserAgentResultListener) and a config file something 
along the lines of that shown below, perhaps allowing use of regular 
expressions for user agents..



   
  
  *blackberry*
  success_blackberry
 
  
  mobile6*
  success_windowsmobile
 
  
  foo
  bar
 
   


I can imagine others have had to do something similar in terms of 
delivering different views to the same action depending upon user agent 
so it would be good to get some community involvement.. I'd happily code 
it up.


Marcus

Andrew Sykes wrote:

There are  couple of ways I can think of to do this, but they're ugly:
- JSP level logic to render the page differently - dont want it, I'd
rather individual jsp's for each supported device (or family) as this
allows developers who are working on targeting a site to a specific
device to concentrate on that device.
- Tiles template level logic - again not ideal as I would like to be
able to use specific templates for device types.



As you rightly say, this is a maintenance nightmare.

  

Better but not perfect would be some sort of post action result
modifying interceptor such that in the struts.xml I could define a
number of different result mappings such as success, success_winmob,
success_blackberry_storm and have the result string that has been
returned from the action (success) modified by some sort of interceptor
(e.g. appending the suffix prior to struts mapping it off to a view)  -
the filter itself could be configured as to whether or not to alter
result strings based on the action and the user device. - Is it possible
to modify the result string post action but prior to struts resolving
the mapping? And if so would I have access to the the name of the action?




You can attach PreResultListeners[1] onto interceptor & action stack
executions. These execute after an action is executed, but before the
result is rendered. At this point, you are free to reach in and fiddle
with the action's returned result code. You can get the action's name if
you require, and manipulate the action in any way - it can be fetched from
the ActionInvocation.

I've used this feature in the past to perform a final "security
checkpoint" on any item being pulled from a database - the
PreResultListener examines the action (by reflection or otherwise) to find
the object, and checks the user is allowed to retrieve it.

Your idea is probably the sanest way to do it. Write an interceptor[2]
that gets the HttpRequest[3] object, and examines the user agent to
determine what kind of device is making the request. Then it attaches an
appropriate PreResultListener to the stack (for example, you could have
individual subclasses for each device type, and maybe configure them with
a string representing the version, which the PreResultListener uses in its
internal logic).

The PreResultListeners examine the action's result, and if it's success
they modify it to success_devicetype_version, which corresponds to the JSP
/WEB-INF/jsp/devicetype/version/success.jsp, for example. The only ugly
part of this is you'll have lots of results defined for each action in
struts.xml, but at least you have sane separation of your JSPs.

HTH,
Andy.

[1]
http://struts.apache.org/2.1.8.1/docs/can-we-access-an-actions-result.html
[2] http://struts.apache.org/2.1.8.1/docs/interceptors.html
[3]
http://struts.apache.org/2.1.8.1/docs/how-can-we-access-the-httpservletrequest.html


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



__ NOD32 4817 (20100129) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com



  



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Modifying action mapping per device type

2010-01-29 Thread Marcus Bond
Interesting, I hadn't thought of that. However a problem I see here with 
this approach is that it implies that there would be different versions 
or a different mapping for every view whereas in reality, if a page 
looks / works fine on say iphone, htc, windows mobile but doesn't on an 
old blackberry then I want to be able to create a tweaked page for one 
device, but all others would use the same page and mapping.


Gabriel Belingueres wrote:

How about using different packages/namespaces for the views?



/bb/index.jsp





/wm/index.jsp




2010/1/28 Marcus Bond :
  

Hi,

I am wanting to implement a site such that some actions may have a different
mapping depending upon the device used (e.g. regular browser / mobile device
etc.) but what I don't want to do is have to litter my actions with this
type of logic. It could be at the result mapping level (i.e. in struts.xml)
such that say a result of success would map to a jsp of somePage.jsp for
regular browsers and somePageMobile.jsp for a mobile device (there will be
more complications to this as I'd like to be able to have fine grained
control based on the user agent so there may be many versions of a jsp such
as somePageWinMobile6_5_htc.jsp).

There are  couple of ways I can think of to do this, but they're ugly:
- JSP level logic to render the page differently - dont want it, I'd rather
individual jsp's for each supported device (or family) as this allows
developers who are working on targeting a site to a specific device to
concentrate on that device.
- Tiles template level logic - again not ideal as I would like to be able to
use specific templates for device types.

Better but not perfect would be some sort of post action result modifying
interceptor such that in the struts.xml I could define a number of different
result mappings such as success, success_winmob, success_blackberry_storm
and have the result string that has been returned from the action (success)
modified by some sort of interceptor (e.g. appending the suffix prior to
struts mapping it off to a view)  - the filter itself could be configured as
to whether or not to alter result strings based on the action and the user
device. - Is it possible to modify the result string post action but prior
to struts resolving the mapping? And if so would I have access to the the
name of the action?

Any suggestions here are greatly appreciated!
Web technologies being used are Struts2, Tiles2 and JSP.

Regards,
Marcus

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org





-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



__ NOD32 4817 (20100129) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com



  



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Modifying action mapping per device type

2010-01-28 Thread Marcus Bond

Hi,

I am wanting to implement a site such that some actions may have a 
different mapping depending upon the device used (e.g. regular browser / 
mobile device etc.) but what I don't want to do is have to litter my 
actions with this type of logic. It could be at the result mapping level 
(i.e. in struts.xml) such that say a result of success would map to a 
jsp of somePage.jsp for regular browsers and somePageMobile.jsp for a 
mobile device (there will be more complications to this as I'd like to 
be able to have fine grained control based on the user agent so there 
may be many versions of a jsp such as somePageWinMobile6_5_htc.jsp).


There are  couple of ways I can think of to do this, but they're ugly:
- JSP level logic to render the page differently - dont want it, I'd 
rather individual jsp's for each supported device (or family) as this 
allows developers who are working on targeting a site to a specific 
device to concentrate on that device.
- Tiles template level logic - again not ideal as I would like to be 
able to use specific templates for device types.


Better but not perfect would be some sort of post action result 
modifying interceptor such that in the struts.xml I could define a 
number of different result mappings such as success, success_winmob, 
success_blackberry_storm and have the result string that has been 
returned from the action (success) modified by some sort of interceptor 
(e.g. appending the suffix prior to struts mapping it off to a view)  - 
the filter itself could be configured as to whether or not to alter 
result strings based on the action and the user device. - Is it possible 
to modify the result string post action but prior to struts resolving 
the mapping? And if so would I have access to the the name of the action?


Any suggestions here are greatly appreciated!
Web technologies being used are Struts2, Tiles2 and JSP.

Regards,
Marcus

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org