AW: [opencms-dev] Writing a CmsProperty that doesnt exist or is empty

Manuel Wallnoefer manuel.wallnoefer at msk-informatik.at
Sat Jul 15 18:39:22 CEST 2006


Solved!!!

 

For writing a property you have to lock the resource before  ;-)

 

 

~manuel

 

 

  _____  

Von: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] Im Auftrag von Manuel Wallnoefer
Gesendet: Freitag, 14. Juli 2006 16:37
An: 'The OpenCms mailing list'
Betreff: [opencms-dev] Writing a CmsProperty that doesnt exist or is empty

 

Hi all,

 

in my code i have a CmsProperty object called "prop".

 

If the object is the null object I want to create a new one and write a
value into it.

 

But now the problem is that I always get Exception:

 

 

Error writing property "SchlagwortIds" on resource "/myresource/"

 

If I open the file manually and write a value into the property field it
works.  

Also when I open the file properties manually an does't write a value in the
field it works too!

 

I'm very confused now!!

 

My code looks like this:

 

 

if (toDo.equalsIgnoreCase("add")) {

                        CmsObject cmsObj = cms.getCmsObject();

                        CmsResource r = cmsObj.readResource(file);

                        CmsProperty cmsProp =
cmsObj.readPropertyObject(r,"SchlagwortIds", false);

                        String ids = "";

 

                        if (cmsProp != CmsProperty.getNullProperty()) {

                             ids = cmsProp.getValue().toUpperCase();

                             StringBuffer buffer = new StringBuffer(ids);

                             buffer.append(schlagwort);

                             buffer.append("#");

                             ids = buffer.toString();

                             cmsProp.setValue(ids, "SchlagwortIds");

                             cmsObj.writePropertyObject(file, cmsProp);

                        } else {

                             StringBuffer buffer = new StringBuffer(ids);

                             buffer.append(schlagwort);

                             buffer.append("#");

                             ids = buffer.toString();

                             //out.println("ids:"+ids);

                             CmsProperty prop = new CmsProperty(null,
null,null, true);

                             prop.setName("SchlagwortIds");

                             prop.setStructureValue(ids);

                             prop.setAutoCreatePropertyDefinition(true);

                             prop.setValue(ids, "SchlagwortIds");

                             cmsObj.writePropertyObject(file, prop);

                        }

 

                  }

 

 

Thx for help !!!

 

~manuel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20060715/cd2104e8/attachment.htm>


More information about the opencms-dev mailing list