You need to sign in to do that
Don't have an account?
Problem with a custom Component
Hello
This is what I am trying to do. From a page conatining an Account ID in the URL (https://c.na6.visual.force.com/apex/Test20100123?id=0018000000dsRyo)
I want to pass the ID to a component, who then will pass it to a class that queries contacts linked to that ID.
I created these elements:
A page:
<apex:page >
<c:MyComponent componentValue= ':ApexPages.currentPage().getParameters().get('id')' />
</apex:page>
My page uses a Component, called MyComponent
<apex:component controller="myComponentController">
<apex:attribute name="componentValue" description="Attribute on the component."
type="Id" required="required" assignTo="{!controllerValue}"/>
<apex:pageBlock title="My Custom Component">
<p>
<code>componentValue</code> is "{!componentValue}"
<br/>
<code>controllerValue</code> is "{!controllerValueContact.name}"
</p>
</apex:pageBlock>
</apex:component>
This component uses a custom controller called myComponentController
public class myComponentController {
public Id controllerValue { get; set; }
public Contact controllerValueContact;
public List<Contact> ListContact;
public myComponentController() {
}
public Contact getControllerValueContact() {
ListContact = [select id, name from Contact where AccountId = :controllerValue];
controllerValueContact = ListContact.get(0);
return controllerValueContact;
}
}
When I run my page I get this error:
Error: Attribute name "id" associated with an element type "apex:componentReference" must be followed by the ' = ' character. at line 2
Anyone has an idea what am I doing wrong?
Thanks
Giorgio
Just offhand, I think the problem might be with this line and the parsing of the single quotes:
<c:MyComponent componentValue= ':ApexPages.currentPage().getParameters().get('id')' />
It thinks you're generating:
<c:MyComponent componentValue= ':ApexPages.currentPage().getParameters().get(' id and at this point it's expecting the "=" sign because now you're assigning the Id attribute.
Perhaps what you want is escaped single quotes so they aren't ending your string literal
<c:MyComponent componentValue= ':ApexPages.currentPage().getParameters().get(\'id\')' />
Don't you hate trivial stuff like this... aren't computers supposed to know what we want by now! :-)
Best, Steve.