cancel
Showing results for 
Search instead for 
Did you mean: 

Date Navigator : parameter passing

Former Member
0 Kudos

Hi,

I am very new to this domain and need a help in the UI element DateNavigator.

On selection of a particular week, the action method created for the view gets invoked but parameter values haven't passed.

For the action I had created two parameters week(int) and year(int).On debugging I find that none of the parameters were passed.

Rahul

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks for all the inputs.

Sebastian, you mentioned of binding the value (selected date) of Date Navigator to context. I find two properties of DateNavigator firstSelectedDate and lastSelected date, which one to bind (there is no date range involved in my case).

Should I then parse the date and get the week and year values from it.When I select a week from the Navigator would the date attribute hold some value.

In the dateNavigator API, in events section it is mentioned

• onWeekSelect

Specifies the action that is carried out when the user chooses a week. Event parameters are the chosen weeks (in the range of 1 to 53) and the chosen year.

Event Parameter Type

week int

year int

I would like to use this method.Please tell me how to map parameters.I have written the following lines in the view

public void onActionWeekSelect(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, int week, int year )

{

//@@begin onActionWeekSelect(ServerEvent)

Integer weekNum = new Integer(week);

Integer yearNum = new Integer(year);

wdContext.currentContextElement().setWeekNumber(weekNum.toString());

wdContext.currentContextElement().setYear(yearNum.toString());

//@@end

}

On debugging it shows null parameters and week and year has initial values.

Former Member
0 Kudos

Add the following code inside method wdDoModifyView():

if (firstTime)
{
  IWDDateNavigator dn = (IWDDateNavigator) view.getElement("ID-of-datenavigator");
  dn.mappingOfOnWeekSelect().addSourceMapping
  (
    "week", /* name of event parameter */
    "week" /* name of action parameter */
  );
  dn.mappingOfOnWeekSelect().addSourceMapping
  (
    "year", /* name of event parameter */
    "year"  /* name of action parameter */
  );
}

In newer versions there is an interface IWDDateNavigator.IWDOnWeekSelect containing constants for the event parameter names.

Armin

Former Member
0 Kudos

Hi,

I use NW04s and see that IWDDateNavigator.IWDOnWeekSelect is

available. Can somebody tell me how to use it?

Thx in advance.

Kind regards,

Maarten.

Former Member
0 Kudos
if (firstTime)
{
  IWDDateNavigator dn = (IWDDateNavigator) view.getElement("ID-of-datenavigator");
  dn.mappingOfOnWeekSelect().addSourceMapping
  (
    IWDDateNavigator.IWDOnWeekSelect.WEEK, /* name of event parameter */
    "week" /* name of action parameter */
  );
  dn.mappingOfOnWeekSelect().addSourceMapping
  (
    IWDDateNavigator.IWDOnWeekSelect.YEAR, /* name of event parameter */
    "year"  /* name of action parameter */
  );
}

or better: If your version of NWDS supports graphical editing of event parameters, use this.

To do so, open context menu in Outline view on UI element and select entry "Parameter Mapping".

Armin

Message was edited by: Armin Reichert

Former Member
0 Kudos

Thx for the quick reply.

I do have another question. In the IWDDateNavigator.IWDOnWeekSelect there is also a attribute "FIRSTDAY". It returns the firstday of the week. The problem i have, is that it's a string. How do i convert a string to a date?

Thx in advance.

Kind regards,

Maarten

Former Member
0 Kudos

These constants are all of type "String" as they stand for the <b>names </b>of event parameters.

Simply define the <b>action parameter</b> with the correct type and you are done.

Armin

Former Member
0 Kudos

Hi,

Thx for the reply, i tried to do what you told.

I created an Action (onWeekSelect) with 2 parameters (firstday (date) and year (date) ). When i look at the Methods tab, there is a method called onActionWeekSelect this method has the same to parameters.

In my wdDoModifyView i put this code:

	if (firstTime)
	{
		IWDDateNavigator dn = (IWDDateNavigator) view.getElement("DateNavigator");
		dn.mappingOfOnWeekSelect().addSourceMapping
		(
		  IWDDateNavigator.IWDOnWeekSelect.FIRST_DAY, "firstday" 
		);
		dn.mappingOfOnWeekSelect().addSourceMapping
		(
		  IWDDateNavigator.IWDOnWeekSelect.YEAR, "year"
		);
	}

I created 2 context attributes of type Date (Year & Firstdate).

In the onActionWeekSelect i put the following code:

wdContext.currentContextElement().setFirstday(firstday);

wdContext.currentContextElement().setYear(year);

When i run the application and select a week, i get the following error:

java.lang.IllegalArgumentException

at java.sql.Date.valueOf(Date.java:103)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

... 31 more

I think i do something wrong, but have no idea. I hope somebody can help me.

Kind Regards,

Maarten.

Former Member
0 Kudos

You obviously also have context attributes named "Firstday" and "Year". Which type do they have?

Use DDIC type "date" for the context attributes and java.sql.Date for the action parameters.

Armin

Former Member
0 Kudos

Armin,

Thx for your reply.

The attributes "Firstday" and "Year" are of type Date. In the properties tab, i selected "Date" there. Is this the DDIC type? I gave the action parameters the java.sql.Date type but still got the IllegalArgumentExeption. I hope you will still help me.

Thx in advance.

Kind regards,

Maarten.

Former Member
0 Kudos

When exactly do you get the error? On application initialization or after selecting something from the date navigator?

The exception occurs if java.sql.Date.valueOf() is called with null or an invalid string (that has not the form "yyyy-mm-dd").

Armin

Former Member
0 Kudos

Hi Armin,

When i select the week i get the error. I totally have no idea....

Thx in advance.

Kind regards,

Maarten.

Former Member
0 Kudos

Open an OSS message on component BC-WD-JAV-RUN.

Armin

Former Member
0 Kudos

Hi Armin,

Thx for the reply. I will open the OSS tommorow (monday 25 of September).

Thx for all the help.

Kind regards,

Maarten.

Answers (3)

Answers (3)

Former Member
0 Kudos

Thankyou Armin, for explaining me parameter mapping.

Rahul

Former Member
0 Kudos

This is a Tree example of how you map attributes...

public static void wdDoModifyView(IPrivateWoChooseTUDTree wdThis, IPrivateWoChooseTUDTree.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

IWDTreeNodeType treeNode = (IWDTreeNodeType) view.getElement("TreeNodeType1");

treeNode.mappingOfOnAction().addSourceMapping( "path", "element");

//@@end

}

The TreeNode's attribute "path" is mapped to the attribute "element" of the onAction:

public void onActionObjectSelected(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.vattenfall.pm.wdp.IPrivateWoChooseTUDTree.ITUDNotifobjprt_TreeElement element )

{

//@@begin onActionObjectSelected(ServerEvent)

..

//@@end

}

/Mikael

Former Member
0 Kudos

Rahul,

your have to bind the value (selected date) of the DateNavigator to your context. Then you can evalute this value in your action handler method.

Btw, parameters in action handler methods are only useful when you are using dynamically created action. You can pass a value to determine which control has fired the action. In your case you should use the context for data transport.

Sebastian

Message was edited by: Sebastian Voss

Former Member
0 Kudos

<i>Btw, parameters in action handler methods are only useful when you are using dynamically created action. You can pass a value to determine which control has fired the action. In your case you should use the context for data transport</i>

That's not correct. Action handler parameters are also useful for statically created actions. Event parameter values may be transported into action handler parameters using <i>parameter mapping</i>.

Armin