function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jyoti TrailheadJyoti Trailhead 

Can I use VF component's controller's parameters in VF page - component is called in VF page

I have a VF page in which VF component is called using <C: VF Component/>

I need to show an error message based on entitlement of logged in user - entitlement functionality is defined in Component controller and isused in Component. Can I call those parameters set for entitlement in Component Controller in my VF page and based on that show error message else show my page content.

Please suggest- this is urgent.

Thanks
Jyoti
 
Dileep KumarDileep Kumar

Hi Jyoti Verma,

Yes,you can do this.

Thanks,

Dileep Kumar

Jyoti TrailheadJyoti Trailhead
Hi Dileep

Please guide me how to use this 

e.g. 
in Component Controller:
CONT{
public boolean abc{get; set;}
public boolean efg{get; set;}

constructor (){
abc = true;
efg = true;
}
}

in VF Component :
COMP{
!abc and !efg are used
}

in VF page:
{
style="display:{IF((CONT.abc || CONT.efg), 'block', 'none')}";
}

here in place of none I need to show an error message - how to do that as well.

Regards
Jyoti
 
Dileep KumarDileep Kumar

Hi Jyoti,

you can not show error message in this way,

You need to do validation inside method and you can show the error message by using <apex:pageMessages /> on visualforce page.

I mean you need to write condition for error inside controller method.

Please try this approach.

If you will face any problem then please paste your full vf cde and apex class.

Thanks,

Jyoti TrailheadJyoti Trailhead
okay - then how can I call validation/ parameters set in VF Component's Controller in my VF page controller as
for CONT.abc  - it throws an error.
Dileep KumarDileep Kumar

Hi Jyoti,

Please try in this way.

Public class A{
    public boolean abc{get;set;}
    public A(){
        abc =false;

    }
    public pageReference B(){
        if(code for true condition ){
        abc =true;
        }
        else{
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'You can not leave all fields blank.'));//Here you can write your error message
             return null; 
        }
    
    }
}
Code for Page:
<apex:pageMessages />

please use this tag inside form tag or inside div tag where you want to show error message in your vf page.

Thanks,

Dileep

Jyoti TrailheadJyoti Trailhead
Hi Dileep

Thanks for your prompt support - you have provided logic containing a VF page and show pagemessage based on values defined based on Condtions in it's controller.

I my case I need to check this condition from the logic already defined in some other Apex class and not VF page controller. How can i do that. How can I use varibales defined in one class into another Apex class.

Please suggest.

Thanks
Jyoti