struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yasser Zamani <yasser.zam...@live.com>
Subject Re: Struts 2.5 ParameterAware and HttpParametersAware
Date Sat, 16 Sep 2017 10:45:54 GMT
I reviewed Strut's internal codes and seems following works:

import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.Parameter;
import org.apache.struts2.interceptor.HttpParametersAware;

import java.util.HashMap;
import java.util.Map;

/**
  * Created by user on 9/16/2017.
  */
public class HttpParametersAwareAction implements HttpParametersAware {
     @Override
     public void setParameters(HttpParameters parameters) {
         Map<String, Parameter> newParams = new HashMap<String,Parameter>();
         for(String key :parameters.keySet()){
             Parameter p = parameters.get(key);
             if(p instanceof Parameter.Request){
                 newParams.put(key, new Parameter.Request(key, new 
String[] {"new"+p.getValue()}));
             }
         }
         parameters.appendAll(newParams);
     }
}

On 9/16/2017 2:23 PM, Alireza Fattahi wrote:
> we are using struts 2.3.xx after upgrade to struts 2.5.12 we found that the ParameterAware
is deprecated and we must use HttpParametersAware.
> 
> There is an action class which extends ParameterAware and change some parameters before
action (It remove input masks for example removes , from 123,456,789) :
> --------------------public class Sample extends ActionSupport implements
>          ModelDriven<SampleVO>,ParameterAware {
> 
> 
>      @Override
>      public void setParameters(Map<String, String[]> parameters) {
>          for (String[] values : parameters.values()) {
>              for (int i = 0; i < values.length; i++) {
>                  values[i] = Mask.removeMask(values[i]);
>              }
>          }
>      }
> 
> }
> ---------------------------
> 
> We tried to do this with new HttpParametersAware and some thing like:
> -------------------
> for (Entry<String, Parameter> entry : parameters.entrySet()) {
>               String key = entry.getKey();
>               Parameter newParam =  new Parameter.Request( key, entry.getValue().getValue().replaceAll(",",
""));
> 
> }
> ----------------
> 
> But I face the error
> HttpParameters are immutable, you cannot put value directly! Can we change parameters
like we used to do it in struts 2.3.x. how ?!
> 
> 
> ~Regards,
> ~~Alireza Fattahi
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Mime
View raw message