Permalink
Browse files

Validate JSON option input. Fix single-value option display [#200 sta…

…te:resolved]
  • Loading branch information...
gschueler committed Feb 26, 2011
1 parent 4abc44d commit c7805d531f8e210c12c874dc96e7b7ab06d97533
@@ -253,6 +253,33 @@ class ScheduledExecutionController {
err.srcUrl = srcUrl
log.error("getRemoteJSON error: URL ${srcUrl} : ${e.message}");
}
//validate result contents
boolean valid = true;
def validationerrors=[]
if(result && result instanceof Collection){
result.eachWithIndex { entry,i->
if(entry instanceof org.codehaus.groovy.grails.web.json.JSONObject){
if(!entry.name){
validationerrors<<"Item: ${i} has no 'name' entry"
valid=false;
}
if(!entry.value){
validationerrors<<"Item: ${i} has no 'value' entry"
valid = false;
}
}else if(!(entry instanceof String)){
valid = false;
validationerrors << "Item: ${i} expected string or map like {name:\"..\",value:\"..\"}"
}
}
}else{
validationerrors << "Expected top-level list with format: [{name:\"..\",value:\"..\"},..], or ['value','value2',..]"
valid=false
}
if(!valid){
result=null
err.message="Failed parsing remote option values: ${validationerrors.join('\n')}"
}
return render(template: "/framework/optionValuesSelect", model: [optionSelect: opt, values: result, srcUrl: srcUrl, err: err,fieldPrefix:params.fieldPrefix,selectedvalue:params.selectedvalue]);
} else {
return error.call()
@@ -46,8 +46,15 @@
<g:set var="valuesMap" value="${values && values instanceof Map?values:null}"/>
<g:if test="${labelsSet && 1==labelsSet.size() && optionSelect.enforced}">
<g:set var="sellabel" value="${labelsSet.iterator().next()}"/>
<g:set var="selvalue" value="${valuesMap?valuesMap[sellabel]:sellabel}"/>
<g:set var="selentry" value="${labelsSet.iterator().next()}"/>
<g:if test="${selentry instanceof Map}">
<g:set var="sellabel" value="${selentry.name}"/>
<g:set var="selvalue" value="${selentry.value}"/>
</g:if>
<g:else>
<g:set var="sellabel" value="${selentry}"/>
<g:set var="selvalue" value="${valuesMap?valuesMap[sellabel]:sellabel}"/>
</g:else>
<g:hiddenField name="${realFieldName}" value="${selvalue.encodeAsHTML()}"/>
<span class="singlelabel">${sellabel.encodeAsHTML()}</span>
</g:if>
@@ -79,7 +86,7 @@
</g:if>
</g:if>
<g:if test="${err}">
<g:expander key="${rkey}_error_detail" classnames="error label">${err.message}</g:expander>
<g:expander key="${rkey}_error_detail" classnames="error label">${err.message.encodeAsHTML()}</g:expander>
<span class="error note" style="display:none" id="${rkey}_error_detail">
<g:if test="${err.exception}">

0 comments on commit c7805d5

Please sign in to comment.