You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Burton Rhodes <bu...@gmail.com> on 2014/11/28 16:29:16 UTC

Struts2 Json Plugin - overwrites parameter values in url string?

I have a simple json action that searches for a Contact in the system.  I
am using a GET request with the following url:

"ContactSearchJson.action?searchCriteria.searchStringContact=Doe&searchCriteria.categories=agent

You'll notice I'm trying to set two variable in the object searchCriteria.
However, when the variables are set in the action only one variable is set,
but not both.  If I remove either "searchStringContact" or "categories",
the remaining value will set fine.

My assumption is it is setting the "searchCriteria.searchStringContact"
value, then when it comes across the "searchCriteria.categories" value it
overwrites the entire object so the only value that is set is "categories".

My questions is, if this a bugor a feature in the json-plugin?  Or am I
doing something wrong here?

Thanks,
Burton

Re: Struts2 Json Plugin - overwrites parameter values in url string?

Posted by Burton Rhodes <bu...@gmail.com>.
Jose - That's it.  Thank you.  I had omitted it because I didn't want it
returned in the json result.  I guess in the struts.xml instead.

Many thanks!!

On Sat, Nov 29, 2014 at 9:33 PM, JOSE L MARTINEZ-AVIAL <jl...@gmail.com>
wrote:

> I think you need to add a getSearchCriteria in ContactSearchJsonAction.
>
> 2014-11-29 17:51 GMT-05:00 Burton Rhodes <bu...@gmail.com>:
>
> > Also, here is a partial version of the SearchCriteria.java object...
> >
> > package com.afs.service.search;
> > public class SearchCriteria implements Serializable {
> >
> >    private int userId = -1;
> >    private int teamId = -1;
> >    private String searchStringContact;
> >    private String categories = null;
> >
> >    public SearchCriteria() { }
> >
> >     public String[] splitCategories() {
> >         return MyStringUtil.splitBy(categories, ",");
> >     }
> >
> >     public int getUserId() {
> >       return userId;
> >    }
> >
> >    public void setUserId(int userId) {
> >       this.userId = userId;
> >    }
> >
> >    public int getTeamId() {
> >       return teamId;
> >    }
> >
> >    public void setTeamId(int teamId) {
> >       this.teamId = teamId;
> >    }
> >
> >    public String getSearchStringContact() {
> >       return searchStringContact;
> >    }
> >
> >    public void setSearchStringContact(String searchStringContact) {
> >       this.searchStringContact = searchStringContact;
> >    }
> >
> >    public String getCategories() {
> >       return categories;
> >    }
> >
> >    public void setCategories(String categories) {
> >       this.categories = categories;
> >    }
> >
> > }
> >
> >
> > On Fri, Nov 28, 2014 at 10:04 AM, Dave Newton <da...@gmail.com>
> > wrote:
> >
> > > What does the action in question look like, specifically, stuff
> > > related to the `searchCriteria` object?
> > >
> > > On Fri, Nov 28, 2014 at 10:29 AM, Burton Rhodes <
> burtonrhodes@gmail.com>
> > > wrote:
> > > > I have a simple json action that searches for a Contact in the
> > system.  I
> > > > am using a GET request with the following url:
> > > >
> > > >
> > >
> >
> "ContactSearchJson.action?searchCriteria.searchStringContact=Doe&searchCriteria.categories=agent
> > > >
> > > > You'll notice I'm trying to set two variable in the object
> > > searchCriteria.
> > > > However, when the variables are set in the action only one variable
> is
> > > set,
> > > > but not both.  If I remove either "searchStringContact" or
> > "categories",
> > > > the remaining value will set fine.
> > > >
> > > > My assumption is it is setting the
> "searchCriteria.searchStringContact"
> > > > value, then when it comes across the "searchCriteria.categories"
> value
> > it
> > > > overwrites the entire object so the only value that is set is
> > > "categories".
> > > >
> > > > My questions is, if this a bugor a feature in the json-plugin?  Or
> am I
> > > > doing something wrong here?
> > > >
> > > > Thanks,
> > > > Burton
> > >
> > >
> > >
> > > --
> > > e: davelnewton@gmail.com
> > > m: 908-380-8699
> > > s: davelnewton_skype
> > > t: @dave_newton
> > > b: Bucky Bits
> > > g: davelnewton
> > > so: Dave Newton
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> >
>

