+ Start a Discussion
paul-lmipaul-lmi 

question on formatting data for VF page

I create a simple VF page and custom controller that I intend to deliver as a Home Page widget for the Ideas object.  The idea (no pun intended) is to better engage my users by putting the ideas functionality right in front of them when they log in.

 

My question is, once I use a controller to return a set of rows from the object, how can I further format these values to present to the user?

 

My controller is just this so far:

public class ideasController { public List<Idea> getNewIdeas(){ return [select id, title, createddate, CreatedBy.Alias, numcomments, votescore from idea where status = 'new']; } }

 

But I need to format the CreatedDate and VoteScore values to something more user appealing.  What would you recommend?

 

Side note, also, how can I control the style of the row/cell values?  They default to left-align, but I want some of them to center.

 

 

<apex:page controller="ideasController" title="Ideas" tabstyle="idea"> <apex:pageBlock > <apex:dataTable value="{!NewIdeas}" var="iIdea" width="100%" > <apex:column > <apex:facet name="header"><b>Title</b></apex:facet> <a href="/ideas/viewIdea.apexp?id={!iIdea.Id}">{!iIdea.Title}</a> </apex:column> <apex:column > <apex:facet name="header"><b>Created On</b></apex:facet> {!iIdea.CreatedDate} </apex:column> <apex:column > <apex:facet name="header"><b>Created By</b></apex:facet> {!iIdea.CreatedBy.Alias} </apex:column> <apex:column > <apex:facet name="header"><b>Score</b></apex:facet> {!iIdea.VoteScore} </apex:column> <apex:column > <apex:facet name="header"><b ><center>Comments</center></b></apex:facet> {!iIdea.NumComments} </apex:column> </apex:dataTable> </apex:pageBlock> </apex:page>

 

 

 

 

 

shan876shan876

hmmm...

 

<apex:outputField value="{CreateDate}"/> or <apex:outputText value="{CreateDate}"/>

 

 That might work...

Strictly IT - Tech Directory

 

 

paul-lmipaul-lmi
no joy on either of those unfortunately.  i also found out that you can't embed VF content into the Home tab, so this project is a bust for now, but I'd still like to know how to do this on the fly formatting.
shan876shan876

Wait you can I did... I embeded a google graph via VF on the home page and also a couple of other things.

The way you do it is Go to 

Setup | Customize | Home | Home Page Components

Click New

Then place in the VF via iframe linking back to the VF page.

Then add it to the Home Page Layout..

 

Hope this helps... Like below...

 Thanks

VF Made Easy

 

<iframe src="/apex/SidebarSummary?core.apexpages.devmode.url=1" width="100%" frameborder="0" height="100"></iframe>

 

 

Tha

 

paul-lmipaul-lmi
yeah, iframes would work well, especially if the VF page has tabs inside itself.  How do you make it so the VF page is only your content, and not the navigation and header for SF too?
shan876shan876

in the VF apex tag

place in showheader="false"  That takes away the tabs...

 

 

<apex:page standardController="Account" extensions="SalesFEDByUserController" showHeader="false" >

VF Made Easy

 

 

 

paul-lmipaul-lmi

thank you so much.  that worked, and the outputField suggestion works for some of the fields, but not all of them, so i'll look into that.

 

any suggestions on optimizing page load?  VF and recently SF itself is just bloated.  home.jsp defaults to be around 500KB in size on first load, which makes agent logins take forever.

shan876shan876

Hmm.. Take a look at your Apex Controller, maybe rearrange it to feed off a <List> or something to get the data back to you in time...

Maybe that would work out..

paul-lmipaul-lmi

here's the controller.  it's pretty basic.  i don't think the bottle neck is the controller though.

 

 

public class ideasController { public List<Idea> getNewIdeas(){ return [select id, title, createddate, CreatedBy.Alias, numcomments, votescore from idea where status = 'new' order by createddate desc limit 5]; } public List<Idea> getImplementedIdeas(){ return [select id, title, createddate, CreatedBy.Alias, numcomments, votescore, lastmodifieddate from idea where status = 'implemented' order by lastmodifieddate desc limit 5]; } }

 

 

 

shan876shan876

can you post your VF Code as well... So I can see what you are feeding back...

shan876shan876

Try this:

Its the get;set; methods...

public class ideasController { public List<Idea> getNewIdeas(){ get { getNewIdeas = [select id,title,createddate,CreatedBy.Alias,numcomments,votescore from idea where status = 'new' order by createddate desc limit 5]; return getNewIdeas ; } set; } public List<Idea> getImplementedIdeas(){ get{ getImplementedIdeas = [select id, title, createddate, CreatedBy.Alias, numcomments, votescore, lastmodifieddate from idea where status = 'implemented' order by lastmodifieddate desc limit 5]; return getImplementedIdeas ; } set; } }

 

paul-lmipaul-lmi
the editor didn't like that syntax for some reason.  what's the differents between what i had (direct query), and what you have, (get results, and then pass the results to the return value)?