Fetch Id from SelectOneChoice in ADF 12c - oracle-adf

I am using Oracle ADF12C, I have a table which has an strong textselect One Choice>(Customized Query) as a column, on change of the value I need to open a popup, I have tried using value Change Listener to fetch the ID but not able to find. Any Suggestions….
I have tried using the JavaScript to fetch the ID, still it did not work
<af:selectOneChoice value="#{row.bindings.ProfileId.inputValue}"
label="#{row.bindings.ProfileId.label}"
required="#{bindings.Assets1.hints.ProfileId.mandatory}"
shortDesc="#{bindings.Assets1.hints.ProfileId.tooltip}"
id="soc7"
binding="#{GenericListenerBean.assetprofileBV}">
<f:selectItems value="#{row.bindings.ProfileId.items}"
id="si8"/>
<f:validator binding="#{row.bindings.ProfileId.validator}"/>
<af:clientListener method="profileLovValue"
type="valueChange"/>
</af:selectOneChoice>
function profileLovValue() {
alert("function called");
var lov_value = document.getElementById('soc8');
alert("Executedd ======"+lov_value);
var strUser = lov_value.options[lov_value.selectedIndex].value;
alert("value ======"+strUser);
}

There is a couple issues in your code. you are doing a :
var lov_value = document.getElementById('soc8');
when your af:selectOneChoice Html DOM ID will be something like "p1::pc2::soc7".
If you want to get the real Html DOM ID of an element from your browser, you need to right-click it in your browser and click Inspect to check the real ID in your console.
Since you are using the oracle ADF framework, you should also avoid JavaScript and use Java with built-in java ADF fonction.
—If you want to get the value of this #{row.bindings.ProfileId.inputValue} use resolveExpression as describe here https://cedricleruth.com/how-to-retreive-the-value-of-an-iterator-binding-variable-programmatically-in-adf/
//Here is how to simply retreive the value of and ADF Binding from the view El Expression :
//Below is a view example with values taken from an ADF View Object
<af:inputText id="it1" autoSubmit="true" value="#{bindings.YOUR_VO.YOUR_VO_ATTRIBUTE.inputValue}" />
<af:table value="#{bindings.YOUR_VO.collectionModel}" var="row">
<af:column sortProperty="#{bindings.YOUR_VO.hints.YOUR_VO_ATTRIBUTE.name}"
id="c1">
<af:outputText value="#{row.YOUR_VO_ATTRIBUTE}" id="ot1"/>
</af:column>
</af:table>
//Using below function you can easily get any of those value in your ADF Bean as follow :
//Note: replace String by the correct type
String inputTextValue= (String)resolveExpression("#{bindings.YOUR_VO.YOUR_VO_ATTRIBUTE.inputValue}");
String currentRowValue= (String)resolveExpression("#{row.YOUR_VO_ATTRIBUTE}");
/**
* Method for taking a reference to a JSF binding expression and returning
* the matching object (or creating it).
* #param expression EL expression
* #return Managed object
* #author : Duncan Mills, Steve Muench and Ric Smith's JSFUtils class
*/
public static Object resolveExpression(String expression) {
FacesContext facesContext = getFacesContext();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, expression, Object.class);
return valueExp.getValue(elContext);
}
—If you want to get the ID of the element that trigger an event :
public void yourValueChangeEvent(ValueChangeEvent valueChangeEvent) {
String IdOfTheObjectTriggeringTheEvent = valueChangeEvent.getComponent().getId();
}

I think you need change your design to avoid using JavaScript. Oracle ADF run java code on server side.
In the code, you bound the selectOneChoice to assetprofileBV
binding="#{GenericListenerBean.assetprofileBV}">
You can get value of this selectOneChoice by assetprofileBV.getValue() .You can use valueChangeListener attribute to listen when value change and get value

Related

I need to access the old value of ADF viewObject