Re: Struts2 Json Plugin - overwrites parameter values in url string?

Posted by JOSE L MARTINEZ-AVIAL <jl...@gmail.com>.
I think you need to add a getSearchCriteria in ContactSearchJsonAction.

2014-11-29 17:51 GMT-05:00 Burton Rhodes <bu...@gmail.com>:

> Also, here is a partial version of the SearchCriteria.java object...
>
> package com.afs.service.search;
> public class SearchCriteria implements Serializable {
>
>    private int userId = -1;
>    private int teamId = -1;
>    private String searchStringContact;
>    private String categories = null;
>
>    public SearchCriteria() { }
>
>     public String[] splitCategories() {
>         return MyStringUtil.splitBy(categories, ",");
>     }
>
>     public int getUserId() {
>       return userId;
>    }
>
>    public void setUserId(int userId) {
>       this.userId = userId;
>    }
>
>    public int getTeamId() {
>       return teamId;
>    }
>
>    public void setTeamId(int teamId) {
>       this.teamId = teamId;
>    }
>
>    public String getSearchStringContact() {
>       return searchStringContact;
>    }
>
>    public void setSearchStringContact(String searchStringContact) {
>       this.searchStringContact = searchStringContact;
>    }
>
>    public String getCategories() {
>       return categories;
>    }
>
>    public void setCategories(String categories) {
>       this.categories = categories;
>    }
>
> }
>
>
> On Fri, Nov 28, 2014 at 10:04 AM, Dave Newton <da...@gmail.com>
> wrote:
>
> > What does the action in question look like, specifically, stuff
> > related to the `searchCriteria` object?
> >
> > On Fri, Nov 28, 2014 at 10:29 AM, Burton Rhodes <bu...@gmail.com>
> > wrote:
> > > I have a simple json action that searches for a Contact in the
> system.  I
> > > am using a GET request with the following url:
> > >
> > >
> >
> "ContactSearchJson.action?searchCriteria.searchStringContact=Doe&searchCriteria.categories=agent
> > >
> > > You'll notice I'm trying to set two variable in the object
> > searchCriteria.
> > > However, when the variables are set in the action only one variable is
> > set,
> > > but not both.  If I remove either "searchStringContact" or
> "categories",
> > > the remaining value will set fine.
> > >
> > > My assumption is it is setting the "searchCriteria.searchStringContact"
> > > value, then when it comes across the "searchCriteria.categories" value
> it
> > > overwrites the entire object so the only value that is set is
> > "categories".
> > >
> > > My questions is, if this a bugor a feature in the json-plugin?  Or am I
> > > doing something wrong here?
> > >
> > > Thanks,
> > > Burton
> >
> >
> >
> > --
> > e: davelnewton@gmail.com
> > m: 908-380-8699
> > s: davelnewton_skype
> > t: @dave_newton
> > b: Bucky Bits
> > g: davelnewton
> > so: Dave Newton
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

Re: Struts2 Json Plugin - overwrites parameter values in url string?

Posted by Burton Rhodes <bu...@gmail.com>.
Also, here is a partial version of the SearchCriteria.java object...

package com.afs.service.search;
public class SearchCriteria implements Serializable {

   private int userId = -1;
   private int teamId = -1;
   private String searchStringContact;
   private String categories = null;

   public SearchCriteria() { }

    public String[] splitCategories() {
        return MyStringUtil.splitBy(categories, ",");
    }

    public int getUserId() {
      return userId;
   }

   public void setUserId(int userId) {
      this.userId = userId;
   }

   public int getTeamId() {
      return teamId;
   }

