I've created a simple ColdFusion 9 ORM test as follows.
Application.cfc:
component {
this.ormenabled = "true";
this.datasource = "cfartgallery";
this.ormsettings.logSQL = "true";
}
State.cfc:
component persistent="true" {
property name="state_code" type="string" fieldtype="id";
property name="state_name" type="string" fieldtype="column";
}
index.cfm:
<cfscript>
ormreload();
</cfscript>
<cfdump var="#EntityLoad("State")#" />
Upon calling index.cfm I get the following error:
Error while loading the entity.
java.sql.SQLSyntaxErrorException: Table/View 'State' does not exist.
The error occurred in D:/WebDocs/tada/data/misc/basicorm/index.cfm: line 62
60 : </cfscript>
61 :
62 : <cfdump var="#EntityLoad("State")#" />
However, if I change index.cfm to use cfquery, shown below, a recordset is returned as expected without error.
<cfquery name="getstates" datasource="cfartgallery">
SELECT * FROM State
</cfquery>
I know that State.cfc is being processed because I can change the file to cause errors. Can anyone think of the problem? Thanks.
You need to enable the dbcreate setting for ORM config. Either set it to update or dropcreate. By default ORM will not create new or update tables based on persistent CFCs.
Related
I have a page at
/content/admin/mycomp-test/testpage/jcr:content
property
name : validated
type : boolean
value : true
Is it possible to get the above property value inside CQ dialog's
I tried the following code, but it;s not working.
<listeners jcr:primaryType="nt:unstructured"
beforesubmit="function(dialog) {
var compPath = dialog.path;
Resource res= resourceResolver.getResource(compPath);
Node node = res.adaptTo(Node.class);
var prop= node.getProperty('validated').getValue().getString();
CQ.Ext.Msg.alert('valieded : ' + prop);
return false;
}" />
}
The following code will get you what you're asking for:
<listeners jcr:primaryType="nt:unstructured"
beforesubmit="function(dialog) {
var properties = CQ.shared.HTTP.eval(CQ.shared.HTTP.noCaching(dialog.path + '.-1.json'));
var validated = properties.validated;
CQ.Ext.Msg.alert('Validated: ' + validated);
}" />
}
In my opinion, it's better to keep this type of JavaScript in an external file which would be included in a clientlib that only displays in edit mode. You can then call that method from within the dialog. For example:
beforesubmit="function(dialog){ foo.bar.baz(dialog); }"
If you're looking to validate user input, there are better ways. Explore the Widgets API documentation.
I want to delete specific record using Field Name
Table : Dummy Entity
Field Id
Field Name
public void deleteLocation(req, res){
String getLocationName = request.getParameter("locationName");
Location locationToDelete = new LocationImpl();
locationToDelete.setLocationName(getLocationName);
LocationLocalServiceUtil.deleteLocation(locationToDelete);
}
It's not showing me any error but the record doesn't get deleted. Please hep me out.
The simplest way to achieve this is to add <finder> node for that specific field in service.xml, as following (saying Location is your entity name, name is your field name and Name is the name of finder entry in service.xml) and build service:
<column name="name" type="String" />
<finder name="Name" return-type="Collection">
<finder-column name="name" />
</finder>
On successful build, it will create CRUD operations in your service based on that column. Now you can find following methods in your LocationUtil.java:
findByName,
removeByName,
countByName,
Create following (new) method in LocationLocalServiceImpl.java:
public void deleteLocationsByName(String name){
try{
LocationUtil.removeByName(name);
}catch(Exception ex){
// log your exception
}
}
Again, on building service, this method will be available for use in your action class from LocationLocalServiceUtil.java, where you can call it like:
public void deleteLocation(req, res){
String locationName = request.getParameter("locationName");
LocationLocalServiceUtil.deleteLocationsByName(locationName);
}
That's it, you have added custom finder method to your service.
If you want to remove an element by id, you can do it by the "LocalServiceUtil.delete(id)"
If you want to remove an elements by other field than id, you need to do a custom Query for that, you can search in the portal soruce for the file: portal.xml containing this example:
<sql id="com.liferay.portal.service.impl.ResourceBlockLocalServiceImpl.deleteResourceBlock">
<![CDATA[
DELETE FROM
ResourceBlock
WHERE
(referenceCount <= 0) AND
(resourceBlockId = ?)
]]>
</sql>
You can see here how to implement a custom query:
https://dev.liferay.com/develop/tutorials/-/knowledge_base/6-2/developing-custom-sql-queries
I am using an ajax box which will fetch the list of object based the string provided in the box as follows:
<p:inputText id="zid" placeholder="Search" value="#{resourceListView.wanted}">
<p:ajax event="keyup" update=":form:abc"
listener="#{resourceListView.SearchResources}" />
</p:inputText>
SearchResources will fetch the objects based on the value of input box as follows:
public void SearchResources(String wanted) {
this.resources=resourceServiceImpl.listResources(wanted);
}
I was running the query in the DAO which was meant to return the object based on the search. But it didn't return anything. So I sysout the query and the query comes out as follows:
SELECT * FROM test.resourcemaster where Resource_ZID like '%javax.faces.event.AjaxBehaviorEvent[source=org.primefaces.component.inputtext.InputText#79d635]%' OR Employee_ID like '%javax.faces.event.AjaxBehaviorEvent[source=org.primefaces.component.inputtext.InputText#79d635]%' OR First_Name like '%javax.faces.event.AjaxBehaviorEvent[source=org.primefaces.component.inputtext.InputText#79d635]%' OR Last_Name like '%javax.faces.event.AjaxBehaviorEvent[source=org.primefaces.component.inputtext.InputText#79d635]%'
the query was supposed to be searching on the 'wanted'
Could anyone explain what is the problem.
Your SearchResources() method accepts one parameter, which you don't supply from page. That's why AjaxBehaviorEvent is passed to it (event.toString(), to be more precise), which is the default if you don't specify parameters in method call.
Try changing the ajax listener to listener="#{resourceListView.SearchResources(resourceListView.wanted)}"
Or, simply remove the parameter from the method, and use bean wariable wanted
public void SearchResources() {
this.resources = resourceServiceImpl.listResources(this.getWanted());
}
I have a managed bean as my View in which I have a method called List<ArrayList> getImages() where I query the database and get a List of entities which is returned by the method. All well and good.
My problem is that when I try to iterate over this List from with JSF using either <c:forEach or ui:repeat e.g. <c:forEach var="image" items="#{viewBean.images}"> the server, Tomee throws and exception java.lang.UnsupportedOperationException: Result lists are read-only. and I'm not even doing anything with the values at this point.
If I just return the ArrayList with simple objects, no problem. I understand it must be something to do with the fact the object is an entity therefore tied to the database but I'm not sure the correct way, or best practice, to return the what I need to the JSP page.
Thanks.
Jason.
Edit. Below is method used for retrieving objects from db for iteration in JSF.
public List<ProfileImage> getProfileImageList() {
profileImageList = facade.findAllByProfileId(1L);
while (profileImageList.size() < 4) {
// Add placeholders to bring the list size to 4
ProfileImage placeHolder = new ProfileImage();
placeHolder.setProfileId(1L);
profileImageList.add(placeHolder);
}
return Collections.unmodifiableList(profileImageList);
}
JSF snippet below : Note, I am not doing anything with the value of var for now
<ui:repeat value="${imageUploadView.profileImageList}" var="profileImage">
<p:commandButton id="imageBtn_1" value="Picture 1" type="button" />
<p:overlayPanel id="imagePanel_1" for="imageBtn_1" hideEffect="fade" >
<ui:include src="/WEB-INF/xhtml/includes/profile_imageupload.xhtml" />
</p:overlayPanel>
</ui:repeat>
The following error is generated
javax.el.ELException: Error reading 'profileImageList' on type com.goobang.view.ImageUploadView
viewId=/profile/create_profile.xhtml
location=/Users/xxxxxxxxx/Documents/NetBeansProjects/testmaven/target/testmaven-1.0-SNAPSHOT/profile/create_profile.xhtml
phaseId=RENDER_RESPONSE(6)
Caused by:
java.lang.UnsupportedOperationException - Result lists are read-only.
at org.apache.openjpa.lib.rop.AbstractResultList.readOnly(AbstractResultList.java:44)
/profile/create_profile.xhtml at line 16 and column 87 value="${imageUploadView.profileImageList}"
I have solved it. The exception is thrown because I am modifying the list after assigning it to the result set. If I simply return the result set all is fine. So to achieve what I intended in getProfileImageList() I created a new ArrayList from the original, as suggested by tt_emrah, and then modify that before returning it.
public List<ProfileImage> getProfileImageList() {
profileImageList = new ArrayList(facade.findAllByProfileId(1L));
while (profileImageList.size() < 4) { // Add placeholders to bring the list size to 4
ProfileImage placeHolder = new ProfileImage();
placeHolder.setProfileId(1L);
profileImageList.add(placeHolder);
}
return profileImageList;
}
All i want to do is display the full path of my Taxonomy field....Simple!
I've added this little snippet of XML to my <ArrayOfProperty> within the field i want to apply this property to.
<Property>
<Name>IsPathRendered</Name>
<Value xmlns:q7="http://www.w3.org/2001/XMLSchema" p4:type="q7:boolean" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">true</Value>
</Property>
All the settings of the field seems to be applied, I've checked via the GUI and SharePoint mananger and it seems to be applied!
However the does not show the full path....
When i go in to the GUI and save the field all works !?!?!?!
My question is why do i have to go in after my deployment and save the field to get this setting to apply?
Although I also would like to know how to do this in XML, there is an alternative: you can handle it in a feature receiver by setting the IsPathRendered property on a TaxonomyField instance.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (SPSite site = (SPSite)properties.Feature.Parent)
{
Guid fieldId = new Guid("{YOUR-FIELD'S-GUID-GOES-HERE}");
TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField;
// Render full taxonomy path, not just the leaf.
field.IsPathRendered = true;
field.Update();
}
}