Skip to Content
author's profile photo Former Member
Former Member

EP KM Flex UI: Filtering your resources - catch dropdownlist selected value

With great intreset I've read and adapted following blog :EP" target="_blank">https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2102">EP KM Flex UI: Filtering your resources.

I've made some adjustments in the FilterControl.java file so that instead of a text input field, a dropdownlist is shown.

Method <i>public Component render()</i> has been modified. <i>new DropdownListBox</i> is the most important. A label has been assigned by method <i>label.setLabelFor(filterDropDownList)</i>

	public Component render()
		throws WdfException
	{
		GridLayout masterLayout = new GridLayout();

		DropdownListBox filterDropDownList = new DropdownListBox(WdfEventDispatcher.dispatchableControlID(this, "onSetFilters", "_filterset")); 
		filterDropDownList.setWidth("90");
		filterDropDownList.addItem("AL", "All");
		filterDropDownList.addItem("RL","Released");
		filterDropDownList.addItem("WT","Waiting");
		filterDropDownList.addItem("AR","Archived");
		filterDropDownList.setOnSelect(WdfEventDispatcher.DISPATCH_EVENT);
		filterDropDownList.setTooltip("Approval state");
		filterDropDownList.setSelection("AL");

		Label label = new Label("approval_label");
		label.setText("Select approval state");
		label.setDesign(TextViewDesign.LABEL);
		label.setLabelFor(filterDropDownList);

		GridLayoutCell cellLabel = new GridLayoutCell(label);
		GridLayoutCell cellDropDown = new GridLayoutCell(filterDropDownList);

		GridLayout filterLayout = new GridLayout();

		filterLayout.addCell(1, 1, cellLabel);
		filterLayout.addCell(1, 2, cellDropDown);

		filterLayout.setCellSpacing(2);
		masterLayout.addComponent(1, 1, filterLayout);
    	
		try
		{
			if(proxy.isDebugEnabled())
				writeDebugInformation();
			if(getTypedResourceList() == null)
				getCollectionRenderer().setParentCollection((ICollection)getResource());
			else
				getCollectionRenderer().setTypedResourceList(getTypedResourceList());
                
			masterLayout.addComponent(2, 1, this.getCollectionRenderer().renderAll());    
			return masterLayout;
		}
		catch(Exception e)
		{
			throw new WdfException(e);
		}
	}

Once a selection is made, the selected value needs to be retrieved. This is done in method <i>public WdfEvent onSetFilters(Event event)</i>. Using <i>.getComponentIdForLabel("approval_label");</i> I want to retrieve the ID of the dropdownlist, to use getDataForComponentId(componentIdForLabel); to get the selected value. Unfortunately, this always gives a <b>null pointer exception</b>.

	public WdfEvent onSetFilters(Event event) throws WdfException {
		
		//obtain string that list should be filtered upon
		//alternative  that should also work this.proxy.getDynamicPage().getPageContext().getDataForComponentId()  

		String componentIdForLabel = this.getControlContext().getParentComponent().getDynPage().getPageContext().getComponentIdForLabel("approval_label");
		log.errorT("Kevin : componentIdForLabel = " + componentIdForLabel);

		AbstractDataType filterString = this.getControlContext().getParentComponent().getDynPage().getPageContext().getDataForComponentId(componentIdForLabel);
		String searchString = filterString.getValueAsString();

		IParameterName paramName = ParametersFactory.getParameterName("FILTERKEY");
		
		IParameterMap paramMap = ParametersFactory.newParameters();
		
		IParameterName paramNames[] = {paramName};   
		IParameters parameters = (IParameters) paramMap.getParameters(paramNames);
		//set filter parameters this will be passed into the Resource filter 
		parameters.setParameter(paramName,searchString);
		
		IRendererStatus ris = null;
		
		try {
			//IRendererStatus object has most of the list details
			ris = ((IRendererStatus) this.proxy.getControlStatus(this.getCollectionRenderer().getID()));
			if(ris != null){
				//filter parameters set 
				ris.setFilterParameters(parameters);
				//parent collection defined which is the list that will be passed into Resource Filter 
				//this will also invoke an actual filtering
				ris.setParent((ICollection)this.getResource());
			}
			
		} catch (WcmException e2) {
			e2.printStackTrace();
		}
		 //filtering complete 
		return null;
	}

Anybody has an idea on how to retrieve the selected value?

Thanks for the help,

Kevin

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Feb 02, 2012 at 09:49 AM

    Hello Kevin,

    Could u please let us know if you solved this problem

    Thanks

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.