TypeConversionException and the conversionError interceptor

2008-12-16 Thread Daniel Baldes

Hello,

I got a problem with type conversion errors.

I have several custom type converters which throw a 
TypeConversionException in case the conversion fails. However, the 
conversionError interceptor does not add any field errors to the action 
in that case; furthermore, it seems that struts rather tries to set the 
un-converted String, leading to an error message from the parameters 
interceptor:


SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception 
caught setting 'xxx.ipAddress' on 'class 
xxx.NidsCustomerApplicationAction: Error setting expression 
'xxx.ipAddress' with value '[Ljava.lang.String;@6dafa36'


(There is no setIpAddress(String) method, which is correct; I think this 
should never happen in the first place)


When there is no TypeConversionException, everything works fine (= the 
type converter is called and works).


I have verified (using a debugger) that the ConversionErrorInterceptor 
gets called. It calls invocationContext.getConversionErrors(), but that 
method returns an empty map. However, after the TypeConversionException 
is thrown, an error message is added to the context in 
XworkConverter.handleConversionException(...). It must get lost 
somewhere on the way to the ConversionErrorInterceptor (?).


So my questions:

- Why does struts or xwork try to set the non-converted value as string
  after conversion fails?
- Where are my error messages?
- What am I doing wrong?

Maybe there is an incompatibility among the libraries I use?

Environment:

 struts 2.0.12
 xwork 2.0.6
 ognl 2.6.11

 (tomcat 6.0.16, java 1.6.0_10 ...)

interceptor stack:

  staticParams
  prepare
  chain
  checkbox
  params
  conversionError
  validation
  workflow

(This list is reduced to the possibly relevant interceptors; there are 
several custom interceptors before and after these in my stack, but I 
think they should not interfere with this problem)


I would appreciate any help on with issue - thanks in advance!

Regards,
Daniel



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



Struts2, JDO transaction handling

2008-03-03 Thread Daniel Baldes

Hi,

If I want to edit my domain objects directly, how can I handle 
transactions? Example:


s:textfield name=login.username /

My action has getLogin(), which returns a database-persistent object. In 
order to let struts set properties of the object, a transaction must be 
active.


I wonder if there is a common way to do this, if you don't use spring.

One way around this would be to return detached objects and attach them 
in a transaction, but this leads to rather complex code because our 
domain model is heavily networked and we would need to consider what to 
detach, we cannot link non-detached objects to detached ones etc.


Any hints / suggestions?

Thanks in advance,

Daniel

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



Re: More package weirdness

2008-03-03 Thread Daniel Baldes


[EMAIL PROTECTED] wrote:

which resolves to be:

 img src=charts/questionChart.action/


The namespace is /charts, but you use charts.


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



s:select and pre-selection

2008-02-29 Thread Daniel Baldes

Hi,

I have a select box:

s:select name=user.property
  list=availableObjects listKey=id listValue=name /

availableObjects is a list of objects having an id and a name 
property, where id is of type long. user.property is 'converted' to 
its id (as String)  by a type converter.


Now, setting user.property works well with this, but the current value 
is not pre-selected when I load the form. When I show user.property in a 
textfield, the correct ID is displayed (the id of the option which 
should be pre-selected).


I found a hint in the s:select documentation, which says that for 
OGNL-generated maps, the type of the key-attribute must be the same as 
the type of the listKey property in order to match. So I implemented 
getIdAsString() and used listKey=idAsString, but it doesn't work either.


What am I doing wrong here?

(I am using struts 2.0.11)

Any help or hint will be appreciated.

Thanks in advance,

Daniel

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



Re: s:select and pre-selection

2008-02-29 Thread Daniel Baldes

Daniel Baldes wrote:

Hi,

I have a select box:

s:select name=user.property
  list=availableObjects listKey=id listValue=name /


Ok, I found it myself:

s:select name=user.property value=%{user.property.id}
  list=availableObjects listKey=id listValue=name /

