cancel
Showing results for 
Search instead for 
Did you mean: 

container.destroy() or resetView()?

Former Member
0 Kudos

Hallo,

I want delete all elements of my container when refreshing, so in my method I have the following:

container.destroyAllChildren();

container.destroy();

container = null;

But sometimes I get an exception about the destroy.

Can I use the resetView instead of detroy methods?

myView.resetView();

container=null;

Thanks...

Andrea

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

container.destroy() recursively destroys all children of a UIElementContainer, the container itself remains intact. That's probably what you need.

Armin

Former Member
0 Kudos

If container.destroy() recursively destroys all children , which is the difference between container.destroy() and container.destroyAllChildren() ?

Thanks,

andrea

Former Member
0 Kudos

container.destroy() destroys the container and all aggregated elements (not only the children).

container.destroyAllChildren() destroys all aggregated children.

Example: You have a Group G (which is a UIElementContainer) that has children A, B and a header H.

Then

G.destroy() destroys G, A, B and H

G.destroyAllChildren() destroys A and B only

Armin

Former Member
0 Kudos

Thanks.

The problem is that the application works fine almost always.

Sometimes I get this error:

CreationFailedException: Cannot create view element implementation com.sap.tc.webdynpro.clientserver.uielib.standard.impl.TransparentContainer

public void retrieveProcess( com.sap.tc.webdynpro.progmodel.api.IWDView view )

.

.

.

if(container != null)

{

container.destroyAllChildren();

container.destroy();

container = null;

}

.

.

.

.

container = (IWDTransparentContainer) view.createElement(IWDTransparentContainer.class, "ElementContainer1");

.

.

.

Thanks e regards,

Andrea

Former Member
0 Kudos

I suppose you are getting this error always in the second time, ie only for one time you will be able to destroy and create the container.....?

it is because you are using 'ElementContainer1' ID always. code in such a way that you give new ID to the container when you create.

i am not sure of this solution, just sharing what came to my mind.

Former Member
0 Kudos

Thanks,

now try to change the id always...

Former Member
0 Kudos

Is your problem solved..?

Former Member
0 Kudos

First, such code should only be called inside wdDoModifyView() or in some static method called from there. Everything else violates the programming model.

Secondly, the following code should work:


