I am working on ADF. I need to display help text on mouse hover for each value of drop down. I struggled al lot but dint find any thing to do in model layer. Finally I endded up playing with string EL expression.
<af:table value="#{bindings.LetterUIConfig1.collectionModel}" rendered="false"
width="98%" styleClass="AFStretchWidth" var="row"
rows="#{bindings.LetterUIConfig1.rangeSize}"
emptyText="#{bindings.LetterUIConfig1.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.LetterUIConfig1.rangeSize}"
rowBandingInterval="0" id="t1" columnStretching="column:c1"
inlineStyle="border-style:hidden;" horizontalGridVisible="false"
verticalGridVisible="false">
<af:column sortProperty="#{bindings.LetterUIConfig1.hints.Name.name}"
sortable="false" id="c1" noWrap="false" headerText="">
<af:panelFormLayout id="pfl1" labelWidth="40%" fieldWidth="60%"
maxColumns="1" labelAlignment="start">
<af:panelLabelAndMessage label="#{row.Name}" id="plam1"
styleClass="alignLeft"
labelStyle="text-align: left;">
<af:panelGroupLayout id="pgl1">
<af:selectOneChoice value="#{row.bindings.Name.inputValue}"
label="#{row.bindings.Name.label}"
required="#{bindings.LetterUIConfig1.hints.Name.mandatory}"
shortDesc="#{bindings.LetterUIConfig1.hints.Name.tooltip}"
id="soc1">
<af:forEach items="#{bindings.LetterAttributeLOV.rangeSet}" var="list">
<af:selectItem id="si1" value="#{list.AttVal}"/>
</af:forEach>
</af:selectOneChoice>
<af:selectBooleanCheckbox value="#{row.bindings.Name.inputValue}"
rendered="#{row.Type eq 'SBC'}"
label="#{row.bindings.Name.label}"
shortDesc="#{bindings.LetterUIConfig1.hints.Name.tooltip}"
id="sbc1"/>
<af:selectManyCheckbox label="#{row.Name}" id="smc1"
rendered="#{row.Type eq 'SMC'}">
<f:selectItems value="#{row.bindings.Name.items}" id="si2"/>
</af:selectManyCheckbox>
</af:panelGroupLayout>
</af:panelLabelAndMessage>
</af:panelFormLayout>
<af:spacer id="s1" height="10"/>
</af:column>
My problem is select item is not displaying substring it is displaying only value. I did use valuePassThrough but no luck.
Try a define method for initialize to itemList;
public List getSelectItemList(){
ArrayList list = new ArrayList();
Iterator<Object> iterator = resolveExpression("#{bind here your LOV}");
while (iterator.hasNext()) {
Object obj= iterator.next();
list.add(new SelectItem(enterObjValue, enterObjValueLabel));
}
return list;
}
public Object resolveExpression(String expression) {
FacesContext fc = getFacesContext();
ELContext elCtx = fc.getELContext();
return fc.getApplication().getExpressionFactory().createValueExpression(elCtx, expression, Object.class).getValue(elCtx);
}
and bind this list to Select one choice component.
<af:selectOneChoice value="#{row.bindings.Name.inputValue}"
label="#{row.bindings.Name.label}"
required="#{bindings.LetterUIConfig1.hints.Name.mandatory}"
shortDesc="#{bindings.LetterUIConfig1.hints.Name.tooltip}"
id="soc1">
<f:selectItems value="#{yourBean.selectItemList}"
id="sadsadsa"/>
</af:selectOneChoice>
Related
I have list of check boxes inside rich:dataTable and I want to check all the boxes at once with a single check box from header column.
<rich:column id="includeInWHMapping" >
<f:facet name="header">
<h:selectBooleanCheckbox value="#{checkallbox.selectAll}">
<f:ajax actionListener="#{checkallbox.selectAllBox}" render="selectedForWHProcess" />
</h:selectBooleanCheckbox>
</f:facet>
<h:selectBooleanCheckbox id="selectedForWHProcess" value="#{checkallbox.checked[data]}">
<f:ajax actionListener="#{checkallbox.selectAllRows}"/>
</h:selectBooleanCheckbox></rich:column>
Code in checkallbox Bean:
private Map<StandardStructure, Boolean> checked = new HashMap<StandardStructure, Boolean>();
private boolean selectAll;
public boolean isSelectAll() {
return selectAll;
}
public void setSelectAll(boolean selectAll) {
this.selectAll = selectAll;
}
public Map<StandardStructure, Boolean> getChecked() {
return checked;
}
public void setChecked(Map<StandardStructure, Boolean> checked) {
this.checked = checked;
}
public void selectAllBox(ValueChangeEvent e){
boolean newSelectAll = (Boolean) e.getNewValue();
Iterator<StandardStructure> keys = checked.keySet().iterator();
while(keys.hasNext()){
StandardStructure ss = keys.next();
checked.put(ss, newSelectAll);
}
}
When I check the h:selectBooleanCheckBox of header column nothing happens. What am I missing here? Should I have to implement Map for "selectAll" property too?
Thanks.
First of all. f:ajax doesn't have actionListener, it has a listener. Read the docs here. Second thing, you can use valueChangeListener on h:selectBooleanCheckbox and only there. Third, listener inside rows boxes is wrong. Basically, it looks like you need to read this topic.
Now, here is the working example:
<h:form>
<rich:dataTable value="#{checkallbox.allValues}" var="data" id="dataTable">
<rich:column>
<f:facet name="header">
<h:selectBooleanCheckbox value="#{checkallbox.selectAll}"
valueChangeListener="#{checkallbox.selectAllBox}">
<f:ajax render="dataTable" />
</h:selectBooleanCheckbox>
</f:facet>
<h:selectBooleanCheckbox value="#{checkallbox.checked[data]}">
<f:ajax />
</h:selectBooleanCheckbox>
</rich:column>
<!-- other columns -->
</rich:dataTable>
</h:form>
Other possible problems with your code (since you've shared just a part).
The data table needs to be in form, since you're executing ajax inside.
Your keys in map are objects. You have to make sure that equals method is good. In 95% of case the default is not, especially if they are #Entity.
You have to make sure that the map is populated with false at the beginning. I use #PostConstruct:
#PostConstruct
protected void performPostConstructAction() {
for (StandardStructure s : getAllValues()) {
checked.put(s, false);
}
}
Thanks Emil! I solved it.
public void selectAllBox(){
if(!selectAll){
for(StandardStructure item : ssTable.getDto()){
checked.put(item, true);
}
}else{
for(StandardStructure item : ssTable.getDto()){
checked.put(item, false);
}
}
}
I need af:selectOneChoice populated with values from the backing bean and one the value from the list (say index=5) should be selected by default. We are using Oracle Adf 10.*
Can somebody help me on this ?
Thanks
For populating the list values, you can use:
<af:selectOneChoice value="val3" label="XXXX" id="soc1" >
<f:selectItems value="#{YourBean.values}" id="si1"/>
</af:selectOneChoice>
In YourBean.java , you will have a method like:
public List<SelectItem> getValues() {
if (list == null) {
list = new ArrayList<SelectItem>();
list(new SelectItem("val1","Label 1"));
list(new SelectItem("val2","Label 2"));
list(new SelectItem("val3","Label 3"));
}
return list;
}
This way you will see "Label 3" as default value in your choice list.
For setting default value, you can use this:
<af:selectOneChoice label="My Field"
id="MyField" value="#{bindings.MyAttribute.inputValue}"
autoSubmit="true"
binding="#{MyBean.myField}">
<f:selectItems value="#{bindings.MyAttribute.items}"
id="MyFieldItems"/>
</af:selectOneChoice>
Notice that SelectOneChoice field has a binding to a java bean. We will use setter method to set default value.
public void setMyField(RichSelectOneChoice myField) {
// since getter/setter methods are called multiple times on
// page load, we need to prevent setting attribute value more than once
if(myField != null && myField.getValue() == null){
ADFUtils.setBoundAttributeValue("MyAttribute", "SomeValue");
}
this.myField = myField;
}
For setting default index (for example, first from the list) we can use a similar approach:
public void setMyField(RichSelectOneChoice myField) {
if(myField != null && myField.getValue() == null){
// default value will be 1st from the list
myField.setValue(0);
}
this.myField = myField;
}
How to add a progress message like "Fetching Data" pragmatically. When the data is getting fetched , i need to display this message on the blank page.I am new to ADF , so pardon me if it is some thing very basic . I couldn't find it on net.
You can use javascript in your page or pagefragment. My example uses a page fragment, so the id of the popup must contain the region. If you have trouble locating the correct id you can look it up from any browser, by using View Source, and searching for the name you gave it (in this case splashPopup).
<af:resource type="javascript">
function enforcePreventUserInput(evt) {
var popup = AdfPage.PAGE.findComponentByAbsoluteId('pt1:r1:0:splashPopup');
if (popup != null) {
AdfPage.PAGE.addBusyStateListener(popup, handleBusyState);
evt.preventUserInput();
}
}
function handleBusyState(evt) {
var popup = AdfPage.PAGE.findComponentByAbsoluteId('pt1:r1:0:splashPopup');
if (popup != null) {
if (evt.isBusy()) {
popup.show();
}
else if (popup.isPopupVisible()) {
popup.hide();
AdfPage.PAGE.removeBusyStateListener(popup, handleBusyState);
}
}
}
</af:resource>
The popup inside the pageFragment. It displays a simple gif animation of a spinning circle. You can find numerous other animations if you need to on google.
<af:popup id="p1" contentDelivery="immediate">
<af:dialog id="d2" type="none" closeIconVisible="false" title="Loading">
<af:panelGroupLayout id="pgl5" layout="vertical" halign="center">
<af:image source="/images/loading.gif" shortDesc="Loading data..." id="i1"/>
</af:panelGroupLayout>
</af:dialog>
</af:popup>
Now, I think you will want to show the popup during a long running query or some other long running process, after pressing a button or an image link. For this you must define a clientListener on your component, which uses the javascript methods defined above.
<af:commandImageLink text="Test LongRunning Query" id="cil1" icon="/icons/excel.jpg"
action="#{myBean.doStuff}"
<af:clientListener method="enforcePreventUserInput" type="action">
</af:clientListener>
</af:commandImageLink>
If you have a long running method call then you can call that method on page load
<af:serverListener type="onloadEvent"
method="#{backingBeanScope.initBean.callMethod}"/>
<af:clientListener type="load" method="triggerOnLoad"/>
<af:resource type="javascript">
function triggerOnLoad(event)
{
AdfCustomEvent.queue(event.getSource(), "onloadEvent", {},false);
return true;
}
</af:resource>
and then use adf status indicator to show the status on the page.
<af:panelStretchLayout id="psl1" startWidth="33%" endWidth="33%"
topHeight="33%" bottomHeight="33%">
<f:facet name="bottom"/>
<f:facet name="center">
<af:statusIndicator id="si1"/>
</f:facet>
<f:facet name="start">
<af:panelGroupLayout id="pgl2"/>
</f:facet>
<f:facet name="end">
<af:panelGroupLayout id="pgl3"/>
</f:facet>
<f:facet name="top">
<af:panelGroupLayout id="pgl4"/>
</f:facet>
</af:panelStretchLayout>
Refer to this blog post fro more details
Show status indicator for long running method calls - ADF
im tring to display records in question__c object along with fields in object as radio button. but im not able to get radio button value. getting only radio button without name.
im new to salesforce.if this is very basic question pls excuse me.
<apex:page standardController="question__c" extensions="GetQuestionList" >
<apex:form >
<apex:repeat value="{!que}" var="a">
<apex:pageBlock >
<apex:pageBlockSection columns="1">
{!a.Quiz_question__c} {!a.id} <br/>
<apex:selectRadio value="{!selectedAns}" >
<apex:selectOption itemValue="{!opt3}" itemLabel="{!a.option_3__c}"/>
<apex:selectOption itemValue="{!opt4}" itemLabel="{!a.option_4__c}"/>
</apex:selectRadio>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:repeat>
</apex:form>
</apex:page>
____mycontroller is
public class GetQuestionList {
question__c q1;
public List<question__c> que{set;}
public List<question__c> getque(){
List<question__C> que= new List<question__c>();
for(question__C q:[select Quiz_question__c,id from question__c]){
que.add(q);
system.debug(que);
}
system.debug(que);
return que;
}
public String selectedAns{get;set;}
public String opt2{get;set;}
public String opt4{get;set;}
public String opt3{get;set;}
public GetQuestionList(ApexPages.StandardController controller) {
}
}
The reason you have no label is because the value field on the <apex:selectRadio> is a String variable, rather than a field. If you want to add a label, there is a label attribute on that visualforce component you can use.
If you want the label to be dynamically shown based on an actual field's label in the data model, you need to set the value field to that field. An example of that would be if you had an Answer__c field on the Question__c object.
<apex:selectRadio value="{!a.Question__r.Answer__c}">
<apex:selectOption itemValue="{!opt3}" itemLabel="{!a.option_3__c}"/>
<apex:selectOption itemValue="{!opt4}" itemLabel="{!a.option_4__c}"/>
</apex:selectRadio>
That value field would use the label assigned to that field in the object model by default.
I have a data table which iterates through a custom object and generates checkboxes. On the second page, I want to determine which of these checkboxes have been selected.
In the VisualForce page:
Age <apex:inputText value="{!age}" id="age" />
<apex:dataTable value="{!Areas}" var="a">
<apex:column >
<apex:inputCheckbox value="{!a.name}" /> <apex:outputText value="{!a.name}" />
</apex:column>
</apex:dataTable>
In the Controller:
public String age {get; set; }
public List<Area_Of_Interest__c> getAreas() {
areas = [select id, name from Area_Of_Interest__c];
return areas;
}
On my second page, I can retrieve the value that the user put in the textbox "age" by using {!age}. How Do I retrieve which checkboxes have been checked?
Thank you.
Ok, if you want to handle it with Javascript, use Pavel's method, otherwise use the following to do it via the controller. You must create a wrapper class for whatever you wish to track. I'm not sure how it works, but somehow if you name a boolean variable "selected" in your wrapper class, it is mapped to the checkbox. Below is the code:
So in your Visual force page, do:
<apex:dataTable value="{!Foos}" var="f">
<apex:column >
<apex:outputLabel value="{!f.foo.name}" /> <apex:inputCheckbox value="{!f.selected}" />
</apex:column>
</apex:dataTable>
<apex:commandButton action="{!getPage2}" value="go"/>
In your Controller, do the following:
1) Make a Wrapper class with the boolean "selected", which somehow maps to the inputCheckbox selected:
public class wFoo {
public Foo__c foo {get; set}
public boolean selected {get; set;}
public wFoo(Foo__c foo) {
this.foo = foo;
selected = false; //If you want all checkboxes initially selected, set this to true
}
}
2) declare the list variables
public List<wFoo> foos {get; set;}
public List<Foo__c> selectedFoos {get; set;}
3) Define the accessor for the List
public List<wFoo> getFoos() {
if (foos == null) {
foos = new List<wFoo>();
for (Foo__c foo : [select id, name from Foo__c]) {
foos.add(new wFoo(foo));
}
}
return foos;
}
4) Define the method to process the selected checkboxes and place them in a List for use on another page
public void processSelectedFoos() {
selectedFoos = new List<Foo__c>();
for (wFoo foo : getFoos) {
if (foo.selected = true) {
selectedFoos.add(foo.foo); // This adds the wrapper wFoo's real Foo__c
}
}
}
5) Define the method to return the PageReference to the next page when the submit button is clicked
public PageReference getPage2() {
processSelectedFoos();
return Page.Page2;
}
In my current project I had faced with the same issue. I used apex:pageBlockTable, but I guess that you can use my code (I made some changes in my code for an object names)
<apex:pageBlockTable value="{!Areas}" var="areas">
<apex:column width="25px">
<apex:facet name="header">
<input type="checkbox" onClick="selectAll();" />
</apex:facet>
<input type="checkbox" id="{!areas.Id}" onClick="saveSelection();" />
</apex:column>
... some additional columns
</apex:pageBlockTable>
I had placed custom object ids to the input id in html, and it looks as
<input id="003R000000lCIq6IAG" onclick="saveSelection();" type="checkbox">
<input id="003R000000lCIoJIAW" onclick="saveSelection();" type="checkbox">
The saveSelection() function has written on javascript
<script>
var areaIds = [];
function saveSelection() {
var selectedIds = areaIds.join('');
$j(':checkbox').each(function(){
if (this.checked) {
if (selectedIds.indexOf(this.id) === -1) {
areaIds.push(this.id);
selectedIds = selectedIds + this.id;
}
} else {
if (selectedIds.indexOf(this.id) !== -1) {
for (i=0; i < areaIds.length; i++) {
if (areaIds[i] === this.id) {
areaIds.splice(i, 1);
selectedIds = areaIds.join('');
}
}
}
}
});
}
and for the restoring was used the following code
function restoreSelection() {
contIds = areaIds.join('');
i = 0;
$j(':checkbox').each(function(){ if(this.id !== ''){ if(contIds.indexOf(this.id) !== -1){this.checked=true;};}});
}
I use jQuery here, that means you should include the following code to your page too
<apex:includeScript id="JQuery" value="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"/>
... some code
<script>
window.$j = jQuery.noConflict();
... some code
</script>
The js is also involved from pagination buttons:
<apex:panelGrid columns="7">
<apex:commandButton status="fetchStatus" reRender="results" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page" onClick="saveSelection();" oncomplete=" restoreSelection()"/>
<apex:commandButton status="fetchStatus" reRender="results" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page" onClick="saveSelection();" oncomplete="restoreSelection()"/>
<apex:commandButton status="fetchStatus" reRender="results" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page" onClick="saveSelection();" oncomplete=" restoreSelection()"/>
<apex:commandButton status="fetchStatus" reRender="results" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page" onClick="saveSelection();" oncomplete=" restoreSelection()" />
<apex:outputText >{!(pageNumber * size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText>
<apex:outputPanel style="color:#4AA02C;font-weight:bold">
<apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
</apex:outputPanel>
</apex:panelGrid>
I hope this may help you.