View Javadoc
1   /*
2    * Copyright 2014 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.web.impl.ui.application.views.pageclicklistener;
20  
21  import java.lang.reflect.InvocationTargetException;
22  
23  import org.apache.commons.beanutils.BeanUtils;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  import com.hack23.cia.model.common.api.ModelObject;
28  
29  /**
30   * The Class PageItemPropertyClickListener.
31   */
32  public final class PageItemPropertyClickListener extends AbstractPageItemRendererClickListener<ModelObject> {
33  
34  	/** The Constant ERROR_GETTING_PAGE_ID. */
35  	private static final String ERROR_GETTING_PAGE_ID = "ErrorGettingPageId";
36  
37  	/** The Constant LOG_MSG_PROBLEM_GETTING_PROPERTY_FROM_OBJECT_EXCEPTION. */
38  	private static final String LOG_MSG_PROBLEM_GETTING_PROPERTY_FROM_OBJECT_EXCEPTION = "Problem getting property {} from object {} exception {}";
39  
40  	/** The Constant serialVersionUID. */
41  	private static final long serialVersionUID = 1L;
42  
43  	/** The Constant LOGGER. */
44  	private static final Logger LOGGER = LoggerFactory
45  			.getLogger(PageItemPropertyClickListener.class);
46  
47  
48  	/** The property. */
49  	private final String property;
50  
51  	/**
52  	 * Instantiates a new page item property click listener.
53  	 *
54  	 * @param page
55  	 *            the page
56  	 * @param property
57  	 *            the property
58  	 */
59  	public PageItemPropertyClickListener(final String page, final String property) {
60  		super(page);
61  		this.property = property;
62  	}
63  
64  	@Override
65  	protected String getPageId(final ModelObject t) {
66  		try {
67  			return BeanUtils.getProperty(t, property);
68  		} catch (IllegalAccessException | InvocationTargetException |
69  	            NoSuchMethodException e) {
70  			LOGGER.warn(LOG_MSG_PROBLEM_GETTING_PROPERTY_FROM_OBJECT_EXCEPTION,property,t,e);
71  			return ERROR_GETTING_PAGE_ID;
72  		}
73  	}
74  
75  }