Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Problem with Calculated Element

I have added a node to my web dynpro. The purpose of this node is to hold a switch that I toggle based on the date range of the data being shown. I've missed something as the element is ALWAYS set to the current week. Where did I go wrong?

  public static void wdDoModifyView(IPrivateDetailView wdThis, IPrivateDetailView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
    if (firstTime)
    {
		ICalculatedValuesElement elem = wdContext.createCalculatedValuesElement();
		wdContext.nodeCalculatedValues().bind(elem);
		elem.setWeekType(WeekToProcess.CURRENT_WEEK);	
    }
    BuildView(wdContext.currentCalculatedValuesElement().getWeekType(), wdThis, wdContext, view);
    IWDMessageManager msgMgr = wdThis.wdGetAPI().getComponent().getMessageManager();
    java.util.Date mDate = new java.util.Date();
    msgMgr.reportWarning("Do Modify View " + mDate + " Date type " + String.valueOf(wdContext.currentCalculatedValuesElement().getWeekType()));
    //@@end
  }

  //@@begin javadoc:onActionPriorWeek(ServerEvent)
  /** Declared validating event handler. */
  //@@end
  public void onActionPriorWeek(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionPriorWeek(ServerEvent)
	wdContext.currentCalculatedValuesElement().setWeekType(WeekToProcess.PRIOR_WEEK);
	IWDMessageManager msgMgr = wdThis.wdGetAPI().getComponent().getMessageManager();
	java.util.Date mDate = new java.util.Date();
	msgMgr.reportWarning("Prior Week " + mDate + " calc value=" + String.valueOf(wdContext.currentCalculatedValuesElement().getWeekType()) );
	wdContext.currentCalculatedValuesElement().setWeekType(WeekToProcess.CURRENT_WEEK);
	msgMgr.reportWarning("Prior Week " + mDate + " calc value=" + String.valueOf(wdContext.currentCalculatedValuesElement().getWeekType()) );

	GregorianCalendar priorWeekDate = new GregorianCalendar();
	priorWeekDate.setTime(new java.util.Date());
	priorWeekDate.add(GregorianCalendar.DATE,-7);
	wdThis.wdGetEmployeeTimeVerificatioinCustController().getEmployeeTimeData(priorWeekDate.getTime());
    //@@end
  }

  //@@begin javadoc:onActionCurrentWeek(ServerEvent)
  /** Declared validating event handler. */
  //@@end
  public void onActionCurrentWeek(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionCurrentWeek(ServerEvent)
	wdContext.currentCalculatedValuesElement().setWeekType(WeekToProcess.CURRENT_WEEK);    
	IWDMessageManager msgMgr = wdThis.wdGetAPI().getComponent().getMessageManager();
	java.util.Date mDate = new java.util.Date();
	msgMgr.reportWarning("Current Week "+ mDate);
	wdThis.wdGetEmployeeTimeVerificatioinCustController().getEmployeeTimeData(new java.util.Date());
    //BuildView(WeekToProcess.CURRENT_WEEK, wdThis, wdContext, view);
  //  wdThis.wdFirePlugDetailViewOut();
   
    //@@end
  }

   //@@begin others
	private static void BuildView(short weekToProcess,IPrivateDetailView wdThis, IPrivateDetailView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view)
	{
		IWDMessageManager msgMgr = wdThis.wdGetAPI().getComponent().getMessageManager();
		java.util.Date mDate = new java.util.Date();
	msgMgr.reportWarning("BuildView " + mDate);
	if (wdContext.nodeCalculatedValues().currentCalculatedValuesElement().getWeekType() == WeekToProcess.CURRENT_WEEK)
		{
			msgMgr.reportWarning("Current Week Type");
			IWDButton currentWeekButton = (IWDButton) view.getElement("CurrentWeek");
			IWDButton priorWeekButton = (IWDButton) view.getElement("PriorWeek");
			currentWeekButton.setEnabled(false);
			priorWeekButton.setEnabled(true);
			
		}
		else
		{
			msgMgr.reportWarning("Prior Week Type");
			IWDButton currentWeekButton = (IWDButton) view.getElement("CurrentWeek");
			IWDButton priorWeekButton = (IWDButton) view.getElement("PriorWeek");
			currentWeekButton.setEnabled(true);
			priorWeekButton.setEnabled(false);
		}
		IWDButton verifyButton = (IWDButton) view.getElement("Verify_0");
		verifyButton.setEnabled(false);
                           .... other code
}

Regards,

Diane

Former Member
Former Member replied

The approach to set the context attribute value in the action handler and query it inside wdDoModifyView() is generally ok. But I would add an additional boolean context attribute "rebuildView" which would be set in the action handler if the week perspective really has been changed.

In wdDoModifyView(), rebuild the view only if the "rebuildView" flag is set:

wdDoModifyView()
{
  if ( wdContext.currentContextElement().rebuildView() )
  {
     /* Rebuild view depending on current week perspective */
     ...
     /* Reset flag */
     wdContext.currentContextElement().setRebuildView(false);
  }
}

Armin

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question