1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.component.html.ext;
20
21 import javax.faces.component.UINamingContainer;
22 import javax.faces.component.UIPanel;
23 import javax.faces.context.FacesContext;
24
25 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
26 import org.apache.myfaces.component.NewspaperTable;
27
28
29
30
31
32
33
34 @JSFComponent
35 public class HtmlTableRow extends UIPanel
36 {
37 public static final String COMPONENT_FAMILY = "org.apache.myfaces.HtmlTableRow";
38 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlTableRow";
39 public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.HtmlTableRow";
40
41 private String _alternateClientId;
42
43 public HtmlTableRow()
44 {
45 setRendererType(DEFAULT_RENDERER_TYPE);
46 }
47
48 @Override
49 public String getClientId(FacesContext context)
50 {
51 String inheritedClientId = super.getClientId(context);
52 if (getParent() instanceof HtmlDataTable)
53 {
54 HtmlDataTable dataTable = (HtmlDataTable) getParent();
55 if (dataTable.getNewspaperColumns() > 1)
56 {
57 if (_alternateClientId == null)
58 {
59 char separator = UINamingContainer.getSeparatorChar(context);
60 _alternateClientId = dataTable.getClientId() + separator +
61 getNewspaperRowIndex(dataTable) + separator + getId();
62 return _alternateClientId;
63 }
64 else
65 {
66 return _alternateClientId;
67 }
68 }
69 else
70 {
71 return inheritedClientId;
72 }
73 }
74 else
75 {
76 return inheritedClientId;
77 }
78 }
79
80 public int getNewspaperRowIndex(HtmlDataTable dataTable)
81 {
82 int rowCount = dataTable.getRowCount();
83
84 int first = dataTable.getFirst();
85 int rows = dataTable.getRows();
86 int last;
87
88 if (rows <= 0)
89 {
90 last = rowCount;
91 }
92 else
93 {
94 last = first + rows;
95 if (last > rowCount)
96 {
97 last = rowCount;
98 }
99 }
100
101 int newspaperColumns = dataTable.getNewspaperColumns();
102 int newspaperRows;
103 if((last - first) % newspaperColumns == 0)
104 newspaperRows = (last - first) / newspaperColumns;
105 else newspaperRows = ((last - first) / newspaperColumns) + 1;
106
107 int currentRow = dataTable.getRowIndex();
108 int nr = NewspaperTable.NEWSPAPER_HORIZONTAL_ORIENTATION.equals(dataTable.getNewspaperOrientation()) ?
109 (currentRow-first)/newspaperColumns :
110 (currentRow-first) % newspaperRows;
111
112 return nr;
113 }
114
115 @Override
116 public void setId(String id)
117 {
118 super.setId(id);
119 _alternateClientId = null;
120 }
121
122 public String getFamily()
123 {
124 return COMPONENT_FAMILY;
125 }
126 }