syedkabeer
I'm new here

Need to Change field in page

Dear All

     I am trying to change one field availble in page, before changing I was trying to lock the page at that time its throwing some exception.

Please find the attached code.

if( storeElement instanceof Page){

                Page page = (Page)storeElement;

                if(!page.isLocked())

                {

                  page.setLock(true);

                 System.out.println("Expiry Date ======   "+ page.getUid() +"    "+page.getFormData().get(null, "pt_expiryDate").get());

                  FormData formData=page.getFormData();

                  formData.get(null, "pt_expiryDate").setToDefault();

                  System.out.println("isLockSupported()   "+page.isLockSupported());

                  page.setFormData(formData);

                  page.save();

                  page.setLock(false);

                }

                else{

                    System.out.println("Already Locked!!");

                }

            }

If I exceute this code I am getting some exception, shown below.

storeElement.getNamea_z_in_module_and_module_element_descriptions

Exception in thread "main" java.lang.UnsupportedOperationException: lock is not supported for release store elements

    at de.espirit.firstspirit.store.access.DefaultStoreElement.setLock(DefaultStoreElement.java:446)

    at de.espirit.firstspirit.store.access.DefaultStoreElement.setLock(DefaultStoreElement.java:440)

    at de.espirit.firstspirit.store.access.AbstractStoreElement.setLock(AbstractStoreElement.java:1109)

    at com.bosch.ExpiryDate.MyHRExpiryDateExecute.getPageCount(MyHRExpiryDateExecute.java:47)

    at com.bosch.ExpiryDate.MyHRExpiryDateExecute.getData(MyHRExpiryDateExecute.java:99)

    at com.bosch.ExpiryDate.MyHRExpiryDate.main(MyHRExpiryDate.java:35)

Please support me to get this.

Labels (1)
0 Kudos
2 Replies
bIT_sosswald
Returning Responder

Re: Need to Change field in page

Hi,

the error message shows you a hint to the root of the problem. "lock is not supported for release store elements"

The stores in FirstSpirit have to „states“ release and current. If you are using the release state you only get the released versions of a objects in the store and these objects are immutable so you can’t change and therefore lock it.

Your code looks fine but somewhere BEFORE that code snipped is executed there must be a point where the store is set to “release” state.

Take a look into the JavaDoc to see how you can get a store in the current/work state.

The following example show you how to obtain a page in the “current” state so you can lock and change it.

PageStoreRoot pageStore = (PageStoreRoot) userService.getStore(Type.PAGESTORE, false);

Page page = (Page) pageStore.getStoreElement("uid", Page.UID_TYPE);

So you have to ensure that the page object you want to modify is taken from a “current” and not a “release” store.

Greetings

Sandro

0 Kudos
mikula
Crownpeak employee
Crownpeak employee

Re: Need to Change field in page

Hello,

do you need further help or did Sandros reply already help you? If so, it would be great if you marked his reply as "correct answer" so that other community users find the solution easily. If you have

already found a solution by yourself, it would be very kind of you, if you posted it here.   

Best regards 

Martin

0 Kudos