RE: Custom error message per converter

2013-05-23 Thread Alfredo Manuel Osorio Martinez
Conversion errors are always reported with a default message defined in the 
xwork.default.invalid.fieldvalue (Invalid field value for field "xxx", where 
xxx is the field name) but what I want is a way to be more specific depending 
of the type. For example for java.math.BigDecimal a custom message for 
java.lang.Integer another message and so on and if no custom message is found 
the default is showed. 

-Mensaje original-
De: Alfredo Manuel Osorio Martinez 
Enviado el: Thursday, May 23, 2013 8:50 AM
Para: Struts Users Mailing List
Asunto: RE: Custom error message per converter

Sure.

public class DateConverter extends StrutsTypeConverter {
@SuppressWarnings("rawtypes")
public Object convertFromString(Map context, String[] values, Class 
toClass) {
if (values != null && values.length > 0 && values[0] != null && 
values[0].length() > 0) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/");
try {
return sdf.parse(values[0]);
}
catch(ParseException e) {
throw new TypeConversionException(e);
}
}
return null;
}
@SuppressWarnings("rawtypes")
public String convertToString(Map context, Object o) {
if (o instanceof Date) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/");
return sdf.format((Date)o);
}
return "";
}
}


-Mensaje original-
De: Lukasz Lenart [mailto:lukaszlen...@apache.org] Enviado el: Thursday, May 
23, 2013 8:01 AM
Para: Struts Users Mailing List
Asunto: Re: Custom error message per converter

Could you show source code of your DateConverter?


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/


2013/5/23 Alfredo Manuel Osorio Martinez :
> Hello,
>
> Is it possible to configure a custom error message per converter?
>
> For example I have this in my xwork-conversion.properties:
> java.util.Date=mx.com.afirme.midas2.converter.DateConverter
>
> Whenever a Date conversion fails in any action I'd like to show a message 
> like this:
> Incorrect format, expected mm/dd/
>
> I don't want to define a custom message per property as mentioned in the 
> documentation:
> http://struts.apache.org/release/2.3.x/docs/type-conversion.html
>
> "However, sometimes you may wish to override this message on a per-field 
> basis. You can do this by adding an i18n key associated with just your action 
> (Action.properties) using the pattern invalid.fieldvalue.xxx, where xxx is 
> the field name."
>
>
> Alfredo Osorio
>

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



RE: Custom error message per converter

2013-05-23 Thread Alfredo Manuel Osorio Martinez
Sure.

public class DateConverter extends StrutsTypeConverter {
@SuppressWarnings("rawtypes")
public Object convertFromString(Map context, String[] values, Class 
toClass) {
if (values != null && values.length > 0 && values[0] != null && 
values[0].length() > 0) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/");
try {
return sdf.parse(values[0]);
}
catch(ParseException e) {
throw new TypeConversionException(e);
}
}
return null;
}
@SuppressWarnings("rawtypes")
public String convertToString(Map context, Object o) {
if (o instanceof Date) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/");
return sdf.format((Date)o);
}
return "";
}
}


-Mensaje original-
De: Lukasz Lenart [mailto:lukaszlen...@apache.org] 
Enviado el: Thursday, May 23, 2013 8:01 AM
Para: Struts Users Mailing List
Asunto: Re: Custom error message per converter

Could you show source code of your DateConverter?


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/


2013/5/23 Alfredo Manuel Osorio Martinez :
> Hello,
>
> Is it possible to configure a custom error message per converter?
>
> For example I have this in my xwork-conversion.properties:
> java.util.Date=mx.com.afirme.midas2.converter.DateConverter
>
> Whenever a Date conversion fails in any action I'd like to show a message 
> like this:
> Incorrect format, expected mm/dd/
>
> I don't want to define a custom message per property as mentioned in the 
> documentation:
> http://struts.apache.org/release/2.3.x/docs/type-conversion.html
>
> "However, sometimes you may wish to override this message on a per-field 
> basis. You can do this by adding an i18n key associated with just your action 
> (Action.properties) using the pattern invalid.fieldvalue.xxx, where xxx is 
> the field name."
>
>
> Alfredo Osorio
>

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



Custom error message per converter

2013-05-22 Thread Alfredo Manuel Osorio Martinez
Hello,

Is it possible to configure a custom error message per converter?

For example I have this in my xwork-conversion.properties:
java.util.Date=mx.com.afirme.midas2.converter.DateConverter

Whenever a Date conversion fails in any action I'd like to show a message like 
this:
Incorrect format, expected mm/dd/

I don't want to define a custom message per property as mentioned in the 
documentation:
http://struts.apache.org/release/2.3.x/docs/type-conversion.html

"However, sometimes you may wish to override this message on a per-field basis. 
You can do this by adding an i18n key associated with just your action 
(Action.properties) using the pattern invalid.fieldvalue.xxx, where xxx is the 
field name."


Alfredo Osorio



RE: Redirect and pass as a parameter the original url from an Interceptor

