Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cadastro de Viagens.

  • Loading branch information...
commit 132123f09cc71671d62cf42b9d2f7d371d64bdb3 1 parent 0d31368
@jairoandre authored
View
121 src/java/com/jota/infopesca/bean/GridBean.java
@@ -20,6 +20,21 @@
public abstract String getOutputTextLabel();
+ private GridConfig getAnnotation(String fieldName) {
+ if (fieldName == null || fieldName.isEmpty()) {
+ return null;
+ } else {
+ try {
+ Field field = this.getClass().getDeclaredField(fieldName);
+ GridConfig annotation = field.getAnnotation(GridConfig.class);
+ return annotation;
+ } catch (Exception e) {
+ System.out.println(e.getStackTrace());
+ return null;
+ }
+ }
+ }
+
/**
* Verifica se o campo é do tipo data.
*
@@ -27,17 +42,16 @@
* @return
*/
public boolean isDate(String fieldName) {
- try {
- Field field = this.getClass().getDeclaredField(fieldName);
- GridConfig annotation = field.getAnnotation(GridConfig.class);
+ GridConfig annotation = getAnnotation(fieldName);
+ if (annotation != null) {
return annotation.date();
- } catch (Exception e) {
- System.out.println("Erro :" + e.getMessage());
+ } else {
return false;
}
+
}
-
- public boolean isNotBigDecimal(String fieldName){
+
+ public boolean isNotBigDecimal(String fieldName) {
return !isCurrency(fieldName) && !isWeight(fieldName);
}
@@ -48,31 +62,28 @@ public boolean isNotBigDecimal(String fieldName){
* @return
*/
public boolean isCurrency(String fieldName) {
- try {
- Field field = this.getClass().getDeclaredField(fieldName);
- GridConfig annotation = field.getAnnotation(GridConfig.class);
+ GridConfig annotation = getAnnotation(fieldName);
+ if (annotation != null) {
return annotation.currency();
- } catch (Exception e) {
+ } else {
return false;
}
}
public boolean isWeight(String fieldName) {
- try {
- Field field = this.getClass().getDeclaredField(fieldName);
- GridConfig annotation = field.getAnnotation(GridConfig.class);
+ GridConfig annotation = getAnnotation(fieldName);
+ if (annotation != null) {
return annotation.weight();
- } catch (Exception e) {
+ } else {
return false;
}
}
public boolean isFlag(String fieldName) {
- try {
- Field field = this.getClass().getDeclaredField(fieldName);
- GridConfig annotation = field.getAnnotation(GridConfig.class);
+ GridConfig annotation = getAnnotation(fieldName);
+ if (annotation != null) {
return annotation.flag();
- } catch (Exception e) {
+ } else {
return false;
}
}
@@ -84,12 +95,11 @@ public boolean isText(String fieldName) {
public String getMask(String fieldName) {
if (masks.get(fieldName) == null) {
- try {
- Field field = this.getClass().getDeclaredField(fieldName);
- GridConfig annotation = field.getAnnotation(GridConfig.class);
- masks.put(fieldName, annotation.mask());
- } catch (Exception e) {
- return "";
+ GridConfig annotation = getAnnotation(fieldName);
+ if (annotation != null) {
+ masks.put(fieldName,annotation.mask());
+ } else {
+ masks.put(fieldName,"");
}
}
return masks.get(fieldName);
@@ -97,14 +107,22 @@ public String getMask(String fieldName) {
}
public int getSize(String fieldName) {
- try {
- Field field = this.getClass().getDeclaredField(fieldName);
- GridConfig annotation = field.getAnnotation(GridConfig.class);
+ GridConfig annotation = getAnnotation(fieldName);
+ if (annotation != null) {
return annotation.size();
- } catch (Exception e) {
+ } else {
return 20;
}
}
+
+ public String getLabel(String fieldName) {
+ GridConfig annotation = getAnnotation(fieldName);
+ if (annotation != null) {
+ return annotation.label();
+ } else {
+ return "Não definido";
+ }
+ }
/**
* Verifica se o campo é do tipo data.
@@ -113,21 +131,19 @@ public int getSize(String fieldName) {
* @return
*/
public boolean isRequired(String fieldName) {
- try {
- Field field = this.getClass().getDeclaredField(fieldName);
- GridConfig annotation = field.getAnnotation(GridConfig.class);
+ GridConfig annotation = getAnnotation(fieldName);
+ if (annotation != null) {
return annotation.required();
- } catch (Exception e) {
+ } else {
return false;
}
}
public boolean isEnum(String fieldName) {
- try {
- Field field = this.getClass().getDeclaredField(fieldName);
- GridConfig annotation = field.getAnnotation(GridConfig.class);
+ GridConfig annotation = getAnnotation(fieldName);
+ if (annotation != null) {
return annotation.enumerated();
- } catch (Exception e) {
+ } else {
return false;
}
}
@@ -144,11 +160,10 @@ public boolean isEnum(String fieldName) {
}
public boolean isBean(String fieldName) {
- try {
- Field field = this.getClass().getDeclaredField(fieldName);
- GridConfig annotation = field.getAnnotation(GridConfig.class);
+ GridConfig annotation = getAnnotation(fieldName);
+ if (annotation != null) {
return annotation.listed();
- } catch (Exception e) {
+ } else {
return false;
}
}
@@ -164,13 +179,6 @@ public boolean isBean(String fieldName) {
}
}
- public String getValidationRules(String fieldName) {
- StringBuilder str = new StringBuilder();
- str.append(isRequired(fieldName) ? "required" : "");
- str.append(isDate(fieldName) ? " date" : "");
- return str.toString();
- }
-
public void setParent(Object parent) {
}
@@ -187,7 +195,7 @@ public void setCreationTime(long creationTime) {
@Override
public boolean equals(Object o) {
Class thisClass = this.getClass();
- if(o == null){
+ if (o == null) {
return false;
}
Class otherClass = o.getClass();
@@ -209,19 +217,8 @@ public int hashCode() {
hash += (getId() != null ? getId().hashCode() : creationTime.hashCode());
return hash;
}
-
- public int getHashCode(){
+
+ public int getHashCode() {
return hashCode();
}
-
- public String getLabel(String fieldName){
- try {
- Field field = this.getClass().getDeclaredField(fieldName);
- GridConfig annotation = field.getAnnotation(GridConfig.class);
- return annotation.label();
- } catch (Exception e) {
- return "";
- }
- }
-
}
View
7 web/resources/custom/grid.xhtml
@@ -65,13 +65,14 @@
paginatorAlwaysVisible="false"
paginatorPosition="top"
selection="#{cc.attrs.mb.selectedItens}"
- rowKey="#{obj.hashCode}">
+ rowKey="#{obj.hashCode}"
+ styleClass="table">
<p:ajax event="rowSelect" process="@none" onstart="clickCheck();" />
<p:ajax event="rowUnselect" process="@none" onstart="clickCheck();"/>
- <p:column selectionMode="multiple" style="text-align: center;"/>
+ <p:column id="selector" selectionMode="multiple" style="text-align: center;"/>
<p:columns id="dynaColumns" value="#{cc.attrs.mb.fieldNames}" var="field" columnIndexVar="idx">
<f:facet name="header">
- <p:outputPanel id="headerLabel" style="white-space: nowrap" layout="block">
+ <p:outputPanel id="headerLabel" style="white-space: nowrap; text-align: left;" layout="block">
#{cc.attrs.mb.labels[field]}
</p:outputPanel>
</f:facet>
Please sign in to comment.
Something went wrong with that request. Please try again.