View Javadoc

1   /*
2    * Copyright 2004-2005 Andreas Andreou
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  package net.sf.tapfx.components.table;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  
21  import org.apache.tapestry.IMarkupWriter;
22  import org.apache.tapestry.IRequestCycle;
23  import org.apache.tapestry.contrib.table.components.Table;
24  import org.apache.tapestry.event.PageDetachListener;
25  import org.apache.tapestry.event.PageEvent;
26  import org.apache.tapestry.form.Form;
27  import org.apache.tapestry.form.TextField;
28  import org.apache.tapestry.html.Body;
29  
30  /***
31   * @author andyhot
32   */
33  public abstract class FilteringTable extends Table implements PageDetachListener
34  {
35      private static final Log log = LogFactory.getLog(FilteringTable.class);
36      // tapestry injected properties
37      public abstract String getFilter();
38      public abstract void setFilterChanged(boolean value);
39      public abstract boolean isFilterChanged();
40      public abstract boolean getUseFilter();
41  
42      protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
43      {
44          if (getUseFilter())
45          {
46  	        TextField textField = (TextField) this.getComponent("txfFilter");
47  	        Form form = (Form) this.getComponent("frmFilter");
48  	        //if (isFilterChanged())
49  	        if (textField.getName()!=null)
50  	        {
51  	            //log.info("Filter was changed...");
52  	            String script = "document." + form.getName() + "."
53  	            	+ textField.getName() + ".focus();";
54  	
55  	            Body body = Body.get(cycle);
56  	            if (body != null)
57  	                body.addInitializationScript(script);
58  	            else
59  	                log.info("Body is null!");
60  	        }
61          }
62          super.renderComponent(writer, cycle);
63      }
64  
65      public void pageDetached(PageEvent event)
66      {
67          /*setFilterChanged(false);
68          log.info("Filter -> FALSE");
69          log.info("Value: " + isFilterChanged());*/
70      }
71  
72      public void onFilterSubmit(IRequestCycle cycle)
73      {
74          /*setFilterChanged(true);
75          log.info("Filter -> TRUE");*/
76      }
77  }