this works. It seems the code which does the pre-selection does not use 
the type-converted value of user.property but the original value.


Cheers,
Daniel

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



Re: action security

2008-02-28 Thread Daniel Baldes

Brian Relph wrote:

Hi, I am concerned about security in my struts2 actions.  I am using spring
to auto-wire my actions by name, but this leads me to believe that a
malicious user can set action properties that i do not want them to.  For
example, i have a .jsp with a form input of name.  My action has a
getter/setter for the String property name.  this property is
automatically populated (by the parameterInterceptor?).  I also have a
userDao object on my action, also with getters/setters so that spring can
auto-wire it.  Is there anything that prevents a user from adding a form
input of userDao.password (just for example), and changing the password on
my userDao?  Do i need to do something to only make certain properties of my
action available to be set from request parameters?

Thanks,



Hi Brian,

you can implement the interface ParameterNameAware. Then, every 
parameter name is passed to the method boolean 
acceptableParameterName(String name) and the parameter is only set when 
it returns true.

Cheers,
Daniel

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



Re: Type conversion questions

2008-02-20 Thread Daniel Baldes

Hello Martin,

this would be ok, but that method doesn't exist in StrutsTypeConverter 
as of struts 2.0.11, and most likely the framework won't call it when I 
implement it. Or am I missing something?


Daniel

Martin Gainty wrote:

package org.apache.struts2.showcase.conversion
public class EnumTypeConverter extends StrutsTypeConverter 
{

//old methods..

//new method to convert map contents to Strings..
 @Override
public String[] convertToStrings(Map context, Object o) 
   {

   int j=0;
   Strings[] s;
List l = (List) o;
String result =;
for (Iterator i = l.iterator(); i.hasNext(); ) 
   {

  s[j++]=i.next();
}
return s;
}
//...other methods..
}



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



Re: Type conversion questions

2008-02-20 Thread Daniel Baldes

Jeromy Evans wrote:
[...]

Now my questions:

1. extending StrutsTypeConverter forces me to implement String 
convertToString(Map context, Object o). I think there is no common 
sense way of converting a collection back to a String in this context. 
It would, maybe, make sense to convert it to a String[]. But what I 
actually want is to have access to the unconverted collection in the 
JSP. This might seem strange from some point of view, and I could live 
without it, but is there a way to do this? Example:

