I had used c:if, c:when JSTL tags in jsp. But I don't know if anything similar is available for visual force pages. just for example I am providing sample code for jsp. --
<h1>A Demo conditional section code</h1>
<c:choose>
<c:when test="${param.colorField == 'red'}">
<table border="0" width="150" height="50" bgcolor="#ff0000">
<tr><td>It is red</td></tr>
</table>
</c:when>
<c:when test="${param.colorField == 'blue'}">
<table border="0" width="150" height="50" bgcolor="#0000ff">
<tr><td>It is blue</td></tr>
</table>
</c:when>
<c:when test="${param.colorField == 'green'}">
<table border="0" width="150" height="50" bgcolor="#00ff00">
<tr><td>Green table</td></tr>
</table>
</c:when>
<c:otherwise>
<table border="0" width="150" height="50" bgcolor="#000000">
<tr><td>No colour changed</td></tr>
</table>
</c:otherwise>
</c:choose>
<br/>
and other codes....
I am missing this kind of page block preparation in vf pages.
What I have found that we can use outputpanel (<apex:outputpanel>) for any block and use the rendered attribute to handle the condition for loading it.
<h1>A Demo conditional section code</h1>
<apex:outputpanel rendered="{!param.colorField == 'red'}">
<table border="0" width="150" height="50" bgcolor="#ff0000">
<tr><td>It is red</td></tr>
</table>
</apex:outputpanel>
<apex:outputpanel rendered="{!param.colorField == 'blue'}">
<table border="0" width="150" height="50" bgcolor="#0000ff">
<tr><td>It is blue</td></tr>
</table>
</apex:outputpanel>
:
:
and other codes....
Same concept as the other answers on here, but you can use the rendered attribute on a PageBlock to render that block or not:
<apex:pageBlock rendered="{!object.Color == 'red'}">
it is red
</apex:pageBlock>
<apex:pageBlock rendered="{!object.Color == 'blue'}">
it is blue
</apex:pageBlock>
<apex:pageBlock rendered="{!object.Color == 'green'}">
it is green
</apex:pageBlock>
In visualforce you can use some logical operators and functions.
Explanation here
You need "Logical Functions" list, same code that you provide, in VF must look like this:
{!IF(salary<=0, "Salary is very low to survive.", "No comment sir")}
You need to put the logic in the controller (where most people say it belongs anyways). Your VF would look like:
<table border="0" width="150" height="50" bgcolor="{!bgColorVar}">
And in your controller, define your logic in the getter:
public string bgColorVar{
get{
//logic
}
set;
}
Related
I have an HTML table setup in a visualforce page with some functionality that appears to be outside of the grasp of a standard apex:datatable. When a user updates the information for one of the rows, I'm attempting to rerender the table so the updated values are reflected. If I use an apex:datatable this works fine, BUT then i lose a lot of the functionality I had to add in my table.
The structure is fairly simple, but this is how it goes:
<table>
<thead>
<tr>
<th>Col 1</th>
</tr>
</thead>
<tbody>
<apex:outputPanel id="table-panel">
<apex:repeat value="{!Parent}" var="row">
<tr name="{!row.Id}">
<td>Cell 1</td>
</tr>
<apex:repeat value="Child__r" var="child">
<tr name="child-{!row.Id}">
<td>Child Cell 1</td>
</tr>
</apex:repeat>
</apex:repeat>
</apex:outputPanel>
</tbody>
</table>
This is in essence the functionality I'm trying to accomplish, with a parent object's children listed below it. As of right now, the rerender converts all my table elements into spans and completely garbles everything. Is it possible to rerender a non-visualforce component, or, alternatively, is there a way I could reproduce this functionality in an apex:datatable?
Thanks!
Its easy. Try this, works fine for me even after rerender:
<apex:panelGrid columns="1" width="400" id="myTable">
<apex:facet name="header">
<apex:outputText value="My table header"/>
</apex:facet>
<apex:repeat value="{!Object}" var="row">
<apex:outputText value="{!row.name}" style="display:block;font-weight:bold;"/>
<apex:repeat value="{!row.ObjectChild__r}" var="child">
<apex:outputText value="{!child.name}"/> <br/>
</apex:repeat>
</apex:repeat>
</apex:panelGrid>
Noe you can reRender your "myTable".
I actually ended up discovering the nifty little "layout" attribute of the apex:outputPanel element. Setting this to "block" completely solved all the problems associated with this.
I am trying to display information about Knowledge Articles on my page. One of the things I want to display is the most viewed article stat.
I have a Visualforce Apex component that looks like this:
<apex:component controller="Component_Query" access="global">
<apex:attribute name="QueryString" type="String" required="true" access="global" assignTo="{!queryString}"
description="A valid SOQL query in string form." />
<apex:variable value="{!results}" var="results"/>
<apex:componentBody />
</apex:component>
I have a Visualforce page that looks like this:
<apex:page >
<table id="articles">
<knowledge:articleList articleVar="article" sortBy="mostViewed" pageSize="5">
<tr>
<td>{!article.articlenumber}</td>
<td><a target="_parent" href="{!URLFOR($Action.KnowledgeArticle.View, article.id)}">{!article.title}</a></td>
<td>{!article.articletypelabel}</td>
<td>{!article.lastpublisheddate}</td>
<td>
<c:Query_component queryString="SELECT NormalizedScore FROM KnowledgeArticleViewStat WHERE ParentId = '{!article.id}'">
<apex:repeat value="{!results}" var="result">
</apex:repeat>
</c:Query_component>
</td>
</tr>
</knowledge:articleList>
</table>
</apex:page>
I put the Visualforce Page into a tab. When I view the page, all the information about the knowledge articles show up except for the information about the most viewed stat. How do I see this stat?
You forgot to add an output for the view stat. You must add an <apex:outputText> tag inside the repeat to show the value.
<apex:outputText>{!result.NormalizedScore}</apex:outputText>
This is what I ended up using in my Visualforce page:
<c:Query_component queryString="SELECT NormalizedScore, Id, ParentId FROM KnowledgeArticleViewStat WHERE Channel='Csp'">
<apex:variable value="{!results[articleid]}" var="result"/>
<span class="inlinesparkline">100, {!result}</span>
</c:Query_component>
I have one issue related to visualforce email template please help me out.
I am using below code to hide the tr:
<apex:repeat var="cx" value="{!relatedTo.Airline_Conf_s__r}">
<tr style="{!IF(!cx.Include_in_Confirmation__c == true,"display:none!important; ","")}">
<td>
<apex:outputText value="{!cx.Airlines_Url__c}" escape="false" />
</td>
</tr>
</apex:repeat>
but i need it to done without inline style .how can it possible.
You could try using the "rendered" attribute of apex:outputtext, like this
<apex:outputText rendered = "{cx.Include_in_Confirmation__c}" value="{!cx.Airlines_Url__c}" escape="false" />
You are better off using an apex:outputPanel tag and using the rendered property:
<apex:repeat var="cx" value="{!relatedTo.Airline_Conf_s__r}">
<apex:outputPanel layout="none" rendered="{!cx.Include_in_Confirmation__c == true}">
<tr>
<td>
<apex:outputText value="{!cx.Airlines_Url__c}" escape="false" />
</td>
</tr>
</apex:outputPanel>
Note that the layout attribute is set to "none" this will effectively tell VF not to render a tag but you will get the benefits of being able to dynamically render the TR tag as the repeater loops.
We are using ExtJS4 in our application. We have a problem with grid focus.We are using grid.getView().focusEl.focus() in ExtJS3. Now it seems that this is not working.What is the replacement for this one in ExtJS4.
I have helped you checked on the differences in ExtJS3 and ExtJS4, the major changes is the focusEl has been removed from the gridView element.
In ExtJS3, focusEl is the anchor link in the view
<div class="x-grid3-scroller" id="ext-gen10" style="width: 298px; height: 174px; ">
<div class="x-grid3-body" style="width:100px;" id="ext-gen12">
<div class="x-grid3-row x-grid3-row-first x-grid3-row-last" style="width:100px;">
<table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="width:100px;">
<tbody>
<tr><td class="x-grid3-col x-grid3-cell x-grid3-td-0 x-grid3-cell-first " style="width: 100px;" tabindex="0"><div class="x-grid3-cell-inner x-grid3-col-0" unselectable="on">0</div></td></tr>
</tbody>
</table>
</div>
</div>
</div>
In ExtJS4, this anchor link doesn't exist
Solution
This is a small fiddle test I have created for you. Basically what you need to change is as follow:
grid.getView().el.focus();
Instead of getting the focusEl (an anchor link), we use the whole element.
Hope this solve your problem.
I am trying to figure out how to test fields (included within a apex:repeat) to see if they are blank, or null, and if so display some alternate text (Ex: No records to display) in the table instead of a blank table. Existing code snippet below:
<apex:repeat var="auditList" value="{!relatedTo.Site_Audit__r}">
<tr>
<td>
<apex:outputField value="{!auditList.Audit_Type__c}" />
</td>
<td>
<apex:outputField value="{!auditList.Delivery_Date__c}" />
</td>
<td>
<apex:outputField value="{!auditList.Review_Date__c}" />
</td>
</tr>
</apex:repeat>
So in pseudo code I am looking for a test such as:
IF RELATED RECORDS FOUND FOR APEX:REPEAT PERFORM FOLLOWING:
<apex:repeat var="auditList" value="{!relatedTo.Site_Audit__r}">
<tr>
<td>
<apex:outputField value="{!auditList.Audit_Type__c}" />
</td>
<td>
<apex:outputField value="{!auditList.Delivery_Date__c}" />
</td>
<td>
<apex:outputField value="{!auditList.Review_Date__c}" />
</td>
</tr>
</apex:repeat>
ELSE IF NO RELATED RECORDS PERFORM FOLLOWING:
<tr>
<td>
No records to display.
</td>
</tr>
Thanks in advance for the help!
Update in response to first answer from 'eyescream'
Gave the apex:pageBlock method a shot, but ran into the following error when trying to save/deploy:
Result: FAILED Problem: <messaging:emailTemplate> cannot contain <apex:pageBlock>.
Now this is a email template that produces an attached PDF (see general outline of the code below). So is that the case...pageBlock is not allowed within a email template? Thanks for the help!
<messaging:emailTemplate subject="Your requested quote #{!relatedTo.Name}"
recipientType="Contact"
relatedToType="X360_Contract_Cycle__c">
<messaging:plainTextEmailBody >
.
.
.
</messaging:plainTextEmailBody>
<messaging:attachment renderAs="pdf" filename="{!relatedTo.name}">
.
.
.
<apex:pageBlock rendered="{!AND(NOT(ISNULL(auditList)),auditList.size>0)}">
<apex:repeat var="auditList" value="{!relatedTo.Site_Audit__r}">
<tr>
<td>
<apex:outputField value="{!auditList.Audit_Type__c}" />
</td>
<td>
<apex:outputField value="{!auditList.Delivery_Date__c}" />
</td>
<td>
<apex:outputField value="{!auditList.Review_Date__c}" />
</td>
</tr>
</apex:repeat>
</apex:pageBlock>
<apex:pageBlock rendered="{!OR(ISNULL(auditList),auditList.size=0)}">
<i>No records to display.</i>
</apex:pageBlock>
.
.
.
</messaging:attachment>
</messaging:emailTemplate>
Generally speaking - wrap your code in higher page element (like <apex:pageBlock>) and then use the attribute rendered. It's optional and available on most of the page elements, the component reference should give you complete list of attributes supported for each tag.
In your case I suppose something like that should do the trick:
<apex:pageBlock rendered="{!AND(NOT(ISNULL(auditList)),auditList.size>0)}">
Stuff is in, put "repeat" tag here.
</apex:pageBlock>
<apex:pageBlock rendered="{!OR(ISNULL(auditList),auditList.size=0)}">
No records to display.
</apex:pageBlock>
Feel free to experiment with the syntax. I've used the function names as in the formula editor (for formula fields, validation rules etc.) but normal logic operators like &&, || should be available too.
Use a wrapper ( is my personal favorite), and use a formula that checks the size of the list for the rendered attribute.
<apex:outputPanel rendered="{!relatedTo.Site_Audit__r.size = 0}">
No Records
</apex:outputPanel>
<apex:outputPanel rendered="{!relatedTo.Site_Audit__r.size != 0}">
<apex:repeat var="auditList" value="{!relatedTo.Site_Audit__r}">
...
</apex:repeat>
</apex:outputPanel>
Stick with the wrapper (use apex:outputPanel or apex:variable) and create a method that returns the list size i.e.
public Integer listSize{get {
if(auditList != null)
return auditList.size();
else
return 0;}}
Use this in the conditional that determines visibility.