You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Pillar <so...@hotmail.com> on 2012/11/29 15:48:48 UTC

[5.3.6] Loop component giving coercion error

I've been reading other posts but nothing seems to work for me.

Here's my page:

public class ServiceActivation {		
	private List<User> users;
	
	@Property 
	private UserService userservice;
	
	@Property
	private User u;
	
	@Inject
	private UserDao userDao; 
	
	public List<User> getUsers() {
		if (users == null) {
			users = userDao.findAll();			
		} 
		return users;
	}
	
	public void onSuccess(UserService userservice) {
		System.out.println(userservice);
	}
}

A user has a List<UserService> that gets loaded at userDao.findAll() along
with the User. I have a form that I want to loop through all the users and
give them an option to 'activate' a service, contained in the userservice
object. I'm just posting the nested loops because I can't format the whole
thing nicely, but it's within a form and there is a sbumit button for each
nested iteration:

<t:loop source = "users" value = "u" formState = "none">
    <t:loop source = "${u.userServices}" value = "userservice" formState =
"none">
    </t:loop>
</t:loop>

Inside both loops I try to access properties of u and userservice. 
					
I get this error message:
Render queue error in BeginRender[service/Activation:loop_0]: Failure
writing parameter 'value' of component service/Activation:loop_0: Could not
find a coercion from type java.lang.String to type
org.synchronica.example.entities.userservice.UserService.

I've read that formState = "none" does something in this case but I don't
understand it. There's also the ValueEncoder I don't understand, but I don't
want to make a database call for each item in the list (if that's the way to
implement it).



--
View this message in context: http://tapestry.1045711.n5.nabble.com/5-3-6-Loop-component-giving-coercion-error-tp5718395.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [5.3.6] Loop component giving coercion error

Posted by Pillar <so...@hotmail.com>.
I need sleep. Thanks!



--
View this message in context: http://tapestry.1045711.n5.nabble.com/5-3-6-Loop-component-giving-coercion-error-tp5718395p5718403.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [5.3.6] Loop component giving coercion error

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 29 Nov 2012 15:40:32 -0200, Pillar <so...@hotmail.com> wrote:

> Hey

Hi!

> Can you tell me why this isn't working?
>
> <t:loop source = "services" values = "service" formState = "none">
>     ${service.name}
> </t:loop			

The parameter name is wrong: it's "value", not "values".

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [5.3.6] Loop component giving coercion error

Posted by Pillar <so...@hotmail.com>.
Hey

So it worked as you said, but now I have another problem.

Can you tell me why this isn't working?

<t:loop source = "services" values = "service" formState = "none">
    ${service.name}
</t:loop			
		
It gives me the following error:

Render queue error in Expansion[PropBinding[expansion
service/Activation(service.name)]]: Property 'service' (within property
expression 'service.name', of
org.synchronica.example.pages.service.ServiceActivation@29b65ab8) is null.

I have properties for both 'services' and 'service'. A service has a name
attribute with a getter.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/5-3-6-Loop-component-giving-coercion-error-tp5718395p5718400.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [5.3.6] Loop component giving coercion error

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 29 Nov 2012 12:48:48 -0200, Pillar <so...@hotmail.com> wrote:

> I've been reading other posts but nothing seems to work for me.

Hi!

>     <t:loop source = "${u.userServices}" value = "userservice" formState

Never, never ever use ${} expansions when passing parameters. It causes  
the value to be coerced to a String, and that's exactly what's causing  
your problem. Just use source="u.userServices".

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [5.3.6] Loop component giving coercion error

Posted by Pillar <so...@hotmail.com>.
Yes, that did it. God damn it's been bugging me for two hours trying to find
solutions. I think I had switched it because something had previously caused
an exception and I thought I needed the expansion. Can you explain the use
of formState and encoder in the form component? I don't quite get the docs.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/5-3-6-Loop-component-giving-coercion-error-tp5718395p5718397.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [5.3.6] Loop component giving coercion error

Posted by Mauricio Aldazosa <ma...@gmail.com>.
On Thu, Nov 29, 2012 at 8:48 AM, Pillar <so...@hotmail.com> wrote:

> I've been reading other posts but nothing seems to work for me.
>
>
> <t:loop source = "users" value = "u" formState = "none">
>     <t:loop source = "${u.userServices}" value = "userservice" formState =
> "none">
>     </t:loop>
> </t:loop>
>
> Inside both loops I try to access properties of u and userservice.
>
>
>From what I can tell, the source of the inner loop shouldn't be using an
expansion. Write it as:

<t:loop source = "u.userServices" value = "userservice" formState ="none">

Take a look at: http://tapestry.apache.org/component-templates.html, there
is a warning there in the "Expansions" section that covers the problem you
are seeing.