   public void setTeamId(int teamId) {
      this.teamId = teamId;
   }

   public String getSearchStringContact() {
      return searchStringContact;
   }

   public void setSearchStringContact(String searchStringContact) {
      this.searchStringContact = searchStringContact;
   }

   public String getCategories() {
      return categories;
   }

   public void setCategories(String categories) {
      this.categories = categories;
   }

}


On Fri, Nov 28, 2014 at 10:04 AM, Dave Newton <da...@gmail.com> wrote:

> What does the action in question look like, specifically, stuff
> related to the `searchCriteria` object?
>
> On Fri, Nov 28, 2014 at 10:29 AM, Burton Rhodes <bu...@gmail.com>
> wrote:
> > I have a simple json action that searches for a Contact in the system.  I
> > am using a GET request with the following url:
> >
> >
> "ContactSearchJson.action?searchCriteria.searchStringContact=Doe&searchCriteria.categories=agent
> >
> > You'll notice I'm trying to set two variable in the object
> searchCriteria.
> > However, when the variables are set in the action only one variable is
> set,
> > but not both.  If I remove either "searchStringContact" or "categories",
> > the remaining value will set fine.
> >
> > My assumption is it is setting the "searchCriteria.searchStringContact"
> > value, then when it comes across the "searchCriteria.categories" value it
> > overwrites the entire object so the only value that is set is
> "categories".
> >
> > My questions is, if this a bugor a feature in the json-plugin?  Or am I
> > doing something wrong here?
> >
> > Thanks,
> > Burton
>
>
>
> --
> e: davelnewton@gmail.com
> m: 908-380-8699
> s: davelnewton_skype
> t: @dave_newton
> b: Bucky Bits
> g: davelnewton
> so: Dave Newton
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts2 Json Plugin - overwrites parameter values in url string?

Posted by Burton Rhodes <bu...@gmail.com>.
Apologies for the delay - Thanksgiving got in the way....

My action is below.  Struts and Json plugin version is 2.3.16.3.

The SearchCriteria.java object is a standard bean object with getters and
setters (no real functionality).  My action class is below which is
processing the url query: "ContactSearchJson.action?searchCriteria.
searchStringContact=Doe&searchCriteria.categories=agent".  I also included
my struts.xml applicable lines.

=========== ContactSerachJsonAction.java =========================

package com.afs.web.action.json;
public class ContactSearchJsonAction extends BaseAction {


    private static final int DEFAULT_PAGESIZE = 20;

    private transient SearchManagerService searchManagerService;

    private SearchCriteria searchCriteria;

    private Map<Integer, String> contactData;
    private Integer count;

    public String execute() throws Exception {

        searchCriteria.setUserId(myAppSession.getUser().getAppUserId());
        searchCriteria.setTeamId(myAppSession.getUser().getTeam().getTeamId());
        searchManagerService.setSearchCriteria(searchCriteria);
        searchManagerService.setTemplate(SearchManagerService.TEMPLATE_CUSTOM);

        List<Contact> contacts =
searchManagerService.performPagedSearch(Contact.class, 0,
DEFAULT_PAGESIZE);
        contactData = new HashMap<Integer, String>();
        for (Contact contact : contacts) {
            String displayName = "";
            if (StringUtils.isNotBlank(contact.getCompany())) {
                displayName = "(" + displayName + contact.getCompany() + ") ";
            }
            displayName = displayName +
contact.getContactHelper().getName().getFirstLastAllString(true);
            contactData.put(contact.getContactId(), displayName);
        }
        count = searchManagerService.getPage().getTotalNumberOfElements();

        return SUCCESS;
    }

    public void setSearchManagerService(SearchManagerService
searchManagerService) {
        this.searchManagerService = searchManagerService;
    }

    public void setSearchCriteria(SearchCriteria searchCriteria) {
        this.searchCriteria = searchCriteria;
    }

    public Map<Integer, String> getContactData() {
        return contactData;
    }

    public Integer getCount() {
        return count;
    }
}


