<%@ jet package="cruise.ui.jsf.templates.impl" imports="java.util.* cruise.model.abstractObjects.BackingObject cruise.umple.compiler.* cruise.ui.jsf.* " class="Validation" skeleton="../skeleton/IGenerator.skeleton" %> <% BackingObject bckObject = (BackingObject) argument; List constructorOneAsociations= bckObject.getConstructorOneAsociations(); List multipleZeroManyToOptionalAssociations=bckObject.getZeroManyToOptionalAssociations(); List multipleNManyToOptionalAssociations=bckObject.getNManyToOptionalAssociations(); List multipleManyToOneAsociations =bckObject.getManyToOneAssociations(); List mandatoryToSingletonAssociations=bckObject.getMandatoryToSingletonAssociations(); List optionalToSingletonAssociations=bckObject.getOptionalToSingletonAssociations(); %> public boolean validate(){ boolean success=true; <% for (AssociationVariable assocVar: constructorOneAsociations) { %> if(getSelected<%=assocVar.getUpperCaseName()%>()==null){ FacesMessage fm = new FacesMessage( resourceBundle.getString("<%=assocVar.getUpperCaseName()%>")+" cannot be null!"); fm.setSeverity(FacesMessage.SEVERITY_ERROR); FacesContext.getCurrentInstance().addMessage(null, fm); success=false; } <% } %> <% for (AssociationVariable assocVar: mandatoryToSingletonAssociations) { %> if(getSelected<%=assocVar.getUpperCaseName()%>()==null){ FacesMessage fm = new FacesMessage( resourceBundle.getString("<%=assocVar.getUpperCaseName()%>")+" cannot be null!"); fm.setSeverity(FacesMessage.SEVERITY_ERROR); FacesContext.getCurrentInstance().addMessage(null, fm); success=false; } <% } %> <% for (AssociationVariable assocVar: multipleNManyToOptionalAssociations) { boolean addtoValidation=false; String ifClause="getSelected"+assocVar.getUpperCaseName()+"List()==null ||"; String ifMinBound=""; String ifMaxBound=""; String msg="resourceBundle.getString(\"" + bckObject.getClassName()+"ClassName\")+\" \" "; if (assocVar.getMinBound() > 0){ ifMinBound ="getSelected"+assocVar.getUpperCaseName()+"List().size()<"+assocVar.getMinBound(); msg=msg +"+\"should have at least "+assocVar.getMinBound() + " \"+" + "resourceBundle.getString(\"" + assocVar.getUpperCaseName()+"\")" + "+\"(s)" ; addtoValidation=true; } if (assocVar.getMaxBound() > 0){ ifMaxBound =((ifMinBound.length()>0)?" || ":"")+ " getSelected"+assocVar.getUpperCaseName()+"List().size()>"+assocVar.getMaxBound(); msg=msg+((ifMinBound.length()>0)?" and it ":"+\"")+ "should have up to "+assocVar.getMaxBound() + " \"+" + "resourceBundle.getString(\"" + assocVar.getUpperCaseName()+"\")" + "+\"(s)" ; addtoValidation=true; } if(addtoValidation){ ifClause=ifClause+ ifMinBound+ ifMaxBound; %> if(<%=ifClause%> ) { FacesMessage fm = new FacesMessage(<%=msg%>"); fm.setSeverity(FacesMessage.SEVERITY_ERROR); FacesContext.getCurrentInstance().addMessage(null, fm); success=false; } <%} } %> <% for (AssociationVariable assocVar: multipleZeroManyToOptionalAssociations) { boolean addtoValidation=false; String ifClause="getSelected"+assocVar.getUpperCaseName()+"List()!=null &&"; String ifMaxBound=""; String msg="resourceBundle.getString(\"" + bckObject.getClassName()+"ClassName\")+\" \" "; if (assocVar.getMaxBound() > 0){ ifMaxBound =" getSelected"+assocVar.getUpperCaseName()+"List().size()>"+assocVar.getMaxBound(); msg=msg+ "+\""+ "should have up to "+assocVar.getMaxBound() + " \"+" + "resourceBundle.getString(\"" + assocVar.getUpperCaseName()+"\")" + "+\"(s)" ; addtoValidation=true; } if(addtoValidation){ ifClause=ifClause+ ifMaxBound; %> if(<%=ifClause%> ) { FacesMessage fm = new FacesMessage(<%=msg%>"); fm.setSeverity(FacesMessage.SEVERITY_ERROR); FacesContext.getCurrentInstance().addMessage(null, fm); success=false; } <%} } %> return success; }