You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Martin Grigorov (JIRA)" <ji...@apache.org> on 2016/02/05 21:23:40 UTC

[jira] [Commented] (WICKET-6069) OnChangeAjaxBehavior does not work if the url contains a request parameter with same name as wicket id

    [ https://issues.apache.org/jira/browse/WICKET-6069?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15134908#comment-15134908 ] 

Martin Grigorov commented on WICKET-6069:
-----------------------------------------

The problem is that by adding a request parameter in the query string there are two values for this request parameter at the server side and if the wrong value is used then the ChoiceRenderer cannot map it to a possible choice, thus `null`.


Devs, what do you think about this change:
{code}
diff --git i/wicket-request/src/main/java/org/apache/wicket/request/Request.java w/wicket-request/src/main/java/org/apache/wicket/request/Request.java
index 95d24cc..0ecec9d 100644
--- i/wicket-request/src/main/java/org/apache/wicket/request/Request.java
+++ w/wicket-request/src/main/java/org/apache/wicket/request/Request.java
@@ -133,7 +133,7 @@ public abstract class Request
         */
        public IRequestParameters getRequestParameters()
        {
-               return new CombinedRequestParametersAdapter(getQueryParameters(), getPostParameters());
+               return new CombinedRequestParametersAdapter(getPostParameters(), getQueryParameters());
        }
{code}

This gives POST parameters higher priority than GET parameters at org.apache.wicket.markup.html.form.AbstractSingleSelectChoice#convertValue(). Here Wicket uses just the first value if there are several.

The GET request parameter is in the Ajax url because of 
{code}
PageParameters parameters = getRecreateMountedPagesAfterExpiry() ? new PageParameters(
				handler.getPage().getPageParameters()).mergeWith(handler.getPageParameters())
				: handler.getPageParameters();
{code}
in AbstractBookmarkableMapper, line 445, Wicket 6.21.0. I.e. for page recreation after expiry.

> OnChangeAjaxBehavior does not work if the url contains a request parameter with same name as wicket id
> ------------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-6069
>                 URL: https://issues.apache.org/jira/browse/WICKET-6069
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 6.21.0
>            Reporter: Robin Shine
>            Assignee: Martin Grigorov
>            Priority: Minor
>         Attachments: myproject.zip
>
>
> To demonstrate the issue, create below simple page:
> {code:title="HomePage.html"}
> <wicket:extend>
>   <select wicket:id="choice"></select>
> </wicket:extend>
> {code}
> {code:title="HomePage.java"}
> public class HomePage extends WebPage {
> 	private String choice = "a";
> 	
> 	@Override
> 	protected void onInitialize() {
> 		super.onInitialize();
> 		List<String> choices = new ArrayList<String>();
> 		choices.add("a");
> 		choices.add("b");
> 		add(new DropDownChoice<String>("choice", new IModel<String>() {
> 			@Override
> 			public void detach() {
> 			}
> 			@Override
> 			public String getObject() {
> 				return choice;
> 			}
> 			@Override
> 			public void setObject(String object) {
> 				choice = object;
> 			}
> 			
> 		}, choices).add(new OnChangeAjaxBehavior() {
> 			@Override
> 			protected void onUpdate(AjaxRequestTarget target) {
> 				System.out.println(choice);
> 			}
> 			
> 		}));		
> 	}
> }
> {code}
> This simple page prints out choosed value via OnChangeAjaxBehavior, it works fine if you access the page via http://localhost:8080. However it always prints "null" if you access the page with a request parameter the same name as the wicket id, for instance: http://localhost:8080/?choice=somevalue
> It works again if you use different value for wicket id of the choice component and request parameter.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)