2011-03-17 Thread Alfredo Manuel Osorio Martinez
Thanks all for your answers, I solved it by calling request.getRequestURL() and 
setting a request attribute with the original url. The redirect gets that 
attribute and includes it in the querystring. 




/agente/RegistrarAgenteAction_input.action?urlOriginal=${#request.urlOriginal}



I will also check the Spring Security.

Alfredo Osorio

-Mensaje original-
De: Roger Varley [mailto:roger.var...@googlemail.com] 
Enviado el: Thursday, March 17, 2011 4:48 PM
Para: Struts Users Mailing List
Asunto: Re: Redirect and pass as a parameter the original url from an 
Interceptor

On Thu, 2011-03-17 at 12:48 -0600, Alfredo Manuel Osorio Martinez wrote:
> I am implementing a Login interceptor which needs to redirect to an
> action to first authenticate the user. The problem is that I want to
> send as a parameter to that action the original url, the one that the
> user was trying to get before the redirect to the login page.

This is not a direct answer to your question, but I would suggest that
rather than re-inventing the wheel, you take a look at integrating
Spring Security, what you're looking for is implemented "out of the box"
with a bit of configuration.

Regards



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



Redirect and pass as a parameter the original url from an Interceptor

2011-03-17 Thread Alfredo Manuel Osorio Martinez
I am implementing a Login interceptor which needs to redirect to an
action to first authenticate the user. The problem is that I want to
send as a parameter to that action the original url, the one that the
user was trying to get before the redirect to the login page.

 

How can I achieve that?

 

Thanks in advance,

 

Alfredo Osorio



Strus 2 populate select dynamically

2011-02-04 Thread Alfredo Manuel Osorio Martinez
What's the best approach to populate a select box dynamically?

 

Imagine I need select boxes for the following fields (vehicle):

Make

Model

Year

 

Each of them are linked. If I select Make model should refresh and so
for model and year.

 

I was thinking about using  tag  to render the output but
I've heard that's not recommended.

 

Also I've heard that you should implement it in the prepare() method of
the Preparable interface but I have my doubts because what if I need to
use those select boxes across different jsp pages, should I repeat the
same logic through all those prepare() methods of their respective
Actions?

 

Another approach would be to use javascript and get the values through
AJAX.

 

Or should I use JSP custom tags?

 

What do you think? What do you suggest?

 

Alfredo Osorio



RE: Create/Update with nested domain objects

2011-01-20 Thread Alfredo Manuel Osorio Martinez
Hmm,I think that is a clean approach because as far as my service is
concerned is just to update or save. And somehow the referenced objects
are already set because of the prepare method. But I would like to know
if that is true or is there another better approach to do it.

Alfredo Osorio

-Mensaje original-
De: Alfredo Manuel Osorio Martinez 
Enviado el: Thursday, January 20, 2011 9:05 AM
Para: 'Struts Users Mailing List'
Asunto: RE: Create/Update with nested domain objects

Any thoughts on this? Please...

Alfredo Osorio

-Mensaje original-
De: Alfredo Manuel Osorio Martinez 
Enviado el: Tuesday, January 18, 2011 10:15 AM
Para: Struts Users Mailing List
Asunto: Create/Update with nested domain objects

Hello,

I have seen examples that show how to do CRUD with one domain object
without nested domain objects (just primitives). Giving the following
example:

@Entity
public class Person implements Serializable {
@Id
private Long id;
private String name;
private Integer age;
private Address address;
private MaritalStatus maritalStatus;
... //getters/setters
}

@Entity
public class MaritalStatus implements Serializable {
@Id
private Long id;
private String description;
... //getters/setters
}

@Entity
public class Address implements Serializable {
@Id
private Long id;
private String street;
private String state;
private String zip;
... //getters/setters
}

Let's say I have a form which creates or update a Person and ask for the
following inputs:
Name: 
Age: ___
Street: _
State: ___
Zip: 
Marital Status: (a select input with the corresponding key(id of the
entity)/value)

So how do you create or update having nested properties which has their
own identity too (persisted in another table).

I was thinking something like this using the prepare method and
paramsPrepareParamsStack:

public class PersonAction extends ActionSupport {
public String save() {
personService.save(person);
return SUCCESS;
}

public String update() {
personService.update(person);
return SUCCESS;
}

public void prepare() {
if (person.getId() != null) {
//find the person using the id.
Person p =
personService.findById(person.getId());

//Update the reference to the selected martial
status
//find the maritalstatus selected from the
select box
MaritalStatus maritalStatus = 

maritalStatusSerivce.findById(person.getMaritalStatus().getId());
//set the reference to the obtained person
p.setMaritalStatus(maritalStatus);

//find the address (in case it already exist)
if (person.getAddress().getId() != null) {
//find the address
Address address =
addressService.findById(person.getAddress().getId());
//set the reference
p.setAddress(address);
}

//finally set the obtained reference to the
action person property
this.person = p;
} else { //New person
//Find the address for the person
if (person.getAddress().getId() != null) {
//Only set the reference to the selected
marital status
//find the maritalstatus selected from
the select box
MaritalStatus maritalStatus = 

maritalStatusSerivce.findById(person.getMaritalStatus().getId());
//set the reference to the person
person.setMaritalStatus(maritalStatus);
}
}
}

private Person person;
//getter/setters
}

Is that the correct way? Any other suggested approach?

Thanks

Alfredo Osorio

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



RE: Create/Update with nested domain objects

2011-01-20 Thread Alfredo Manuel Osorio Martinez
Any thoughts on this? Please...

Alfredo Osorio

-Mensaje original-
De: Alfredo Manuel Osorio Martinez 
Enviado el: Tuesday, January 18, 2011 10:15 AM
Para: Struts Users Mailing List
Asunto: Create/Update with nested domain objects

Hello,

I have seen examples that show how to do CRUD with one domain object
without nested domain objects (just primitives). Giving the following
example:

@Entity
public class Person implements Serializable {
@Id
private Long id;
private String name;
private Integer age;
private Address address;
private MaritalStatus maritalStatus;
... //getters/setters
}

@Entity
public class MaritalStatus implements Serializable {
@Id
private Long id;
private String description;
... //getters/setters
}

@Entity
public class Address implements Serializable {
@Id
private Long id;
private String street;
private String state;
private String zip;
... //getters/setters
}

Let's say I have a form which creates or update a Person and ask for the
following inputs:
Name: 
Age: ___
Street: _
State: ___
Zip: 
Marital Status: (a select input with the corresponding key(id of the
entity)/value)

So how do you create or update having nested properties which has their
own identity too (persisted in another table).

I was thinking something like this using the prepare method and
paramsPrepareParamsStack:

public class PersonAction extends ActionSupport {
public String save() {
personService.save(person);
return SUCCESS;
}

public String update() {
personService.update(person);
return SUCCESS;
}

public void prepare() {
if (person.getId() != null) {
//find the person using the id.
Person p =
personService.findById(person.getId());

//Update the reference to the selected martial
status
//find the maritalstatus selected from the
select box
MaritalStatus maritalStatus = 

maritalStatusSerivce.findById(person.getMaritalStatus().getId());
//set the reference to the obtained person
p.setMaritalStatus(maritalStatus);

//find the address (in case it already exist)
if (person.getAddress().getId() != null) {
//find the address
Address address =
addressService.findById(person.getAddress().getId());
//set the reference
p.setAddress(address);
}

//finally set the obtained reference to the
action person property
this.person = p;
} else { //New person
//Find the address for the person
if (person.getAddress().getId() != null) {
//Only set the reference to the selected
marital status
//find the maritalstatus selected from
the select box
MaritalStatus maritalStatus = 

maritalStatusSerivce.findById(person.getMaritalStatus().getId());
//set the reference to the person
person.setMaritalStatus(maritalStatus);
}
}
}

private Person person;
//getter/setters
}

Is that the correct way? Any other suggested approach?

Thanks

Alfredo Osorio

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



RE: Add a map to HttpRequest attributes

2011-01-19 Thread Alfredo Manuel Osorio Martinez
What about iterating the map and put each attribute in the HttpRequest.

Something like this:
Map myMap = getMyMap();
Set> entrySet = myMap.entrySet();
for (Map.Entry entry : myMap.entrySet()) {
request.setAttribute(entry.getKey(), entry.getValue());
}

Alfredo Osorio

-Mensaje original-
De: Dave Evans [mailto:dsevan...@gmail.com] 
Enviado el: Wednesday, January 19, 2011 4:21 PM
Para: Struts Users Mailing List
Asunto: Add a map to HttpRequest attributes

Hello,

I have a business layer method that returns a map of objects. I would
like to put all of the keys and values of this map into the request
attribute map, like this:
HttpRequest.putAll(map);
This of course doesn't work, as the request isn't a map and the
attributes map isn't available as a map.

Are there any Struts or Apache commons utils that will do this?

Thanks,

Dave

-
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



Create/Update with nested domain objects

2011-01-18 Thread Alfredo Manuel Osorio Martinez
Hello,

I have seen examples that show how to do CRUD with one domain object
without nested domain objects (just primitives). Giving the following
example:

@Entity
public class Person implements Serializable {
@Id
private Long id;
private String name;
private Integer age;
private Address address;
private MaritalStatus maritalStatus;
... //getters/setters
}

@Entity
public class MaritalStatus implements Serializable {
@Id
private Long id;
private String description;
... //getters/setters
}

@Entity
public class Address implements Serializable {
@Id
private Long id;
private String street;
private String state;
private String zip;
... //getters/setters
}

Let's say I have a form which creates or update a Person and ask for the
following inputs:
Name: 
Age: ___
Street: _
State: ___
Zip: 
Marital Status: (a select input with the corresponding key(id of the
entity)/value)

So how do you create or update having nested properties which has their
own identity too (persisted in another table).

I was thinking something like this using the prepare method and
paramsPrepareParamsStack:

public class PersonAction extends ActionSupport {
public String save() {
personService.save(person);
return SUCCESS;
}

public String update() {
personService.update(person);
return SUCCESS;
}

public void prepare() {
if (person.getId() != null) {
//find the person using the id.
Person p =
personService.findById(person.getId());

//Update the reference to the selected martial
status
//find the maritalstatus selected from the
select box
MaritalStatus maritalStatus = 

maritalStatusSerivce.findById(person.getMaritalStatus().getId());
//set the reference to the obtained person
p.setMaritalStatus(maritalStatus);

//find the address (in case it already exist)
if (person.getAddress().getId() != null) {
//find the address
Address address =
addressService.findById(person.getAddress().getId());
//set the reference
p.setAddress(address);
}

//finally set the obtained reference to the
action person property
this.person = p;
} else { //New person
//Find the address for the person
if (person.getAddress().getId() != null) {
//Only set the reference to the selected
marital status
//find the maritalstatus selected from
the select box
MaritalStatus maritalStatus = 

maritalStatusSerivce.findById(person.getMaritalStatus().getId());
//set the reference to the person
person.setMaritalStatus(maritalStatus);
}
}
}

private Person person;
//getter/setters
}

Is that the correct way? Any other suggested approach?

Thanks

Alfredo Osorio

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



RE: Struts 2 JSR-303 Bean Validation Support

2010-12-20 Thread Alfredo Manuel Osorio Martinez
What I mean is out of the box support/integration.

-Mensaje original-
De: stanl...@gmail.com [mailto:stanl...@gmail.com] 
Enviado el: Monday, December 20, 2010 11:06 AM
Para: Struts Users Mailing List
Asunto: Re: Struts 2 JSR-303 Bean Validation Support

Not quite sure what that means.  JSR303 is an annotations based
validation
API and you could certainly add your own JSR303Interceptor at the
appropriate point in the stack.

On Mon, Dec 20, 2010 at 10:41 AM, Alfredo Manuel Osorio Martinez <
alfredo.oso...@afirme.com> wrote:

> Hello,
>
> Does Struts 2 have support for JSR-303 Bean Validation?
>
>
> Alfredo Osorio
>
> -
> 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



Struts 2 JSR-303 Bean Validation Support

2010-12-20 Thread Alfredo Manuel Osorio Martinez
Hello,

Does Struts 2 have support for JSR-303 Bean Validation?


Alfredo Osorio

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



RE: Question about OGNL / EL

2010-12-06 Thread Alfredo Manuel Osorio Martinez
Try replacing %{partnerId} with %{#session.partnerId}

Alfredo Osorio

-Mensaje original-
De: Greg Akins [mailto:angryg...@gmail.com] 
Enviado el: Monday, December 06, 2010 11:16 AM
Para: user@struts.apache.org
Asunto: Question about OGNL / EL

This might not be specifically a OGNL question.  I've got some code
that doesn't appear to behave correctly.

 -
${partnerId}


When I open this page the title includes the partnerId but the url
doesn't

partnerId is set on the Session.  I'm wondering if it isn't set when
the  tag is evaluated, but is when the EL expression is
evaluated.

Any other idea why this wouldn't be working?

-- 
Greg Akins

http://insomnia-consulting.org
http://www.pghcodingdojo.org
http://pittjug.dev.java.net
http://twitter.com/akinsgre
http://www.linkedin.com/in/akinsgre

-
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: ActionErrors and ActionMessages not included in the result generated by org.apache.struts2.json.JSONResult

2010-11-22 Thread Alfredo Manuel Osorio Martinez
I found out looking at the code that in order that properties of
superclass get included in the json output you need to set
ignoreHierarchy param to false:

false


Alfredo Osorio
-Mensaje original-
De: Alfredo Manuel Osorio Martinez 
Enviado el: Monday, November 22, 2010 2:03 PM
Para: Struts Users Mailing List
Asunto: ActionErrors and ActionMessages not included in the result
generated by org.apache.struts2.json.JSONResult

Hello,

I'm trying to generate a json output with the JSONResult but the problem
is that actionMessages and actionErrors properties are not being
included.

I also tried to pass this parameter to the interceptor but it didn't
work:

actionErrors,actionMessages


Please help, what am I doing wrong?

Thanks in advance

Alfredo Osorio

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



ActionErrors and ActionMessages not included in the result generated by org.apache.struts2.json.JSONResult

2010-11-22 Thread Alfredo Manuel Osorio Martinez
Hello,

I'm trying to generate a json output with the JSONResult but the problem
is that actionMessages and actionErrors properties are not being
included.

I also tried to pass this parameter to the interceptor but it didn't
work:

actionErrors,actionMessages


Please help, what am I doing wrong?

Thanks in advance

Alfredo Osorio

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



RE: RE: Have you ever used InputConfig annotation?

2010-11-08 Thread Alfredo Manuel Osorio Martinez
Hello Dave,

> you can trivially avoid unnecessary prepare calls.

How can I avoid unnecessary prepare calls? I mean how can I avoid the
prepare method won't be called if there are not validation errors.

Thanks in advance

Alfredo Osorio

-Mensaje original-
De: Dave Newton [mailto:davelnew...@gmail.com] 
Enviado el: Monday, November 08, 2010 1:30 PM
Para: Struts Users Mailing List
Asunto: Re: RE: Have you ever used InputConfig annotation?

And I'm saying #1 that a testable action is worth a lot and #2 you can
trivially avoid unnecessary prepare calls.

Dave
 On Nov 8, 2010 1:54 PM, "Alfredo Manuel Osorio Martinez" <
alfredo.oso...@afirme.com> wrote:
> Hello Dave and thanks for your response,
>
> I think I didn't explain myself what I tried to say is whenever you
> submit to the action that will process the input data that action's
> prepare (or prepareXXX) needs to know how to populate the data needed
> for the input result and that's because if validation fails the result
> will be the input result (where the data came from) and needs that
data
> for the repopulation of some controls (list, etc). So whether the
> validation passed or failed that logic is always called. So is that
the
> price you have to pay for a cleaner testable action? My point is the
> overhead of calling that method (prepare) for input repopulation even
> though sometimes (successful validation) you won't need it.
>
> Thanks
>
> Alfredo Osorio
>
> -Mensaje original-
> De: Dave Newton [mailto:davelnew...@gmail.com]
> Enviado el: Monday, November 08, 2010 10:47 AM
> Para: Struts Users Mailing List
> Asunto: Re: Have you ever used InputConfig annotation?
>
> On Mon, Nov 8, 2010 at 10:07 AM, Alfredo Manuel Osorio Martinez wrote:
>> Are you saying that input methods shouldn't have any logic in and
just
>> return the string of the result. If that's the case where should you
>> retrieve those list values? What other alternatives do I have? The
> only
>> other one that comes to my mind is Preparable and action tag.
>
> Preparable; I have issues with using  tag for that as well;
> it puts too much responsibility into the view layer, and means you
> *must* integration-test the entire flow, including page rendering, in
> order to know if the action works, rather than testing the action in
> isolation.
>
> My acid test for determining what's appropriate in a method:
>
> Pass:
>
> Q: What does getInputResultNameDo?
> A: Returns the name of the input result.
>
> Fail:
>
> Q: What does getInputResultNameDo?
> A: It gets the name to use for the input result. And goes to the
> database, retrieves a bunch of values, handles persistence-layer
> Texceptions, and may populate error messages to return to the user.
>
>> So in the cases where the validation is going to be
>> successful why would you want to retrieve the input lists values or
>> other stuff for the input result if you are not even going to use it.
>> Isn't that unnecessary overhead?
>
> Don't submit to the same action. Or use prepare{methodName}. Or take
> advantage of it being a MethodFilterInterceptor and configure it to
> run only for the methods you want. Or extend it to default to your
> desired application-specific behavior. Or...
>
> Dave
>
> -
> 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: Have you ever used InputConfig annotation?

2010-11-08 Thread Alfredo Manuel Osorio Martinez
Hello Dave and thanks for your response,

I think I didn't explain myself what I tried to say is whenever you
submit to the action that will process the input data that action's
prepare (or prepareXXX) needs to know how to populate the data needed
for the input result and that's because if validation fails the result
will be the input result (where the data came from) and needs that data
for the repopulation of some controls (list, etc). So whether the
validation passed or failed  that logic is always called. So is that the
price you have to pay for a cleaner testable action? My point is the
overhead of calling that method (prepare) for input repopulation even
though sometimes (successful validation) you won't need it.

Thanks

Alfredo Osorio

-Mensaje original-
De: Dave Newton [mailto:davelnew...@gmail.com] 
Enviado el: Monday, November 08, 2010 10:47 AM
Para: Struts Users Mailing List
Asunto: Re: Have you ever used InputConfig annotation?

On Mon, Nov 8, 2010 at 10:07 AM, Alfredo Manuel Osorio Martinez wrote:
> Are you saying that input methods shouldn't have any logic in and just
> return the string of the result. If that's the case where should you
> retrieve those list values? What other alternatives do I have? The
only
> other one that comes to my mind is Preparable and action tag.

Preparable; I have issues with using  tag for that as well;
it puts too much responsibility into the view layer, and means you
*must* integration-test the entire flow, including page rendering, in
order to know if the action works, rather than testing the action in
isolation.

My acid test for determining what's appropriate in a method:

Pass:

Q: What does getInputResultNameDo?
A: Returns the name of the input result.

Fail:

Q: What does getInputResultNameDo?
A: It gets the name to use for the input result. And goes to the
database, retrieves a bunch of values, handles persistence-layer
Texceptions, and may populate error messages to return to the user.

> So in the cases where the validation is going to be
> successful why would you want to retrieve the input lists values or
> other stuff for the input result if you are not even going to use it.
> Isn't that unnecessary overhead?

Don't submit to the same action. Or use prepare{methodName}. Or take
advantage of it being a MethodFilterInterceptor and configure it to
run only for the methods you want. Or extend it to default to your
desired application-specific behavior. Or...

Dave

-
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: Have you ever used InputConfig annotation?

2010-11-08 Thread Alfredo Manuel Osorio Martinez
Hello,

> I still don't believe using a framework-defined method, whose intent
is to
> return a string result name, to load data is an expressive design.

Are you saying that input methods shouldn't have any logic in and just
return the string of the result. If that's the case where should you
retrieve those list values? What other alternatives do I have? The only
other one that comes to my mind is Preparable and action tag.

About Preparable interface and input field repopulation there is
something that I don't get it. When you submit the form data to the
action the Preparable (prepare method) will be executed regardless of
validation. So in the cases where the validation is going to be
successful why would you want to retrieve the input lists values or
other stuff for the input result if you are not even going to use it.
Isn't that unnecessary overhead?

Alfredo Osorio

-Mensaje original-
De: Dave Newton [mailto:davelnew...@gmail.com] 
Enviado el: Saturday, November 06, 2010 6:30 AM
Para: Struts Users Mailing List
Asunto: Re: Have you ever used InputConfig annotation?

I still don't believe using a framework-defined method, whose intent is
to
return a string result name, to load data is an expressive design.
 On Nov 6, 2010 2:36 AM, "Maurizio Cucchiara"

wrote:
> InputConfig works as documented. I reccomend to use Li's suggestion
> for inheritance matter. When you need to overwrite base class
> behavior, then mark method with InputConfig annotation.
>
> 2010/11/5 Alfredo Manuel Osorio Martinez :
>> Hello,
>>
>> By looking at DefaultWorkflowInterceptor I saw an annotation that I
>> didn't know existed. I am talking about:
>>
>> com.opensymphony.xwork2.interceptor.annotations.InputConfig
>>
>> I think it can be used for input repopulation and can be used as an
>> alternative to Preparable and .
>>
>> What surprised me was that there is a little documentation about the
use
>> of the annotation or examples.
>>
>> Haver you ever used this one before?
>>
>> Is it a good idea to use it for input repopulation for example
>> collections for selects in case a validation fails?
>>
>> Thanks
>>
>>
>>
>> -
>> 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-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



Have you ever used InputConfig annotation?

2010-11-05 Thread Alfredo Manuel Osorio Martinez
Hello,

By looking at DefaultWorkflowInterceptor I saw an annotation that I
didn't know existed. I am talking about:

com.opensymphony.xwork2.interceptor.annotations.InputConfig

I think it can be used for input repopulation and can be used as an
alternative to Preparable and .

What surprised me was that there is a little documentation about the use
of the annotation or examples.

Haver you ever used this one before?

Is it a good idea to use it for input repopulation for example
collections for selects in case a validation fails?

Thanks



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



RE: Struts 2 s:action tag doesn't render action errors if any are present

2010-10-28 Thread Alfredo Manuel Osorio Martinez
I am using defaultStack but I was reading the issue you just told me:

https://issues.apache.org/jira/browse/WW-2869

And talks about invoking an action with the action tag an
ChainingInterceptor but I don't know if the actionErrors from the source
action will be copied. 

And by the way I am using the lastest version 2.2.1


-Mensaje original-
De: Maurizio Cucchiara [mailto:maurizio.cucchi...@gmail.com] 
Enviado el: Thursday, October 28, 2010 5:25 PM
Para: Struts Users Mailing List
Asunto: Re: Struts 2 s:action tag doesn't render action errors if any
are present

> Which interceptor do you mean? ChainingInterceptor?

I meant implementing a new Interceptor from scratch. Although this
issue are related to the chainInterceptor.
What interceptor stack are you using? Does your request fire
chainInterceptor?

2010/10/29 Alfredo Manuel Osorio Martinez :

--
Maurizio Cucchiara

-
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: Struts 2 s:action tag doesn't render action errors if any are present

2010-10-28 Thread Alfredo Manuel Osorio Martinez
Which interceptor do you mean? ChainingInterceptor?

Alfredo Osorio

-Mensaje original-
De: Maurizio Cucchiara [mailto:maurizio.cucchi...@gmail.com] 
Enviado el: Thursday, October 28, 2010 4:25 PM
Para: Struts Users Mailing List
Asunto: Re: Struts 2 s:action tag doesn't render action errors if any
are present

I totally agree with Dave: ParameterInterceptor is the better choice.
BTW, I'm not sure it fits your needs but you should take a look at
this issue https://issues.apache.org/jira/browse/WW-2869 and
https://issues.apache.org/jira/browse/WW-3488 (especially where Lukasz
talked about copyErrors and copyMessages flags)

Anyway, you should be able to copy actionError through actions simply
by implementing an Interceptor.

-- 
Maurizio Cucchiara

-
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: Struts 2 s:action tag doesn't render action errors if any are present

2010-10-28 Thread Alfredo Manuel Osorio Martinez
The problem is that the functionality it's already working except for the 
validation message part. Also the scenario was just an example it's not the 
real code from the application. 

In my application I have 4 controls Country, State, City and Postal Code and I 
need to use that four controls on different pages across the application in 
different JSPs. So for the sake of modularity I thought that using the action 
approach would work and it does except for the validation messages.

> You might be able to configure the action in such a way that the
> actionErrors property is filled off the value stack, but ew.

I'd like to know how can I put the actionErrors property set to the parent 
action actionErrors in order to let the messages get rendered properly.

Thanks

Alfredo


-Mensaje original-
De: Dave Newton [mailto:davelnew...@gmail.com] 
Enviado el: Thursday, October 28, 2010 1:10 PM
Para: Struts Users Mailing List
Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are 
present

You could try keeping them in the session, but that might involve
tricky configuration sometimes--not sure. You're rendering a single
control; I don't see that you're saving much... I still believe
Preparable is a cleaner choice.

You might be able to configure the action in such a way that the
actionErrors property is filled off the value stack, but ew.

Dave

On Thursday, October 28, 2010, Alfredo Manuel Osorio Martinez
 wrote:
> Hello Dave and thank you for your quick response,
>
> 1. Let's say I want to keep doing the rendering of the control in that way. 
> How would I solve the problem with the action error messages?
> 2. What I liked about having an action for rendering the controls it's that I 
> can reuse them across different JSP pages.  What other alternatives do you 
> suggest me that can achieve the same level of modularity?
>
>
> Alfredo Osorio
>
> -Mensaje original-
> De: Dave Newton [mailto:davelnew...@gmail.com]
> Enviado el: Thursday, October 28, 2010 12:51 PM
> Para: Struts Users Mailing List
> Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are 
> present
>
> Rendering a control (and repopulating its values) is a different thing
> than displaying validation error messages.
>
> IMO the way you're doing it isn't a particularly good idea; it would
> be better to render the control on the page, *possibly* using s:action
> to create the list of possible values (which I also really don't
> like), but not to render the control. Note that the text on that page
> states only that the control will be populated and rendered, which is
> true.
>
> I'm opposed to using the s:action tag as a solution to this problem in
> general; I don't think it's a good idea, and introduces more issues
> than it solves, particularly since better alternatives exist.
>
> Dave
>
> On Thu, Oct 28, 2010 at 1:35 PM, Alfredo Manuel Osorio Martinez
>  wrote:
>> For example I have the following:
>>
>> struts.xml:
>>
>> 
>>
>>    /jsp/personForm.jsp
>>
>> 
>>
>> 
>>
>>    /jsp/successSave.jsp
>>
>>    /jsp/personForm.jsp
>>
>> 
>>
>> 
>>
>>    /jsp/countries.jsp
>>
>> 
>>
>> personForm.jsp:
>>
>> <%@ taglib prefix="s" uri="/struts-tags" %>
>>
>> 
>>
>>        
>>
>>        
>>
>>        
>>
>>        
>>
>> 
>>
>> CountriesAction.java:
>>
>> public class CountriesAction extends ActionSupport {
>>
>>    public String execute() {
>>
>>        countries = getCountries();
>>
>>        return SUCCESS;
>>
>>    }
>>
>>
>>
>>    private Map getCountries() {
>>
>>            ...
>>
>>    }
>>
>>
>>
>>    private Map countries;
>>
>> }
>>
>> countries.jsp:
>>
>>    <%@ taglib prefix="s" uri="/struts-tags" %>
>>
>>    >
>>        headerKey="-1" headerValue="Please select the country ..."/>
>>
>> SavePerson.action
>>
>> public class SavePerson extends ActionSupport {
>>
>>
>>
>>    public void validate() {
>>
>>        if (firstName == "") {
>>
>>            addFieldError(firstName, "First Name is required.");
>>
>>        }
>>
>>
>>
>>        if (lastName == "") {
>>
>>            addFiel

RE: Struts 2 s:action tag doesn't render action errors if any are present

2010-10-28 Thread Alfredo Manuel Osorio Martinez
Hello Dave and thank you for your quick response,

1. Let's say I want to keep doing the rendering of the control in that way. How 
would I solve the problem with the action error messages?
2. What I liked about having an action for rendering the controls it's that I 
can reuse them across different JSP pages.  What other alternatives do you 
suggest me that can achieve the same level of modularity? 


Alfredo Osorio

-Mensaje original-
De: Dave Newton [mailto:davelnew...@gmail.com] 
Enviado el: Thursday, October 28, 2010 12:51 PM
Para: Struts Users Mailing List
Asunto: Re: Struts 2 s:action tag doesn't render action errors if any are 
present

Rendering a control (and repopulating its values) is a different thing
than displaying validation error messages.

IMO the way you're doing it isn't a particularly good idea; it would
be better to render the control on the page, *possibly* using s:action
to create the list of possible values (which I also really don't
like), but not to render the control. Note that the text on that page
states only that the control will be populated and rendered, which is
true.

I'm opposed to using the s:action tag as a solution to this problem in
general; I don't think it's a good idea, and introduces more issues
than it solves, particularly since better alternatives exist.

Dave

On Thu, Oct 28, 2010 at 1:35 PM, Alfredo Manuel Osorio Martinez
 wrote:
> For example I have the following:
>
> struts.xml:
>
> 
>
>    /jsp/personForm.jsp
>
> 
>
> 
>
>    /jsp/successSave.jsp
>
>    /jsp/personForm.jsp
>
> 
>
> 
>
>    /jsp/countries.jsp
>
> 
>
> personForm.jsp:
>
> <%@ taglib prefix="s" uri="/struts-tags" %>
>
> 
>
>        
>
>        
>
>        
>
>        
>
> 
>
> CountriesAction.java:
>
> public class CountriesAction extends ActionSupport {
>
>    public String execute() {
>
>        countries = getCountries();
>
>        return SUCCESS;
>
>    }
>
>
>
>    private Map getCountries() {
>
>            ...
>
>    }
>
>
>
>    private Map countries;
>
> }
>
> countries.jsp:
>
>    <%@ taglib prefix="s" uri="/struts-tags" %>
>
>    
>        headerKey="-1" headerValue="Please select the country ..."/>
>
> SavePerson.action
>
> public class SavePerson extends ActionSupport {
>
>
>
>    public void validate() {
>
>        if (firstName == "") {
>
>            addFieldError(firstName, "First Name is required.");
>
>        }
>
>
>
>        if (lastName == "") {
>
>            addFieldError(lastName, "Last Name is required.");
>
>        }
>
>
>
>        if (countryId == "-1") {
>
>            addFieldError(countryId, "Country is required.");
>
>        }
>
>
>
>    }
>
>
>
>    public String execute() {
>
>        //get the properties and save the person...
>
>        return SUCCESS;
>
>    }
>
>
>
>    private String firstName;
>
>    private String lastName;
>
>    private String countryId;
>
>
>
>    //corresponding setters and getters..
>
> }
>
> When I submit the form and a validation error occurs for example let's
> say we didn't fill in any data so the input fields 'firstName' and
> 'lastName' will have their corresponding message next to them. But
> that's not the case for the country select list, even though there are
> action errors those won't display.
>
> I believe this happens because the parent action which is SavePerson is
> the one who added the errors (addFieldErrors) but when the other action
> Countries (the one that populates the list) is called then those errors
> are not available in that context because if I call hasErrors() within
> that Action it will be "false" so when the input gets rendered and check
> if there are any errors in order to render the message will call
> hasErrors and will return false so no errors messages will be rendered.
>
> This approach of calling another action just to render another input
> controls is one of the ways that Struts 2 FAQS tell to do that:
> http://struts.apache.org/2.2.1/docs/how-do-we-repopulate-controls-when-v
> alidation-fails.html
> <http://struts.apache.org/2.2.1/docs/how-do-we-repopulate-controls-when-
> validation-fails.html>
>
> So how can I make those controls on those actions render the action
> errors from its parent action.
>
> Any thoughts?
>
> Thank you in advance
>
>
>
>

-
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



Struts 2 s:action tag doesn't render action errors if any are present

2010-10-28 Thread Alfredo Manuel Osorio Martinez
For example I have the following:

struts.xml:



/jsp/personForm.jsp





/jsp/successSave.jsp

/jsp/personForm.jsp





/jsp/countries.jsp



personForm.jsp:

<%@ taglib prefix="s" uri="/struts-tags" %>













CountriesAction.java:

public class CountriesAction extends ActionSupport {

public String execute() {

countries = getCountries();

return SUCCESS;

}



private Map getCountries() {

...

}



private Map countries;  

}

countries.jsp:

<%@ taglib prefix="s" uri="/struts-tags" %>



SavePerson.action

public class SavePerson extends ActionSupport {



public void validate() {

if (firstName == "") {

addFieldError(firstName, "First Name is required.");

}



if (lastName == "") {

addFieldError(lastName, "Last Name is required.");

}



if (countryId == "-1") {

addFieldError(countryId, "Country is required.");

}



}



public String execute() {

//get the properties and save the person...

return SUCCESS;

}



private String firstName;

private String lastName;

private String countryId;



//corresponding setters and getters..

}

When I submit the form and a validation error occurs for example let's
say we didn't fill in any data so the input fields 'firstName' and
'lastName' will have their corresponding message next to them. But
that's not the case for the country select list, even though there are
action errors those won't display. 

I believe this happens because the parent action which is SavePerson is
the one who added the errors (addFieldErrors) but when the other action
Countries (the one that populates the list) is called then those errors
are not available in that context because if I call hasErrors() within
that Action it will be "false" so when the input gets rendered and check
if there are any errors in order to render the message will call
hasErrors and will return false so no errors messages will be rendered.

This approach of calling another action just to render another input
controls is one of the ways that Struts 2 FAQS tell to do that:
http://struts.apache.org/2.2.1/docs/how-do-we-repopulate-controls-when-v
alidation-fails.html
 

So how can I make those controls on those actions render the action
errors from its parent action.

Any thoughts?

Thank you in advance