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

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

Related

Fetch Id from SelectOneChoice in ADF 12c

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

How to handle incremental fetches from Salesfore and Database Component

I have a salesforce query which returns contact information. I need to save the data in 2 tables. In the first table I have to store some metadata about the contacts in an intermediate state. I then get the auto-generated metadata table ID from the metadata saved and apply it to every contact. I then have to save the contact data into a database table and then finally update the contacts metadata to its final state. The problem is that there is a lot of data so I have to include a fetch size when performing this process. What I want to achieve should be something like this, please note this is only what I am looking to achieve. How can I know that the fetch contacts is complete, so that I can save the final state? How can I structure the flow for transactions?
Ideally, I would like to pass the ConsumerIterator to a Java component where I can easily control the process. Can I pass a reference of the ConsumerIterator to a Java component for example? If I can how can I do so?
<sfdc:query fetchSize="100" config-ref="sfdc-connector"
query="dsql:SELECT Id, Account.Id,
Account.Name, Account.PersonEmail, Account.LastName From Contact" />
dw:transform-message metadata:id="d1f6ab4f-4b40-4e30-ae" doc:name="trnsfm">
<enricher target="variable:metaInfo">
<flow-refname="getContactMetadata"/>
</enricher>
<dw:set-payload><![CDATA[%dw 1.0
.//Rest of transformer
<db:insert config-ref="MySQL_Configuration" doc:name="Save Metatdata">
...
</db:insert>
<db:insert config-ref="MySQL_Configuration" doc:name="Save contacts">
....
<db:insert>
<db:insert config-ref="MySQL_Configuration" doc:name="Update Metadata
Final State">
....
<db:insert>
</flow>
Problem Solved. I wrote a Java Component, implementing Callable and grabbed the ConsumerIterator. I then was able to use the iterator to obtain items in fetchSize. I then used Spring Jdbc since the data model is simple enough to transactionally save the data

How to inject an error message into entity without using validation in cakephp3?

I have a model wich checks a lot of things in beforeSave callback. I do not want to use cakephp validation system for that purpose because it is more simple for me in this case.
If the checking chain fails in somewhere I return false and no saving happens, It is the normal work. I want to give back informal error messages in the entity to use it in the controller and/or view.
How I can do that?
Example:
public function beforeSave($event, $entity, $options)
{
if($entity->isNew())
{
if(fail1) $entity->inserterrormessage('XYZ is missing');
if(fail2) $entity->inserterrormessage('Please check if...');
}
}
How I can do that?
Via the errors() method, or as of CakePHP 3.4 the setError() and setErrors() methods.
$entity->errors('propertyName', ['Message']);
$entity->setErrors(['propertyName' => ['Message']]);
$entity->setError('propertyName', ['Message']);
In case the error isn't related to an actual entity property, just choose a special name, like _generic. Alternatively create custom generic error storage functionality in a base entity or trait.
See also
Cookbook > Database Access & ORM > Entities > Validation Errors
API > \Cake\DataSource\EntityTrait::errors()
API > \Cake\DataSource\EntityTrait::setError()
API > \Cake\DataSource\EntityTrait::setErrors()

TableRegistry unable to find table (namespace issue ?)

I'm currently using CakePHP 3's ORM on a Slim Framework 3 project.
I used CakePHP's naming conventions for my namespaces and classes. I'm trying to get my users by accessing the users' table (location : App\Model\Table\UsersTable.php).
In my controller (App\Controller\UsersController.php), when I try :
$usersTable = TableRegistry::get('Users'); // NOT working
$usersTable = TableRegistry::get('Users', ['className' => \App\Model\Table\UsersTable::class]); // working
I have to specifically set my className (which is horrible, because I need to do this in every controller and table (for associations) classes). I don't get what I did wrong and why CakePHP is not able to retrieve these classes.
My composer.json is as following :
{
"require": {
"slim/slim": "^3.0",
"cakephp/orm": "^3.2",
"cakephp/validation": "^3.2",
"cakephp/i18n": "^3.2",
},
"autoload": {
"psr-4": {
"App\\": "src"
}
}
}
My project's files are located under src/ (for example, users' table is in src/Model/Table).
Does anyone have an idea on how I could fix this and directly be able to use TableRegistry::get('Users'); and being forced to add the className ?
That's what happens when using non-standard namespaces, and/or not configuring the base namespace option (properly), ie App.namespace.
Short classname resolution needs to know about the possible base namespace, otherwise it's impossible to build the proper fully qualified name, ie you must tell CakePHP about App
\Cake\Core\Configure::write('App.namespace', 'App');
Without this information, the short classname would only resolve to Model\Table\UsersTable.
Cookbook > Configuration > General Configuration
Cookbook > Database Access & ORM > Table Objects > Configuring the Namespace to Locate ORM classes

SalesForce Bulk API: Relationship between custom object and Account

I have a custom object in SalesForce called Deal, which is a child of the built-in Account object. I am trying to use the Bulk XML API to upload a batch of records, but I can't seem to figure out how to specify this relationship correctly. From the documentation it says that you should reference a custom object's relationships like so:
<Relationship__r>
<sObject>
<some_indexed_field>#####</some_indexed_field>
</sObject>
</Relationship__r>
If you have any idea how to specify a relationship to the Account object from a custom object I'd really appreciate it.
Added
The Deal object has the following 2 fields:
DealID
API Name - DealID__c
Data Type - Text(255)(External ID)(Unique Case Sensitive)
Account
API Name - Account__c
Data Type - Master-Detail(Account)
Request XML:
<Account__r>
<sObject>
<ID>0013000000kcWpfAAE</ID>
</sObject>
</Account__r>
Result XML:
<result>
<errors>
<message>Field name provided, Id is not an External ID or indexed field for Account</message>
<statusCode>INVALID_FIELD</statusCode>
</errors>
<success>false</success>
<created>false</created>
</result>
There appears to be a bug and you have to strip out all whitespace and newlines when dealing with reference objects.
Check out:
http://success.salesforce.com/ideaview?id=08730000000ITQ7AAO
From the docs
<RelationshipName>
<sObject>
<IndexedFieldName>rwilliams#salesforcesample.com</IndexedFieldName>
</sObject>
Everything looks good, but instead of using "ID" for the Indexed Field Name, you need to use "Account__c". That should take care of your issue.

Resources