Controller Object binding not working from template

Bug #512503 reported by Thibaut
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
Status tracked in 1.0
1.0
Fix Released
Undecided
Unassigned
1.1
Fix Committed
Undecided
Unassigned

Bug Description

I'm trying to pass an custom object (not a primitive such as String, Date, etc...) as parameter.

public static void index(Test t) throws Exception {
 render(t);
        }

I can set the parameters and access the parameters just fine when
calling index?t.p1=test&t.p2=p2.... This works as expected :)
I can also call the action from another action or controller, and the redirect url is generated correctly, and all parameters can be accessed in the controller.

However, the automatic generation of links is not working from the template:

@{Application.index(t)} will interpret t in String context, and generate a wrong url. (I would like to set parameters later with @{Application.index(t.setSortBy("asc"))}, without having to specify all the parameters of the object seperatly in the template).

As an alternative, II could use actionBridge.Application.index().add(key,value) to generate the links. actionBridge.Application.index() will however return an instance of Router.ActionDefinition which only contains a 1to1 map instead of a manyto1 map, thus making it impossible to define multiple parameters with the same key.

For more information, please have a look at: http://groups.google.com/group/play-framework/browse_thread/thread/2b8476a392b1b2
Version affected 1.0.1

Revision history for this message
Thibaut (thibaut-blue) wrote :

Just tested it and it seems to work perfectly! Thanks!

Revision history for this message
Thibaut (thibaut-blue) wrote :

There is still a small bug left:

It works fine if I'm setting a single entity: (I'm always making a clone of the object in the loop with s.clone(), so I keep the original settings)

@{www.WebSearch.index(s.clone().setPage(0))}

However If i'm adding somthing to a collection (eg HashSet<String> collection)), e.g in a loop, play will not use my cloned instance!

@{www.WebSearch.index(s.clone().addHighlighted(key).setPage(0))}

At each iteration of the loop, s will contain all previous keys I added to the loop!

After each iteration I have to manually remove each key I added
        %{
         s = s.removeHighlighted(key);
        }%

The clone function is below.

public SearchSettings clone() {
  try {
   return (SearchSettings) super.clone();
  } catch (CloneNotSupportedException e) {
   return null;
  }
 }

Revision history for this message
Guillaume Bort (guillaume-bort) wrote : Re: [Bug 512503] Re: Controller Object binding not working from template

The problem is that variables are not locals even into a tag body. Can
you post the list code?

On 1 mars 2010, at 18:15, Thibaut <email address hidden> wrote:

> There is still a small bug left:
>
> It works fine if I'm setting a single entity: (I'm always making a
> clone
> of the object in the loop with s.clone(), so I keep the original
> settings)
>
> @{www.WebSearch.index(s.clone().setPage(0))}
>
> However If i'm adding somthing to a collection (eg HashSet<String>
> collection)), e.g in a loop, play will not use my cloned instance!
>
> @{www.WebSearch.index(s.clone().addHighlighted(key).setPage(0))}
>
> At each iteration of the loop, s will contain all previous keys I
> added
> to the loop!
>
> After each iteration I have to manually remove each key I added
> %{
> s = s.removeHighlighted(key);
> }%
>
>
> The clone function is below.
>
> public SearchSettings clone() {
> try {
> return (SearchSettings) super.clone();
> } catch (CloneNotSupportedException e) {
> return null;
> }
> }
>
> --
> Controller Object binding not working from template
> https://bugs.launchpad.net/bugs/512503
> You received this bug notification because you are subscribed to play
> framework.

Revision history for this message
Thibaut (thibaut-blue) wrote :

That's why I'm using the clone function to make a clone?

Here is the list code:

I have to call

%{
s = s.removeHighlighted(key);
}%

to remove the keys again.

<div id="reduced_tagcloud">
      #{list items:normordered, as:'key'}
       #{if !s.isHighlighted(key)}
        <span class="tag${r.normout.getCount(key)+1}"><span class="type${r.normout.getCount(key)+1}"><a href="@{www.WebSearch.index(s.clone().addHighlighted(key).setPage(0))}">${key}<!--${r.freqout.getCount(key)}--></a></span></span>
        %{
         s = s.removeHighlighted(key);
        }%

       #{/if}
       #{else}
        <span class="tag${r.normout.getCount(key)+1} tag${r.normout.getCount(key)+1}selected"><span class="type${r.normout.getCount(key)+1}"><a href="@{www.WebSearch.index(s.clone().removeHighlighted(key).setPage(0))}">${key}<!--${r.freqout.getCount(key)}--></a></span></span>
       #{/else}
      #{/list}
</div>

 public SearchSettings addHighlighted(String tag) {
  if (sqh == null) {
   sqh = new HashSet<String>();
  }
  sqh.add(tag);
  return this;
 }

 public SearchSettings removeHighlighted(String tag) {
  if (sqh != null) {
   sqh.remove(tag);
  }
  return this;
 }

Would it be possible to create a function similar to @ that automatically creates clones of each variable passed, before evaluating .setPage(0) etc..?

Revision history for this message
Thibaut (thibaut-blue) wrote :

This works:

s.clone().setCat will not overwrite the category field for the next compare. That's why I'm suprised that the above doesn't work.
This is no loop however.

    <li #{if s.isCat(search.katta.SearchControllerSettings.CATEGORY.all)}class="active"#{/if}><a href="@{www.WebSearch.index(s.clone().setCat(search.katta.SearchControllerSettings.CATEGORY.all))}">Alle</a></li>
    <li #{if s.isCat(search.katta.SearchControllerSettings.CATEGORY.business)}class="active"#{/if}><a href="@{www.WebSearch.index(s.clone().setCat(search.katta.SearchControllerSettings.CATEGORY.business))}">Wirtschaft</a></li>

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.