I’m having a problem with my Seam code and I can’t seem to figure out what I’m doing wrong. It’s doing my head in 🙂 Here’s an excerpt of the stack trace:
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field com.oobjects.sso.manager.home.PresenceHome.customerId to java.lang.String
I’m trying to get a parameter set on my URL passed into one of my beans. To do this, I’ve got the following set up in my pages.xml:
<page view-id='/customer/presences.xhtml'> <begin-conversation flush-mode='MANUAL' join='true' /> <param name='customerId' value='#{presenceHome.customerId}' /> <raise-event type='PresenceHome.init' /> <navigation> <rule if-outcome='persisted'> <end-conversation /> <redirect view-id='/customer/presences.xhtml' /> </rule> </navigation> </page>
My bean starts like this:
@Name('presenceHome') @Scope(ScopeType.CONVERSATION) public class PresenceHome extends EntityHome<Presence> implements Serializable { @In private CustomerDao customerDao; @In(required = false) private Long presenceId; @In(required = false) private Long customerId; private Customer customer; // Getters, setters and other methods follow. They return the correct types defined above }
Finally the link I use to link one one page to the next looks like this:
<s:link styleClass='#{selected == 'presences' ? 'selected' : ''}' view='/customer/presences.xhtml' title='Presences' propagation='none'> <f:param name='customerId' value='#{customerId}' /> Presences </s:link>
All this seems to work fine. When I hover over the link above in my page, I get a URL ending in something like ‘?customerId=123’. So the parameter is being passed over and it’s something that can be easily converted into a Long type. But for some reason, it’s not. I’ve done similar things to this before in other projects and it’s worked then. I just can’t see what it isn’t working now.
If I remove the element from my page declaration, I get through to the page fine.
So, does anyone have any thoughts?
You want to add a converter to your pages.xml file. Like this:
See the seampay example provided with seam for more details.