I have ADF page fragement (.jsff), which conatins ADF form based on ViewObject, I need to get the old value of af:RichInputField using EL expression, when I use:
#{bindings.fieldName.inputValue}, it gets the new submitted value, but what I need is the value before submission...
You can use the valueChangeListener attribute (https://docs.oracle.com/cd/E21043_01/apirefs.1111/e12046/oracle/adf/view/js/event/AdfValueChangeEvent.html) of your af:RichInputField to trigger a java function in a bean that will get the new value and the old value for you to do whatever you want.
Here is a quick example with an inputText (It would work in a similar way with any ADF Faces input) :
//In your jsff
<af:inputText value="#{bindings.YOUR_VO_BINDING_VALUE.inputValue}"
valueChangeListener="#{YOUR_BEAN_SCOPE.YOUR_BEAN.itChange}"
id="it">
<f:validator binding="#{bindings.YOUR_VO_BINDING_VALUE.validator}"/>
</af:inputText>
//In your YOUR_BEAN_SCOPE.YOUR_BEAN
public void itChange(ValueChangeEvent valueChangeEvent) {
String oldValue = valueChangeEvent.getOldValue();
String newValue = valueChangeEvent.getNewValue();
//do whatever you want with those values
}
If you need to set a binding value in the [//do whatever you want with those values] please read https://cedricleruth.com/how-to-set-jsf-binding-attribute-programmatically-in-oracle-adf/ :
JSFUtils.setExpressionValue("#{bindings.YOUR_VO_ATTRIBUTE.inputValue}",oldValue);

How to create checkbox element in htmlunit?

I am trying to use the createElement method explained in the following link:
http://htmlunit.sourceforge.net/apidocs/com/gargoylesoftware/htmlunit/html/InputElementFactory.html#createElement-com.gargoylesoftware.htmlunit.SgmlPage-java.lang.String-org.xml.sax.Attributes-
For this I am trying to use the following code:
HtmlPage page = webClient.getPage("http://...");
HtmlCheckBoxInput checkBox = (HtmlCheckBoxInput) page.createElement("checkbox");
But the createElement method returns an HtmlUnknownElement object. How can I create the checkbox element?
The following code is working while creating an input text element:
HtmlElement tmpCheckBox = (HtmlElement) pageClientInput.createElement("input");
Following the suggestion given here I have tried this other way:
HtmlElement tmpInput = (HtmlElement) page.createElement("input");
tmpInput.setAttribute("type", "checkbox");
HtmlRadioButtonInput tmpCheckBox = (HtmlRadioButtonInput) tmpInput;
tmpCheckBox.setChecked(true);
But I am getting an exception casting the HtmlElement to HtmlRadioButtonInput:
java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlTextInput cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput
I need an HtmlRadioButtonInput in order to use the setChecked method. HtmlElement doesn't have setChecked method available.
Your code wont work because HtmlPage.createElement can't choose the correct Element Factory without attributes. Which you cannot set through this method.
You can access the correct element factory through InputElementFactory and setting the type as checkbox, as below.
WebClient webClient = new WebClient();
webClient.getOptions().setCssEnabled(false);
HtmlPage page = webClient.getPage("http://...");
//Attribute need to decide the correct input factory
AttributesImpl attributes = new org.xml.sax.helpers.AttributesImpl();
attributes.addAttribute(null, null, "type", "text", "checkbox");
// Get the input factory instance directly or via HTMLParser, it's the same object
InputElementFactory elementFactory = com.gargoylesoftware.htmlunit.html.InputElementFactory.instance; // or HTMLParser.getFactory("input")
HtmlCheckBoxInput checkBox = (HtmlCheckBoxInput) elementFactory.createElement(page, "input", attributes);
// You need to add to an element on the page
page.getBody().appendChild(checkBox);
//setChecked like other methods return a new Page with the changes
page = (HtmlPage) checkBox.setChecked(false);
Your createElement call produces an HtmlUnknownElement because there is not checkbox html tag. To create a checkbox you have to create an input with type 'checkbox'.
Start here to read more about html and checkboxes.

Inserting image into visualforce email template (without hard-coding IDs)

The "official" solution for including images in visualforce email templates suggests hard coding IDs in your template to reference an image file stored as a document.
https://help.salesforce.com/HTViewHelpDoc?id=email_template_images.htm&language=en_US
Is there a better way that avoids hard coding instance ID and OID? I tried using the partner URL to grab the instance ID, but I got the following error
Error Error: The reference to entity "oid" must end with the ';' delimiter.
Using:
{!LEFT($Api.Partner_Server_URL_140,FIND(".com/",$Api.Partner_Server_URL_140)+3)/
to replace "https://na2.salesforce.com/"
in
"na2.salesforce.com/servlet/servlet.ImageServer?id=01540000000RVOe&oid=00Dxxxxxxxxx&lastMod=1233217920"
Should I use a static resource instead?
I've arrived here looking for an answer for this question related to hardcoded ID and OID in Visualforce e-mail templates. Well, I found a workaround for that.
First I needed to create a Visualforce Component:
<apex:component access="global" controller="LogomarcaController">
<apex:image url="{!LogoUrl}" />
</apex:component>
In the respective controller class, I've created a SFInstance property to get the correct URL Salesforce Instance, LogoUrl property to concatenate SFInstance and IDs... And Finally I've used Custom Settings (Config_Gerais__c.getInstance().ID_Documento_Logomarca__c) to configurate the ID of Image (in my case, Document Object) on Sandbox or Production:
public class LogomarcaController {
public String LogoUrl {
get {
id orgId = UserInfo.getOrganizationId();
String idDocumentoLogomarca = Config_Gerais__c.getInstance().ID_Documento_Logomarca__c;
return this.SfInstance + '/servlet/servlet.ImageServer?id=' + idDocumentoLogomarca + '&oid=' + orgId ;
}
}
public String SfInstance
{
get{
string SFInstance = URL.getSalesforceBaseUrl().toExternalForm();
list<string> Dividido = SFInstance.split('.visual', 0);//retira o restante a partir de .visual
SFInstance = dividido[0];
dividido = SFInstance.split('://',0);//retira o https://
SFInstance = dividido[1];
if(!SFInstance.contains('sybf')) //managed package prefix, if you need
{
SFInstance = 'sybf.'+ SFInstance;
}
return 'https://'+SFInstance;
}
}
}
And finally, I've added the component in Visualforce template:
<messaging:emailTemplate subject="Novo Ofício - {!relatedTo.name}" recipientType="User" relatedToType="Oficio__c" >
<messaging:htmlEmailBody >
<c:Logomarca />
</messaging:htmlEmailBody>
<messaging:plainTextEmailBody >
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
PS: Some of my variables, properties and comments are in my native language (portuguese). If you have some problems understanding them, please ask me!
We ran into a similar problem and after trying various solutions, the following worked for us. In our case the image is uploaded as a content asset(https://help.salesforce.com/articleView?id=000320130&type=1&language=en_US&mode=1)
Solution:
<img src="{!LEFT($Api.Partner_Server_URL_260,FIND('/services',$Api.Partner_Server_URL_260))}/file-asset-public/<Image_Name_Here>?oid={!$Organization.Id}&height=50&width=50"/>

Pass Parameter to JSF backing bean while rendering of rich data table

i m using JSF 1.2, Servlets 2.5, Tomcat "6" and richfaces 3. I m displaying data from a table in oracle on page using rich:dataTable. now i need to display some customized information in a particular column of table row depending on its id. i tried to send parameter to my backing bean as follows (i know tomcat 7 and el 2.2 jar , servlets 3 would solve this prob but i cant move from my present setup so i wana know my alternatives. thanks)
<rich:dataTable rendered="true" value="#{studentBean.studentList}" var="dataList">
...
<rich:column sortable="true">
<f:facet name="header">
<h:outputText value="Details"/>
</f:facet>
<h:outputText value="#{studentBean.studentCategory(dataList.id)}"/>
</rich:column>
...
</rich:dataTable>
my backing bean is
public String studentCategory(Long id)
{
String categoryString;
//...process table rows with id and return a
//...concatenated string
return categoryString;
}
I get following error
The function studentCategory must be used with a prefix when a default namespace is
not specified
Help is solicited.
JSF 1.2 doesn't support pass arguments to methods. Since you can't migrate to JSF 2. The solution can be use Facelets it lets you implement EL functions.
You can see this answer:
How to create a custom EL function to invoke a static method?
And this article
http://www.ibm.com/developerworks/web/library/j-facelets2/index.html

How to serialize form inside modal window in ExtJS?

I'm trying to build modal windows on the fly from single javascript object passed by server.
But I have no clue how can I serialize form inside modal window without defining form variable .
In most examples serialize process look like this:
//create form
var CustomForm = new Ext.FormPanel({...});
//submiting form
CustomForm.getForm().submit({...});
In my case all inner components like "form" are created from xtype value,and no variable is assigned to it.
Is there any way to select and serialize form using something like this:
Ext.get(this).select('form').serialize();
or what is apropriate way of doing so?
You can assign the form an id and use Ext.getCmp(formid).
To retrieve the form values of a FormPanel use myFormPanel.getForm().getValues()
That will come back with a js object representing the form fields.
I wrote a function to take values from a form and generate a string for adding to the query string:
/**
* takes an array of form values and converts them into a
* query string
*
* #param {object} Ext.form
* #return {string}
*/
this.serialize_form_values = function(form)
{
var serial = '',
values = form.getValues();
for(var value in values)
serial += '&' + value + '=' + values[value];
return serial.substr(1);
};
Maybe it could be useful for someone?

Resources