[...]
It does really follow the intended contract of the interface, but I 
don't see why convertFromString can't return a different view of the 
object than convertToString.  Have you tried it?  This effectively gives 
you the databinding feature of ASP.net (which I personally cringe at, 
but can't argue with how productive it is to work with)


Hi Jeromy,

the problem here is that convertToString only allows returning .. a 
String. Accessing myObjects in a JSP would always call 
converter.convertToString(context, myaction.getMyObjects()) (as far as I 
can tell). So this way I can't return a collection of objects where I 
could, for example, iterate over.


Daniel

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



Re: Type conversion questions

2008-02-20 Thread Daniel Baldes

Hi Jeromy,

Jeromy Evans wrote:

Daniel Baldes wrote:

[...]
2. Is there a way to define a type converter application wide, like 
always use this type converter for setting types which are subclasses 
of X and for setting types which are Collectionsubclass-of-X? 
This way I could define the type converter once for all 
persistence-capable classes.


classpath:xwork-converters.properties allows you to define global 
converters by class name.  You may be able to the the element_ feature 
for collections.

Otherwise visitor validation will have to do


I found out that this line in xwork-conversion.properties is sufficient 
to define my custom converter for all subclasses AND collections of 
subclasses:


 com.acme.SuperClass = com.acme.CustomConverter

Perfect - this is what I need.

Thanks for your Help,

Daniel




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



Re: Type conversion questions

2008-02-20 Thread Daniel Baldes

Hi Jeromy,

Jeromy Evans wrote:

Ah, I see the problem better now.  In your select:

s:select multiple=true
   name=myObjects
   list=myObjects listKey=id listValue=name /
you're trying to access myObjects as both a list of objects (list=) and 
as a string (name=).  You can't do what you're describing because 
convertToString needs to provide the currently selected value for the 
select.


I presume you don't really mean that, but rather want:
s:select multiple=true
   name=mySelectedObject
   list=myObjects listKey=id listValue=name /

where mySelectObject is the same class as the elements in the list, and 
type conversion ensures that the select contains id:name and sees just 
the selected object loaded from persistence and provides a list of 
objects loaded from persistence (no handling of strings what-so-ever).


Sorry, now I see that my example was misleading. Let me try again:

F.e. I would want to display a list of myObjects, and a multiple 
select box where you can modify the list.


List:
s:iterator value=myObjects var=o ${o.name}/s:iterator

Select:
s:select multiple=true name=myObjects list=availableMyObjects 
listKey=id listValue=name /


This way, the iterator would need to get a collection from 
getMyObjects() (without type conversion), but the select would send IDs 
which needed to be converted.


Now the funny thing is that this seems to work. I got all sorts of 
exceptions at first, but they don't seem to be related to conversion.


Thanks for all your help, and I'm sorry for wasting your time on this 
one. I'll get back when I find the real problem, should it be related to 
struts.


Daniel

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



Re: Type conversion questions

2008-02-20 Thread Daniel Baldes

Laurie Harper wrote:

Daniel Baldes wrote:

[...]

[...]

   s:select multiple=true
name=myObjects
list=myObjects listKey=id listValue=name /

This way I could use getMyObjects() for displaying my objects and 
setMyObjects() for setting them (using only their IDs).


Doesn't this imply that the myObjects property represents both the set 
of values that can be selected *and* the set of values that is / has 
been selected? What would happen if the user made their selection(s) and 
submitted the form, and the form was re-displayed due to a validation 
error?


Maybe I'm missing the pattern, but this doesn't seem right to me :=)

L.


This example was actually misleading, I'm sorry. Please just ignore this 
part of my post, the problem may be non-existent ;-)


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



Type conversion questions

2008-02-19 Thread Daniel Baldes

Hello,

I have a web form where you can, generally speaking, assign objects to 
groups. This is done via a multiple select box which displays an 
object's name and uses its ID property as value.


So, usually, my action would get back a String array containing the IDs 
of the selected objects. I want the framework to load the corresponding 
objects from the database and pass them as a Collection to my action's 
setObjects(CollectionObject objects) method, so that my action doesn't 
have to deal with loading objects.


So I wrote a type converter. The convertFromString method takes the 
String array with the IDs, determines the target element type using 
ObjectTypeDeterminer, loads the objects and returns them in a 
collection. In this direction - form to action - it works quite well.


Now my questions:

1. extending StrutsTypeConverter forces me to implement String 
convertToString(Map context, Object o). I think there is no common sense 
way of converting a collection back to a String in this context. It 
would, maybe, make sense to convert it to a String[]. But what I 
actually want is to have access to the unconverted collection in the 
JSP. This might seem strange from some point of view, and I could live 
without it, but is there a way to do this? Example:


   s:select multiple=true
name=myObjects
list=myObjects listKey=id listValue=name /

This way I could use getMyObjects() for displaying my objects and 
setMyObjects() for setting them (using only their IDs).



2. Is there a way to define a type converter application wide, like 
always use this type converter for setting types which are subclasses 
of X and for setting types which are Collectionsubclass-of-X? This 
way I could define the type converter once for all persistence-capable 
classes.


Thanks in advance,

Daniel



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



Re: ParametersInterceptor setting values using a String[]

2008-02-14 Thread Daniel Baldes

Matthew Seaborn wrote:
Why is this happening and short of creating my own TypeConverter or 
blocking it in the logger config, how can I stop this error being logged 
for GET requests?


AFAIK this error is only logged in devMode.

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