I am having problems while trying to render a pageblocksection in visualforce. The code that i have used is as given below.
<apex:pageBlockSection title="My Content Section" columns="2">
<apex:pageBlockSectionItem>
<apex:outputLabel value="Account Site"/>
<apex:outputPanel>
<apex:inputText value="{!account.site}" id="account__site"
onclick="changefont(this)">
<apex:actionSupport event="onclick"
rerender="thePageBlock" status="Status"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
Here I am trying to render a page block and a javascript function at the same time, i,e the checking of a checkbox(Account Site). The problem here is when i try to execute the changefont(this) function in the onclick of apex:inputText and then try to render "thePageblock" in event="onclick" of apex:actionSupport the rendering does not take place. Is there a problem with my code or should i do this a different way.
Thanks..
Try calling your Javascript function from the onsubmit or oncomplete attribute of your apex:actionSupport tag:
<apex:inputText value="{!account.site}" id="account__site" >
<apex:actionSupport event="onclick" rerender="thePageBlock"
status="Status" onsubmit="changefont(this)" />
</apex:inputText>
Related
I'm trying to use command buttons using a dynamic component. I want to render these command buttons on the bottom of the page but I'm not able to do it. when I use location=top, it works. when I use location=bottom, I can't see the buttons at all. When I use location=both, I see them only at the top. I'm not using any facets. Please help me if someone knows!
I used them using apex code.
This is the VF page:
<apex:page title="Opportunity Display" controller="MyPageController1" showHeader="true" sidebar="false" readOnly="true" cache="false" >
<apex:sectionHeader subtitle="SOQL Offset Example w/Dynamic Page Buttons" title="Opportunity Display Table" />
<apex:form >
<apex:pageBlock >
<apex:dynamicComponent componentValue="{!myCommandButtons}" />
<apex:actionFunction action="{!refreshGrid}" name="queryByPage" reRender="myPanel,myButtons" >
<apex:param name="firstParam" assignTo="{!selectedPage}" value="" />
</apex:actionFunction>
<apex:pageBlockSection title="Opportunity Display (Total List Size: {!total_size})" collapsible="false">
<apex:outputPanel id="myPanel">
<apex:pageMessages id="theMessages" />
<apex:pageBlockTable value="{!opportunity}" var="n" align="center">
<apex:column><apex:inputCheckbox value="{!n.checked}"/></apex:column>
<apex:column value="{!n.cat.Id}" />
<apex:column value="{!n.cat.Name}" />
<apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
I have a custom Cases apex page where I use a apex:pageBlockTable to display my list of Cases. Here is the code for it:
<apex:page standardController="Case" recordSetVar="Case" sidebar="true" showHeader="true">
<apex:form >
<apex:pageBlock title="Cases">
<apex:outputLabel value="View:"/>
<apex:selectList value="{!filterId}" size="1">
<apex:actionSupport event="onchange" rerender="cases_table"/>
<apex:selectOptions value="{!listviewoptions}"/>
</apex:selectList>
<apex:pageBlock >
<apex:pageBlockButtons >
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!case}" var="c" rows="50" id="cases_table" >
<apex:column >
<a target="_parent" href="{!URLFOR($Action.Case.View, c.id)}">{!c.CaseNumber}</a>
<apex:facet name="header">Case Number</apex:facet>
</apex:column>
<apex:column value="{!c.ContactId}" />
<apex:column value="{!c.Subject}" />
<apex:column value="{!c.Status}" />
<apex:column value="{!c.Priority}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
<base target="_parent"/>
</apex:page>
I would like to get a button inside my apex:pageBlockButtons like in the default Cases page. When the user clicks the button, I would like it to take the user to the new Cases page. I tried this:
<apex:commandButton action="{!new}" value="New"/>
but that gave me an error. How do I make a button that will take me to the new Cases page?
Try this:
<apex:commandButton onclick="window.location.href='{!URLFOR($Action.Case.NewCase)}'" value="New" immediate="true" rerender="blank"/>
Important to note that the rerender tag is needed otherwise the page will do a postback. By using a dummy rerender tag the redirect will work. Immediate is there to avoid running any validation rules on click.
I have a custom Cases apex page where I use a apex:pageBlockTable to display my list of Cases. Here is the code for it(custom object):
<apex:commandButton action="{!URLFOR($Action.Your_Custom_Object__c.New)}" ...>
I have a VF page where I am using checkbox fiels, I want to display three other fiels if the checkbox is selected.
How can I go about doing that ?
Thanks !!
Use the rendered attribute on <apex:inputfield> or <apex:inputtext>. By setting this attribute, you can control whether or not a component appears on a Visualforce Page.
Include all fields that may or may not be shown on the Visualforce Page, but set rendered="{!Object.YourCheckboxField}" on the fields that you want to show/hide based on the checkbox field. Optionally, you can use a Visualforce function like IF or NOT.
For example, if you wanted to show or hide the Email field on Contacts based on whether or not the HasOptedOutOfEmail field is true or false, it would look like this.
<apex:page standardController="Contact">
<apex:sectionHeader title="Custom Contact Visualforce Page" />
<apex:form>
<apex:pageblock>
<apex:pageblocksection>
<apex:inputfield value="{!Contact.FirstName}" />
<apex:inputfield value="{!Contact.LastName}" />
<apex:inputfield value="{!Contact.Phone}" />
<apex:inputfield value="{!Contact.Email}" rendered="{!NOT(Contact.HasOptedOutOfEmail)}" />
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
I have a VF page where i am using a apex:pageblocktable to display bunch of records.
One of the columns is a picklist and i need to display/not display fields according to selection on the picklist.
<apex:pageBlockTable value="{!showRecord}" var="item">
<apex:column headerValue="Delivery">
<apex:inputField value="{!item.delivery__c}"/>
</apex:column>
<apex:column headerValue="Roadway">
<apex:inputField value="{!item.road__c}"/>
</apex:column>
<apex:column headerValue="Rail">
<apex:inputField value="{!item.rail__c}"/>
</apex:column>
</apex:pageBlockTable>
in the above code delivery_c is picklist with values roadways and railways. if the user selects roadways then i need to display road--c and if user selects railways then i need to display rail_c
How can i go about doing that?
Thanks
One way to do this would be to use partial-page refreshes in Visualforce.
Put both fields in the same column and use the "rendered" attribute to dynamically show/hide the field using an if-statement. Then you set up an AJAX onchange event handler for the delivery__c field using the actionSupport tag. This will basically listen for that field to change then refresh the table on the page. Each time this is refreshed, your if statements will be re-evaluated and result in showing one of the two fields in that column.
I didn't get a chance to try this but I think it should work.
<apex:pageBlockTable id="mytable" value="{!showRecord}" var="item">
<apex:column headerValue="Delivery">
<apex:actionRegion>
<apex:inputField value="{!item.delivery__c}">
<apex:actionSupport event="onchange" reRender="mytable">
</apex:inputField>
</apex:actionRegion>
</apex:column>
<apex:column headerValue="Delivery Type">
<apex:inputField rendered="{!item.delivery__c='Road'}" value="{!item.road__c}"/>
<apex:inputField rendered="{!item.delivery__c='Rail'}" value="{!item.rail__c}"/>
</apex:column>
</apex:pageBlockTable>
I have created a search query which returns the records in a table. I have used command in the records returned so that i can edit them and save them in the table only. But after changing the records in the table and clicking on the SAVE button, I am not able to update the the records in the table. How can I use 'rerender' to show the updated data? The page code and controller action I'm using are below:
<!-- Page -->
<apex:pageBlock id="pb1">
<apex:outputPanel id="pan">
<apex:pageBlockTable value="{!l1}" var="k" rendered="{!flag}" id="pb">
<apex:column value="{!k.First_Name__c}"/>
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
<apex:column value="{!k.Last_Name__c}"/>
<apex:inlineEditSupport event="ondblclick" showOnEdit="save"/>
<apex:column value="{!k.E_mail__c}"/>
<apex:inlineEditSupport event="ondblclick" showOnEdit="save"/>
<apex:column value="{!k.Employee_ID__c}"/>
<apex:commandButton action="{!save}" id="saveButton" value="Save" />
</apex:pageBlockTable>
</apex:outputPanel>
<apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
<apex:commandButton action="{!save}" id="saveButton" value="Save"/>
<apex:actionSupport event="onclick" rerender="pan" status="refreshstatus"/>
<apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
<apex:actionStatus id="refreshstatus" startstyle="color:green;" startText="Saving....">
</apex:actionStatus>
</apex:pageBlock>
// controller action
public pagereference save(){update l1;return null;}}
Posting some of your code would go a long way here, but the long and the short of it is this:
<!-- put your table in a panel with an ID -->
<apex:outputPanel id="thePanel:>
<!-- put your table here -->
</apex:outputPanel>
<!-- specify the panel's ID as the rerender target for the action -->
<apex:commandButton value="Save" action="{!TheSaveAction}" rerender="thePanel"/>
And then make sure your controller returns a Pagereference with a value of null:
public Pagereference TheSaveAction()
{
// save
return null;
}
If you're still struggling after doing this, put in the page code (or the relevant parts) so I can see what's going on.