Hello Remi,
You are right: this is more like method invocation. I was just
wondering about a best practice here with Stripes.
The thing is that my DTO is already very compact: it holds a
Map<Gender, SomeDtoWithGenderAndDouble> which is actually exposed
and provides a method
addSomeDtoWithGenderAndDouble(Gender, Double) and I was wondering if I
could go through that from Stripes :).
Anyways, thanks all for the suggestions.
Cosmin.
Hi Cosmin,
Well, setFoo(X,Y) isn't a setter in the JavaBean sense. In this case,
Foo isn't a property at all, so binding to it isn't possible I guess.
What you describe isn't property binding, it looks more like remote
method invocation...
Correct if I'm wrong (the Map thing confuses me actually), but if you
have in your domain model :
setSomething(Gender,Double)
Then IMHO the action bean should look like :
class MyAction ... {
// setters with possible validation etc.
public void setSomethingGender(Gender g) { ... }
public void setSomethingDouble(Double d) { ... }
// in the event handler, or @Before, or whatever...
public ... {
myObject.setSomething(Gender, Double);
}
}
Otherwise I'm afraid you have to create a class that acts as a
container for Gender/Double pairs, write a type converter... even
uglier IMHO :P
Cheers
Remi
On Tue, Sep 16, 2008 at 2:37 PM, Cosmin Marginean <[EMAIL PROTECTED]> wrote:
Hey Freddy,
Thanks for the prompt and detailed reply.
I know about the map-related bindings as I have some extensive
Struts/Struts2 experience. However, I need to perform some logic when
binding this value. In other words, I need more than a map. As mentioned
earlier, I would like to bind to something like
setSomething(Gender gender, Double value)
When method setSomething is called I need to perform some additional
logic. I was just wondering if it's possible to bind to something like
this, as I don't want to implement a Map for such a small issue.
As I said, this is not an actual problem as I am using a Map already to
which I am binding and then calling setSomething(...) for each entry in
the Map. My question is if I have this "option" to improve my code.
Cosmin
Hi Cosmin,
You know the old saying: the only idiotic question is the one that you
have but do not ask. :)
With your property of type Map<SomeEnum, Double>, you can indeed bind
with something['enumValue']. In this case, 'enumValue' must be one of
the values that you defined in SomeEnum, case sensitive. Stripes will
convert 'enumValue' to SomeEnum using its EnumeratedTypeConverter
(you'll find it in the net.sourceforge.stripes.validation package) and
the value to Double with DoubleTypeConverter.
For example, if you have
public enum Gender {
Female,
Male
}
and a property:
private Map<Gender, Double> map;
public Map<Gender, Double> getSomething() { return map; }
public void setSomething(Map<Gender, Double> map) { this.map = map; }
You could bind with:
<s:text name="something['Female']"/>
The value entered would be converted to a Double and bound to the map
with key Female from the Gender enum.
Let me know if that helps.
Cheers,
Freddy
http://www.stripesbook.com
-
- Hello everyone,
-
- I first want to congratulate Tim Fennell and all Stripes contributors
- for the great work they've done. I started to migrate a Struts2
- application to Stripes and I must say: I'm impressed about the level of
- integration with the standards (a section at which Struts2 sucks) and
- also about the programming model. First impression is great. Great work.
-
- I came here though also to ask for a small (and idiotic) question. I am
- trying to bind a property with a non-basic type. For this I already have
- a method on my DTO
-
- public void setSomething(SomeEnum enumValue, Double someValue) {
- // create and store a type storing enum and value
- }
-
- In other words there is some logic that must be performed when setting
- such a Double. I am currently exposing a Map<SomeEnum, Double> and I am
- converting it manually inside the action. This works for me and the
- solution is "decent". However, I was wondering if Stripes has ways of
- binding to such methods. For example, if we have a getMap() we can bind
- to map['key']. I was wondering if for my above function I would be able
- to bind in a similar way: something['enumValue'].
-
- Thanks,
- Cosmin
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url="">
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Cosmin Marginean
--
cosminaru.ro
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url="">
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url="">
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Cosmin Marginean
--
cosminaru.ro
|