wdDoModifyView(...)
{
   if (...)
   {
     IWDTransparentContainer container = (IWDTransparentContainer ) view.getElement("id_of_container");
     if (container != null)  container.destroy();
     container = ((IWDTransparentContainer) view.createElement("id_of_container");
   }
}

Armin

Former Member
0 Kudos

Hallo,

I dont'use wdDoModifyView to dinamically create the UI.

I have a method that calls a web service and builds the layout:

public void retrieveProcess( com.sap.tc.webdynpro.progmodel.api.IWDView view )

{

//@@begin retrieveProcess()

IWDMessageManager msg = wdComponentAPI.getMessageManager();

logger.infoT("RoadMapView.retrieveProcess", "" + Calendar.getInstance().getTime());

category.log(Severity.INFO,logger, "RoadMapView.createRoadMap" + " - " + Calendar.getInstance().getTime());

wdContext.getContext().reset(false);

try {

if(container != null)

{

container.destroyAllChildren();

container.destroy();

viewRoadMap.resetView();

msg.reportSuccess("Container != null ,"" id_container after destroy= "container.getId());

container = null;

msg.reportSuccess("ElementContainer1 Exist? " + (view.getElement("ElementContainer1")== null? false: true));

}

} catch (Exception e) {

// TODO Auto-generated catch block

}

try {

ProcessInquiryT processInquiryT = new ProcessInquiryT();

PrincipalT principalT = new PrincipalT();

principalT.setPrincipal(wdContext.currentContextElement().getIUserID());

processInquiryT.setIUser(principalT);

ApplicationContextT context = new ApplicationContextT();

context.setApplicationId(wdContext.currentContextElement().getApplicationID());

context.setEntityType(wdContext.currentContextElement().getEntityType());

processInquiryT.setContext(context);

String [] processID = {wdContext.currentContextElement().getProcessID()};

processInquiryT.setProcess(processID);

TLManagementPpt port = wdThis.wdGetDA_compController().getTLManagementPpt();

SystemT[] arrSystemT = port.retrieveProcess(processInquiryT);

if (arrSystemT == null)

{

//msg.reportSuccess("RoadMapView.retrieveProcess: arrSystemT = null");

}

else

{

SystemT systemT = arrSystemT[0];

String system_id = systemT.getSequenceGroup1().getSystemId();

String system_desc = systemT.getSequenceGroup1().getSystemDesc();

FlowT flowT = systemT.getSequenceGroup1().getFlowList().getSequenceGroup1().getFlow()[0];

String flow_id = flowT.getSequenceGroup1().getFlowId();

String flow_desc = flowT.getSequenceGroup1().getFlowDesc();

ProcessT processT = flowT.getSequenceGroup1().getProcessList().getSequenceGroup1().getProcess()[0];

String process_id = processT.getSequenceGroup1().getProcessId();

String process_desc = processT.getSequenceGroup1().getProcessId();

FileT fileT = processT.getSequenceGroup1().getFileLIst().getSequenceGroup1().getFilePackage()[0];

String file_id = fileT.getSequenceGroup1().getId();

String file_desc = fileT.getSequenceGroup1().getDescription();

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setSystem_desc(system_desc);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setSystem_id(system_id);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setFlow_desc(flow_desc);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setFlow_id(flow_id);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setProcess_desc(process_desc);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setProcess_id(process_id);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setFilepackage_desc(file_desc);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setFilepackage_id(file_id);

int phaseSize = processT.getSequenceGroup1().getPhaseList().getSequenceGroup1().getPhase().length;

for (int i = 0; i < phaseSize; i++)

{

PhaseT phaseT = processT.getSequenceGroup1().getPhaseList().getSequenceGroup1().getPhase()<i>;

IWDNodeInfo fase = wdContext.getNodeInfo().addChild("dyn_phase" + i, null, true, true, true, false, false, true, null, null, null);

fase.addAttribute("dyn_phaseDesc", "com.sap.dictionary.string");

fase.addAttribute("dyn_phaseId", "com.sap.dictionary.string");

IWDNodeInfo sottoFasi = fase.addChild("dyn_subphases", null, true, true, true, false, false, true, null, null, null);

int subPhaseSize = phaseT.getSequenceGroup1().getSubPhaseList().getSequenceGroup1().getSubPhase().length;

for (int j = 0; j < subPhaseSize; j++)

{

IWDNodeInfo sottoFase = sottoFasi.addChild("dyn_subphase" + j, null, true, true, true, false, false, true, null, null, null);

sottoFase.addAttribute("dyn_subphaseId", "com.sap.dictionary.string");

sottoFase.addAttribute("dyn_subphaseDesc", "com.sap.dictionary.string");

sottoFase.addAttribute("dyn_subphaseStatus", "com.sap.dictionary.string");

}

}

for (int i = 0; i < phaseSize; i++)

{

PhaseT phaseT = processT.getSequenceGroup1().getPhaseList().getSequenceGroup1().getPhase()<i>;

IWDNode nodoDynFase = wdContext.currentContextElement().node().getChildNode("dyn_phase" + i, IWDNode.LEAD_SELECTION);

IWDNodeElement element = nodoDynFase.getCurrentElement(); //Attribute("labelFase");

element.setAttributeValue("dyn_phaseDesc", phaseT.getSequenceGroup1().getPhaseDesc());

element.setAttributeValue("dyn_phaseId", phaseT.getSequenceGroup1().getPhaseId());

IWDNode nodoDynSubFasi = nodoDynFase.getChildNode("dyn_subphases", IWDNode.LEAD_SELECTION);

int subPhaseSize = phaseT.getSequenceGroup1().getSubPhaseList().getSequenceGroup1().getSubPhase().length;

for (int j = 0; j < subPhaseSize; j++)

{

SubPhaseT subPhaseT = phaseT.getSequenceGroup1().getSubPhaseList().getSequenceGroup1().getSubPhase()[j];

IWDNode nodoDynSubFase = nodoDynSubFasi.getChildNode("dyn_subphase" + j, IWDNode.LEAD_SELECTION);

IWDNodeElement elementDynSubFase = nodoDynSubFase.getCurrentElement();

elementDynSubFase.setAttributeValue("dyn_subphaseId",subPhaseT.getSequenceGroup1().getSubPhaseId());

elementDynSubFase.setAttributeValue("dyn_subphaseDesc", subPhaseT.getSequenceGroup1().getSubPhaseDesc());

elementDynSubFase.setAttributeValue("dyn_subphaseStatus", subPhaseT.getSequenceGroup1().getStatus());

}

}

IWDGroup rootContainer = (IWDGroup) view.getElement("gr_rootGroup");

container = (IWDTransparentContainer) view.createElement(IWDTransparentContainer.class, "ElementContainer1"+(new Date()).getTime());

IWDGridLayout layout = (IWDGridLayout) container.createLayout(IWDGridLayout.class);

layout.setColCount(phaseSize);

layout.setCellSpacing(10);

layout.setStretchedHorizontally(false);

String currentStatus = "";

String currentPhaseId = "";

String currentSubphaseId = "";

String currentNotifyId = "";

String lastStatus = "";

for (int i = 0; i < phaseSize; i++)

{

PhaseT phaseT = processT.getSequenceGroup1().getPhaseList().getSequenceGroup1().getPhase()<i>;

IWDTransparentContainer blocco = (IWDTransparentContainer) view.createElement(IWDTransparentContainer.class,"blocco"i(new Date()).getTime());

IWDGridLayout blocco_layout = (IWDGridLayout) blocco.createLayout(IWDGridLayout.class);

layout.setColCount(phaseSize);

layout.setCellSpacing(10);

IWDTable tb_phase = (IWDTable) view.createElement(IWDTable.class,"tb_phase"+i);

String bindPath = "dyn_phase"+i;

tb_phase.bindDataSource(bindPath);

tb_phase.setFooterVisible(false);

tb_phase.setRowSelectable(false);

tb_phase.setSelectionMode(WDTableSelectionMode.NONE);

tb_phase.setScrollableColCount(0);

tb_phase.setVisibleRowCount(1);

tb_phase.setWidth("100%");

IWDTableColumn col_phase = (IWDTableColumn) view.createElement(IWDTableColumn.class,"col_phase"+i);

IWDTextView tw_phase = (IWDTextView) view.createElement(IWDTextView.class,"tw_phase"+i);

tw_phase.bindText(bindPath+".dyn_phaseDesc");

col_phase.setTableCellEditor(tw_phase);

tb_phase.addColumn(col_phase);

blocco.addChild(tb_phase);

IWDTable tb_subPhase = (IWDTable) view.createElement(IWDTable.class,"tb_subPhase"+i);

tb_subPhase.setFooterVisible(false);

tb_subPhase.setRowSelectable(false);

tb_subPhase.setSelectionMode(WDTableSelectionMode.NONE);

tb_subPhase.setVisibleRowCount(1); //verificare con Alberto

tb_subPhase.bindDataSource( bindPath+".dyn_subphases");

int subPhaseSize = phaseT.getSequenceGroup1().getSubPhaseList().getSequenceGroup1().getSubPhase().length;

for(int j = 0; j< subPhaseSize; j++)

{

SubPhaseT subPhaseT = phaseT.getSequenceGroup1().getSubPhaseList().getSequenceGroup1().getSubPhase()[j];

String status = subPhaseT.getSequenceGroup1().getStatus();

IWDTableColumn col_subPhase = (IWDTableColumn) view.createElement(IWDTableColumn.class,"col_subPhase"i"_"+j);

IWDTextView tw_subPhase = (IWDTextView) view.createElement(IWDTextView.class,"tw_subPhase"i"_"+j);

tw_subPhase.bindText( bindPath+".dyn_subphases.dyn_subphase" + j + ".dyn_subphaseDesc");

tw_subPhase.setTooltip(status);

col_subPhase.setTableCellEditor(tw_subPhase);

lastStatus = status;

if (status != null && !status.equals(""))

{

currentStatus = status;

currentPhaseId = phaseT.getSequenceGroup1().getPhaseId();

currentSubphaseId = subPhaseT.getSequenceGroup1().getSubPhaseId();

if (status.equals(DAConst.STATUS_NOTIFY))

{

currentNotifyId = subPhaseT.getSequenceGroup1().getNotifyId();

}

}

if(status.equals(DAConst.STATUS_RUNNING)){

col_subPhase.setCellDesign(wdContext.currentColoreCelleElement().getRUNNING());

}else if(status.equals(DAConst.STATUS_NOTIFY)){

col_subPhase.setCellDesign(wdContext.currentColoreCelleElement().getNOTIFY());

}else if(status.equals(DAConst.STATUS_COMPLETED)){

col_subPhase.setCellDesign(wdContext.currentColoreCelleElement().getCOMPLETED());

}else if(status.equals(DAConst.STATUS_ABORTED)){

col_subPhase.setCellDesign(wdContext.currentColoreCelleElement().getABORTED());

}else{

//col_subPhase.setCellDesign(wdContext.currentColoreCelleElement().getOTHER());

}

tb_subPhase.addColumn(col_subPhase);

}

blocco.addChild(tb_subPhase);

container.addChild(blocco);

}

rootContainer.addChild(container);

wdContext.currentContextElement().setVisibility_completed(WDVisibility.NONE);

wdContext.currentContextElement().setVisibility_running(WDVisibility.NONE);

wdContext.currentContextElement().setVisibility_notify(WDVisibility.NONE);

wdContext.currentContextElement().setVisibility_aborted(WDVisibility.NONE);

wdContext.currentContextElement().setUrl("");

if (currentStatus.equals(DAConst.STATUS_COMPLETED))

{

if(lastStatus.equals(DAConst.STATUS_COMPLETED))

{

wdContext.currentContextElement().setVisibility_completed(WDVisibility.VISIBLE);

wdContext.currentContextElement().setEnabled_pollingProcess(false);

}

else

{

wdContext.currentContextElement().setVisibility_running(WDVisibility.VISIBLE);

}

}

else if (currentStatus.equals(DAConst.STATUS_ABORTED))

{

wdContext.currentContextElement().setVisibility_aborted(WDVisibility.VISIBLE);

}

else if (currentStatus.equals(DAConst.STATUS_RUNNING))

{

wdContext.currentContextElement().setVisibility_running(WDVisibility.VISIBLE);

}

else if (currentStatus.equals(DAConst.STATUS_NOTIFY))

{

String currData=wdContext.currentContextElement().getCurrData();

String currState= process_id"_"currentPhaseId"_"currentSubphaseId;

if(currData==null)

currData="";

if(!currData.equalsIgnoreCase(currState))

{

//fermare il refresh

wdContext.currentContextElement().setEnabled_pollingProcess(false);

wdContext.currentContextElement().setVisibility_notify(WDVisibility.VISIBLE);

//ricavare l'url dal file di properties

String currentFlow = flow_id.substring(0, 3);

//msg.reportSuccess("url=" + DAProperties.URL_NOTIFY + currentFlow + "." + currentPhaseId + "." + currentSubphaseId + "." + currentNotifyId);

String url = wdThis.wdGetDA_compController().getPropertyValue(DAProperties.URL_NOTIFY + "." + currentFlow + "." + currentPhaseId + "." + currentSubphaseId + "." + currentNotifyId);

url = url.replaceAll("%processId",wdContext.currentContextElement().getProcessID());

wdContext.currentContextElement().setUrl(url);

}

else

wdContext.currentContextElement().setVisibility_running(WDVisibility.VISIBLE);

}

else

{

wdContext.currentContextElement().setVisibility_running(WDVisibility.VISIBLE);

}

}

String refreshAt = wdContext.currentLabelsElement().getMsgRefreshAt().replaceAll("%1", Utils.getCurrentDate());

wdContext.currentContextElement().setRefreshAt(refreshAt);

} catch (RemoteException e) {

// TODO: handle exception

msgReportException("retrieveProcess", e);

logger.throwing("RoadMapView.retrieveProcess",e);

} catch (Exception e) {

// TODO: handle exception

msgReportException("retrieveProcess", e);

logger.throwing("RoadMapView.retrieveProcess",e);

}

//@@end

}

Former Member
0 Kudos

Move all the code that accesses the view elements from this method to wdDoModifyView(). Set a flag (boolean context attribute) inside the method to indicate that the view should be modified. In wdDoModifyView() check this flag and reset it after the view modification.

Armin

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

As per SAP documentation

destroy()->Destroys this view element by removing it from the containing view and from the containing parent.

destroyAllChildren()->Destroys all elements in the Children list.

Regards

Ayyapparaj

sanyev
Active Participant
0 Kudos

Hi Andrea,

myView.resetView() Resets the view's layout to the initial state declared at design time. That is, all dynamic modifications to the view layout are thrown away and the view returns to the state it was in when it was initialised. Only design times UI Elements will remain and if you don't have any UI Element in your View at design time you can use resetView() to clear all the dynamic changes to the view.

Why do you want to clear all the UI Elements on refreshing? Refreshing the screen can happen due to lot of reasons (happens on every round trip) and recreating your entire UI on every refresh seems unnecessary. If you can explain why you need to do this may be we can come up with some alternatives.

On the root container you can call container.destroyAllChildren(); to remove all the UI elements.

Regards,

Sanyev