========= struts.xml ============

<package name="jsonSecure" namespace="/app/json" extends="json-default">

       <!-- Define results: custom json result (dynamically changes
result type) -->
       <result-types>
           <result-type name="myJsonResult"
class="com.afs.web.interceptor.JsonDynamicContentTypeResult"/>
       </result-types>

       <!-- Define custom interceptors and interceptor stacks -->
       <interceptors>

           <!-- Session Interceptor: makes sure user is logged in -->
           <interceptor name="sessionInterceptorJson"
class="com.afs.web.interceptor.SessionInterceptorJson" />

           <!-- Replace the existing "exception" interceptor -->
           <interceptor name="exceptionInterceptor"
class="com.afs.web.interceptor.ExceptionInterceptorJson" />

           <!-- Default stack -->
           <interceptor-stack name="myDefaultStackJson">
               <interceptor-ref name="sessionInterceptorJson" />
               <interceptor-ref name="exceptionInterceptor">
                   <param name="logEnabled">true</param>
                   <param name="logLevel">ERROR</param>
               </interceptor-ref>
               <interceptor-ref name="servletConfig"/>
               <interceptor-ref name="prepare"/>
               <interceptor-ref name="checkbox"/>
               <interceptor-ref name="multiselect"/>
               <interceptor-ref name="actionMappingParams"/>
               <interceptor-ref name="params">
                   <param
name="excludeParams">^class\..*,^dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,^parameters\..*,^action:.*,^method:.*</param>
               </interceptor-ref>
               <interceptor-ref name="conversionError"/>
               <interceptor-ref name="deprecation"/>
               <interceptor-ref name="validation">
                   <param name="excludeMethods">input,back,cancel</param>
               </interceptor-ref>
               <interceptor-ref name="jsonValidation"/>
               <interceptor-ref name="workflow"/>
           </interceptor-stack>

           <!-- Preparable default stack -->
           <interceptor-stack name="myPreparableStackJson">
               <interceptor-ref name="sessionInterceptorJson" />
               <interceptor-ref name="exceptionInterceptor">
                   <param name="logEnabled">true</param>
                   <param name="logLevel">ERROR</param>
               </interceptor-ref>
               <interceptor-ref name="params"/>
               <interceptor-ref name="servletConfig"/>
               <interceptor-ref name="prepare"/>
               <interceptor-ref name="checkbox"/>
               <interceptor-ref name="multiselect"/>
               <interceptor-ref name="actionMappingParams"/>
               <interceptor-ref name="params">
                   <param
name="excludeParams">^class\..*,^dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,^parameters\..*,^action:.*,^method:.*</param>
               </interceptor-ref>
               <interceptor-ref name="conversionError"/>
               <interceptor-ref name="deprecation"/>
               <interceptor-ref name="validation">
                   <param name="excludeMethods">input,back,cancel</param>
               </interceptor-ref>
               <interceptor-ref name="jsonValidation"/>
               <interceptor-ref name="workflow"/>
           </interceptor-stack>

       </interceptors>

       <!--  Set default interceptor -->
       <default-interceptor-ref name="myDefaultStackJson" />

       <!-- define global results to include action messages -->
       <global-results>
           <result name="login" type="myJsonResult">
               <param name="ignoreHierarchy">false</param>
               <param
name="includeProperties">actionErrors.*,actionMessages.*,fieldErrors.*</param>
           </result>
           <result name="input" type="myJsonResult">
               <param name="ignoreHierarchy">false</param>
               <param
name="includeProperties">actionErrors.*,actionMessages.*,fieldErrors.*</param>
           </result>
           <result name="error" type="myJsonResult">
               <param name="ignoreHierarchy">false</param>
               <param
name="includeProperties">actionErrors.*,actionMessages.*,fieldErrors.*</param>
           </result>
       </global-results>
       <global-exception-mappings>
           <exception-mapping exception="java.lang.Exception" result="error" />
       </global-exception-mappings>

       <action name="ContactSearchJson"
