Skip to content

Commit

Permalink
#341 Correctly translate errors into labels
Browse files Browse the repository at this point in the history
  • Loading branch information
doolse committed Oct 10, 2017
1 parent 050a6de commit 94a9677
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<div class="mimeEditPage">
<#assign title><#if m.editId==0>add<#else>edit</#if>.pagetitle</#assign>
<h2>${b.key(title)}</h2>
<#if m.errorKey??>
<@setting label="" error=b.key("error." + m.errorKey) />
<#if m.errorLabel??>
<@setting label="" error=m.errorLabel />
</#if>
<#list s.tabs.tabModel.getVisibleTabs(_info) as tab>
<@render tab.renderer/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.tle.web.mimetypes.model;

import com.tle.web.sections.annotations.Bookmarked;
import com.tle.web.sections.render.Label;

/*
* @author aholland
Expand All @@ -27,14 +28,14 @@ public class MimeTypesEditModel
private long editId;

// Render time
private String errorKey;
private Label errorKey;

public String getErrorKey()
public Label getErrorLabel()
{
return errorKey;
}

public void setErrorKey(String errorKey)
public void setErrorLabel(Label errorKey)
{
this.errorKey = errorKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public class MimeDetailsSection extends AbstractPrototypeSection<MimeDetailsSect
HtmlRenderer
{
@PlugKey("error.mimetype.empty")
private static Label ERROR_MIME_TYPE_EMPTY;
private static String ERROR_MIME_TYPE_EMPTY;
@PlugKey("error.extensions.length")
private static Label ERROR_EXTENSIONS_LENGTH;
private static String ERROR_EXTENSIONS_LENGTH;

@ViewFactory
private FreemarkerFactory viewFactory;
Expand Down Expand Up @@ -142,7 +142,7 @@ public void saveEntry(SectionInfo info, MimeEntry entry)
{
if( Check.isEmpty(type.getValue(info)) )
{
throw new InvalidDataException(new ValidationError("type", ERROR_MIME_TYPE_EMPTY.getText()));
throw new InvalidDataException(new ValidationError("type", null, ERROR_MIME_TYPE_EMPTY));
}
entry.setDescription(description.getValue(info));
entry.setType(type.getValue(info));
Expand All @@ -152,7 +152,7 @@ public void saveEntry(SectionInfo info, MimeEntry entry)
{
if( ext.length() >= 20 )
{
throw new InvalidDataException(new ValidationError("extensions", ERROR_EXTENSIONS_LENGTH.getText()));
throw new InvalidDataException(new ValidationError("extensions", null, ERROR_EXTENSIONS_LENGTH));
}
}
entry.setExtensions(extensions.getValues(info));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.tle.beans.mime.MimeEntry;
import com.tle.common.NameValue;
import com.tle.common.beans.exception.InvalidDataException;
import com.tle.common.beans.exception.ValidationError;
import com.tle.core.i18n.BundleNameValue;
import com.tle.core.institution.InstitutionService;
import com.tle.core.mimetypes.MimeTypeService;
Expand Down Expand Up @@ -51,6 +52,7 @@
import com.tle.web.sections.render.GenericTemplateResult;
import com.tle.web.sections.render.HtmlRenderer;
import com.tle.web.sections.render.Label;
import com.tle.web.sections.result.util.KeyLabel;
import com.tle.web.sections.standard.Button;
import com.tle.web.sections.standard.TabLayout;
import com.tle.web.sections.standard.annotations.Component;
Expand Down Expand Up @@ -147,7 +149,8 @@ public void editMimeEntry(MimeEntry entry)
catch( InvalidDataException ve )
{
info.preventGET();
model.setErrorKey(ve.getMessage());
ValidationError firstError = ve.getErrors().get(0);
model.setErrorLabel(new KeyLabel(firstError.getKey(), firstError.getMessage()));
}
}

Expand Down

0 comments on commit 94a9677

Please sign in to comment.