I bet most of you are using css classes in your vf components in order to select them using JQuery. I believe this the easiest workaround but not really that efficient especially if you have a number of vf components in your page and most of them should be using similar css classes. You are not able to use JQuery with the vf component's ID since it adds additional data to the ID you specified. The additional data denotes the component's position in the vf page structure. There is an easy way to refer to your vf components IDs without doing much code, however, just make sure that you don't have duplicate IDs or else this approach will fail. You may refer to your specific visualforce component by using this JQuery expression: $('[id$=YourVFComponentID]'). This will search all the IDs of the page components which contains the specified text after the id$.
Here's an example:
<apex:page>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(function()
{
$('[id$=itDate]').datepicker();
});
</script>
<apex:form >
<apex:pageblock>
<apex:pageBlockSection columns="2">
<apex:pageBlockSectionItem >
<apex:outputlabel value="Date:"/>
<apex:inputText id="itDate"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Header
Showing posts with label salesforce. Show all posts
Showing posts with label salesforce. Show all posts
Tuesday, October 25, 2011
Visualforce Component IDs in JQuery
Labels:
apex,
css,
javascript,
jquery,
salesforce,
sfdc,
vf,
vf page,
visualforce
Sunday, August 14, 2011
Visualforce Page Redirection
I needed a button in a standard page of a custom object to do some logic when pressed. Initially, I found out that this could be done through a Global Apex Class. So, I started developing using this approach but I had a hard time passing some parameters to the class from the page. I managed to find some workarounds to address the issue, however, it seemed that I was doing a lot just to make it work. With this, I decided to find another alternative to do the functionality. I realized that I could redirect to a Visualforce page using the button and add method in the controller to do the logic. This time, my problem is that the page redirection does not work after the method is executed in the constructor. After some researching on the cause of this, it turned out that the constructor does not know what to do with the pagereference object it got from the method. As a result, no page redirection happens. To address this issue, you need to call the method in the action parameter of the visualforce page instead of the constructor.
Here's an example:
<apex:page controller="SampleController" action="{!sampleLogicMethodWithRedirection}">
Here's an example:
<apex:page controller="SampleController" action="{!sampleLogicMethodWithRedirection}">
Labels:
apex,
salesforce,
sfdc,
vf,
vf page,
visualforce
Subscribe to:
Posts (Atom)