class="com.afs.web.action.json.ContactSearchJsonAction">
           <result type="myJsonResult" />
       </action>

</package>




On Fri, Nov 28, 2014 at 10:04 AM, Dave Newton <da...@gmail.com> wrote:

> What does the action in question look like, specifically, stuff
> related to the `searchCriteria` object?
>
> On Fri, Nov 28, 2014 at 10:29 AM, Burton Rhodes <bu...@gmail.com>
> wrote:
> > I have a simple json action that searches for a Contact in the system.  I
> > am using a GET request with the following url:
> >
> >
> "ContactSearchJson.action?searchCriteria.searchStringContact=Doe&searchCriteria.categories=agent
> >
> > You'll notice I'm trying to set two variable in the object
> searchCriteria.
> > However, when the variables are set in the action only one variable is
> set,
> > but not both.  If I remove either "searchStringContact" or "categories",
> > the remaining value will set fine.
> >
> > My assumption is it is setting the "searchCriteria.searchStringContact"
> > value, then when it comes across the "searchCriteria.categories" value it
> > overwrites the entire object so the only value that is set is
> "categories".
> >
> > My questions is, if this a bugor a feature in the json-plugin?  Or am I
> > doing something wrong here?
> >
> > Thanks,
> > Burton
>
>
>
> --
> e: davelnewton@gmail.com
> m: 908-380-8699
> s: davelnewton_skype
> t: @dave_newton
> b: Bucky Bits
> g: davelnewton
> so: Dave Newton
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts2 Json Plugin - overwrites parameter values in url string?

Posted by Dave Newton <da...@gmail.com>.
What does the action in question look like, specifically, stuff
related to the `searchCriteria` object?

On Fri, Nov 28, 2014 at 10:29 AM, Burton Rhodes <bu...@gmail.com> wrote:
> I have a simple json action that searches for a Contact in the system.  I
> am using a GET request with the following url:
>
> "ContactSearchJson.action?searchCriteria.searchStringContact=Doe&searchCriteria.categories=agent
>
> You'll notice I'm trying to set two variable in the object searchCriteria.
> However, when the variables are set in the action only one variable is set,
> but not both.  If I remove either "searchStringContact" or "categories",
> the remaining value will set fine.
>
> My assumption is it is setting the "searchCriteria.searchStringContact"
> value, then when it comes across the "searchCriteria.categories" value it
> overwrites the entire object so the only value that is set is "categories".
>
> My questions is, if this a bugor a feature in the json-plugin?  Or am I
> doing something wrong here?
>
> Thanks,
> Burton



-- 
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton
b: Bucky Bits
g: davelnewton
so: Dave Newton

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


Re: Struts2 Json Plugin - overwrites parameter values in urlstring?

Posted by Felipe Lorenz <fe...@idealogic.com.br>.
 

Hi Burton, 

It should not be happining. 

Which version of struts
and json plugin are you using? 

regards, 
---

FELIPE LORENZ
Gerente de
Projetos
Idealogic Software
Fone: (51) 3715 5523 - (51) 3715
5548
www.idealogic.com.br

On 28/11/2014 13:29, Burton Rhodes wrote: 

>
I have a simple json action that searches for a Contact in the system.
I
> am using a GET request with the following url:
> 
>
"ContactSearchJson.action?searchCriteria.searchStringContact=Doe&searchCriteria.categories=agent
>

> You'll notice I'm trying to set two variable in the object
searchCriteria.
> However, when the variables are set in the action only
one variable is set,
> but not both. If I remove either
"searchStringContact" or "categories",
> the remaining value will set
fine.
> 
> My assumption is it is setting the
"searchCriteria.searchStringContact"
> value, then when it comes across
the "searchCriteria.categories" value it
> overwrites the entire object
so the only value that is set is "categories".
> 
> My questions is, if
this a bugor a feature in the json-plugin? Or am I
> doing something
wrong here?
> 
> Thanks,
> Burton