如果您对Spring3-在JSP中访问messages.properties和springboot的jsp怎么访问感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解Spring3-在JSP中访问m
如果您对Spring 3-在JSP中访问messages.properties和springboot的jsp怎么访问感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解Spring 3-在JSP中访问messages.properties的各种细节,并对springboot的jsp怎么访问进行深入的分析,此外还有关于
- Spring 3-在JSP中访问messages.properties(springboot的jsp怎么访问)
读取多个 Properties - asp.net – 使用HttpRequestMessage.Properties传递每个请求的上下文
- com.intellij.lang.properties.PropertiesLanguage的实例源码
- com.intellij.uiDesigner.propertyInspector.properties.BindingProperty的实例源码
Spring 3-在JSP中访问messages.properties(springboot的jsp怎么访问)
我是使用Spring 3的新手,对此已经停留了一段时间。
您知道如何从jsp访问messages.properties。例如,在控制器中,我为模型设置了一个值:
model.setError("user.not.found")
messages.properties:
user.not.found=Sorry, we haven''t been able to found this user
在jsp中,我希望能够
${model.error}
并显示“对不起…”。但是,即使在使用@Valid …,bindingResult然后使用表单时,此方法都可以正常工作,但我始终会得到“
user.not.found”。
谢谢,
答案1
小编典典<spring:message>
从spring
taglib 使用:
<spring:message code = "${model.error}" />
将taglib导入为
<%@ taglib prefix = "spring" uri = "http://www.springframework.org/tags" %>
读取多个 Properties
由于在 spring 的源码中可以看到的是,
String location = element.getAttribute("location");
if (StringUtils.hasLength(location)) {
String[] locations = StringUtils.commaDelimitedListToStringArray(location);
builder.addPropertyValue("locations", locations);
}
因此,在加载 locations 的时候,是以数组的形式加载的。
故在 XML 中配置的时候,可以使用逗号进行分割。
<context:property-placeholder location=
"classpath:jdbc.properties,abc.properties"
/>
asp.net – 使用HttpRequestMessage.Properties传递每个请求的上下文
但是,当我使用ASP.NET Web API Self Host(Beta)package时,我需要创建一个自定义生命周期,以便根据HTTP请求确定这些服务的范围.
如何使用HttpRequestMessage.Properties携带每个请求上下文?
解决方法
public class MyApplication : HttpApplication { protected void Application_Start() { RegisterHttpMessageHandlers(GlobalConfiguration.Configuration); } public void RegisterHttpMessageHandlers(HttpConfiguration config) { config.MessageHandlers.Add(new MyMessageHandler()); } } public static class MyHttpMessageHandlerExtensions { public static class HttpPropertyKey { public static readonly string MyProperty = "MyCompany_MyProperty"; } public static MyContext GetContext(this HttpRequestMessage request) { return (MyContext)request.Properties[HttpPropertyKey.MyProperty ]; } public static void SetContext(this HttpRequestMessage request,MyContext ctx) { request.Properties[HttpPropertyKey.MyProperty] = ctx; } } public class MyMessageHandler : DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,CancellationToken cancellationToken) { request.SetContext(new MyContext(){/*some your data*/}); return base.SendAsync(request,cancellationToken); } } public class MyController: ApiController { public object GetData() { MyContext ctx = this.Request.GetContext(); // the extenstion method is used } }
com.intellij.lang.properties.PropertiesLanguage的实例源码
@Nullable private PsiElement resolvetoCustomSystemProperty(@NotNull String propertyName,@Nullable String propertyValue) { if (propertyValue == null) return null; PsiFile propFile = PsiFileFactory.getInstance(myProject).createFileFromText("SystemProperties.properties",PropertiesLanguage.INSTANCE,propertyName + '=' + propertyValue); return ((PropertiesFile)propFile).getProperties().get(0).getPsiElement(); }
@Nullable private PsiElement resolvetoCustomSystemProperty(@NotNull String propertyName,propertyName + '=' + propertyValue); return ((PropertiesFile)propFile).getProperties().get(0).getPsiElement(); }
protected void prepareTemplate(@NotNull Template template,@NotNull final PsiElement element,String relativePath,@NotNull final PsiFile filetoInsertComment) { final List<String> allFiles = Util.collectFilePaths(element,new Function<PsiFile,String>() { public String fun(@NotNull final PsiFile psiFile) { PsiFile file = psiFile.getViewProvider().getPsi(PropertiesLanguage.INSTANCE); if (!(file instanceof PropertiesFile)) { return null; } final VeLocityPropertiesProvider propertiesProvider = new VeLocityPropertiesProvider((PropertiesFile)file); List<PsiFile> macroLibs = collectReferencedLibFiles(ModuleUtil.findModuleForPsiElement(element),propertiesProvider); for (PsiFile macroLib : macroLibs) { if (!(macroLib instanceof VtlFile) || ((VtlFile)macroLib).getNumberOfMacros(((VtlReferenceExpression)element).getReferenceName()) <= 0) { continue; } VirtualFile vFile = macroLib.getViewProvider().getVirtualFile(); String res = Util.computeFilePath(propertiesProvider,vFile.getPath(),vFile.getName(),filetoInsertComment); if(res != null) return res; } return null; } }); template.addTextSegment("#* @veLocityproperties path="); final Expression pathExpression = new StringCollectionExpression(allFiles); template.addVariable("PATH",pathExpression,true); final String fileRef = relativePath != null ? " file=\"" + relativePath + "\"" : ""; template.addTextSegment(fileRef + " *#\n"); template.addEndVariable(); }
private static List<String> computeFilePaths(final PsiElement element,final PsiFile filetoInsertComment) { final VtlFileReferenceSet refSet = findVtlFileReferenceSet(element); if (refSet == null) { return Collections.emptyList(); } final PsiFile[] referencedFiles = findReferencedFiles(ModuleUtil.findModuleForPsiElement(element),refSet.getLastReference().getCanonicalText()); if (referencedFiles.length == 0) { return Collections.emptyList(); } return collectFilePaths(element,String>() { public String fun(@NotNull final PsiFile psiFile) { PsiFile file = psiFile.getViewProvider().getPsi(PropertiesLanguage.INSTANCE); if (file instanceof PropertiesFile) { PropertiesFile propFile = (PropertiesFile)file; VeLocityPropertiesProvider veLocityProperties = new VeLocityPropertiesProvider(propFile); for (PsiFile referencedFile : referencedFiles) { String referencedFilePath = referencedFile.getViewProvider().getVirtualFile().getPath(); String filePath = computeFilePath(veLocityProperties,referencedFilePath,refSet.getPathString(),filetoInsertComment); if (filePath != null) return filePath; } } return null; } }); }
public PropertiesCompletionContributor() { extend(CompletionType.BASIC,PlatformPatterns.psiElement().withLanguage(PropertiesLanguage.INSTANCE),new PropertiesCompletionProvider()); }
@NotNull public Language getLanguage() { return PropertiesLanguage.INSTANCE; }
public PropertiesCodeStyleSettings(CodeStyleSettings container) { super(PropertiesLanguage.INSTANCE.getID(),container); }
@Nullable @Override public String getConfigurabledisplayName() { return PropertiesLanguage.INSTANCE.getdisplayName(); }
public PropertiesElementType(@NonNls String debugName) { super(debugName,PropertiesLanguage.INSTANCE); }
private static String guessSeparator(final Project project,final VirtualFile file) { Collection<PropertiesFile> files; if (file instanceof ResourceBundleAsVirtualFile) { files = ((ResourceBundleAsVirtualFile)file).getResourceBundle().getPropertiesFiles(project); } else { PsiManager psiManager = PsiManager.getInstance(project); final FileViewProvider provider = psiManager.findViewProvider(file); files = new SmartList<PropertiesFile>(); if (provider != null) { ContainerUtil.addIfNotNull((PropertiesFile)provider.getPsi(PropertiesLanguage.INSTANCE),files); } } final TIntLongHashMap charCounts = new TIntLongHashMap(); for (PropertiesFile propertiesFile : files) { if (propertiesFile == null) continue; List<IProperty> properties = propertiesFile.getProperties(); for (IProperty property : properties) { String key = property.getUnescapedKey(); if (key == null) continue; for (int i =0; i<key.length(); i++) { char c = key.charat(i); if (!Character.isLetterOrDigit(c)) { charCounts.put(c,charCounts.get(c) + 1); } } } } final char[] mostProbableChar = new char[]{'.'}; charCounts.forEachKey(new TIntProcedure() { long count = -1; public boolean execute(int ch) { long charCount = charCounts.get(ch); if (charCount > count) { count = charCount; mostProbableChar[0] = (char)ch; } return true; } }); if (mostProbableChar[0] == 0) { mostProbableChar[0] = '.'; } return Character.toString(mostProbableChar[0]); }
public PropertiesFileImpl(FileViewProvider viewProvider) { super(viewProvider,PropertiesLanguage.INSTANCE); }
private PlayJavaConfFileType() { super(PropertiesLanguage.INSTANCE); }
com.intellij.uiDesigner.propertyInspector.properties.BindingProperty的实例源码
private static void adjustDuplicates(final Map<RadComponent,RadComponent> duplicates) { for(RadComponent c: duplicates.keySet()) { RadComponent copy = duplicates.get(c); if (c.getBinding() != null) { String binding = BindingProperty.getDefaultBinding(copy); new BindingProperty(c.getProject()).setValueEx(copy,binding); copy.setDefaultBinding(true); } for(IProperty prop: copy.getModifiedProperties()) { if (prop instanceof IntroComponentProperty) { final IntroComponentProperty componentProperty = (IntroComponentProperty)prop; String copyValue = componentProperty.getValue(copy); for(RadComponent original: duplicates.keySet()) { if (original.getId().equals(copyValue)) { componentProperty.setValueEx(copy,duplicates.get(original).getId()); } } } } } }
private static void adjustDuplicates(final Map<RadComponent,duplicates.get(original).getId()); } } } } } }
private static void adjustDuplicates(final Map<RadComponent,duplicates.get(original).getId()); } } } } } }
private static boolean canCreateListener(final ArrayList<RadComponent> selection) { if (selection.size() == 0) return false; final RadRootContainer root = (RadRootContainer)FormEditingUtil.getRoot(selection.get(0)); if (root.getClasstoBind() == null) return false; String componentClass = selection.get(0).getComponentClassName(); for(RadComponent c: selection) { if (!c.getComponentClassName().equals(componentClass) || c.getBinding() == null) return false; if (BindingProperty.findBoundField(root,c.getBinding()) == null) return false; } return true; }
private static void updateBoundFieldType(final GuiEditor editor,final RadComponent oldComponent,final ComponentItem targetItem) { PsiField oldBoundField = BindingProperty.findBoundField(editor.getRootContainer(),oldComponent.getBinding()); if (oldBoundField != null) { final PsiElementFactory factory = JavaPsiFacade.getInstance(editor.getProject()).getElementFactory(); try { PsiType componentType = factory.createTypeFromText(targetItem.getClassName().replace('$','.'),null); new ChangeFieldTypeFix(editor,oldBoundField,componentType).run(); } catch (IncorrectOperationException e) { LOG.error(e); } } }
private void saveButtonGroupIsBound() { if (myGroup.isBound() != myBindToFieldCheckBox.isSelected()) { myGroup.setBound(myBindToFieldCheckBox.isSelected()); notifyListeners(new ChangeEvent(myGroup)); if (myGroup.isBound()) { BindingProperty.updateBoundFieldName(myRootContainer,null,myGroup.getName(),ButtonGroup.class.getName()); } else { BindingProperty.checkRemoveUnusedField(myRootContainer,FormEditingUtil.getNextSaveUndoGroupId(myRootContainer.getProject())); } } }
private void saveButtonGroupName() { String oldName = myGroup.getName(); String newName = myNameTextField.getText(); if (!oldName.equals(newName)) { myGroup.setName(newName); notifyListeners(new ChangeEvent(myGroup)); if (myGroup.isBound()) { BindingProperty.updateBoundFieldName(myRootContainer,oldName,newName,ButtonGroup.class.getName()); } } }
private static boolean canCreateListener(final ArrayList<RadComponent> selection) { if (selection.size() == 0) return false; final RadRootContainer root = (RadRootContainer)FormEditingUtil.getRoot(selection.get(0)); if (root.getClasstoBind() == null) return false; String componentClass = selection.get(0).getComponentClassName(); for(RadComponent c: selection) { if (!c.getComponentClassName().equals(componentClass) || c.getBinding() == null) return false; if (BindingProperty.findBoundField(root,c.getBinding()) == null) return false; } return true; }
private static void updateBoundFieldType(final GuiEditor editor,componentType).run(); } catch (IncorrectOperationException e) { LOG.error(e); } } }
private void saveButtonGroupIsBound() { if (myGroup.isBound() != myBindToFieldCheckBox.isSelected()) { myGroup.setBound(myBindToFieldCheckBox.isSelected()); notifyListeners(new ChangeEvent(myGroup)); if (myGroup.isBound()) { BindingProperty.updateBoundFieldName(myRootContainer,FormEditingUtil.getNextSaveUndoGroupId(myRootContainer.getProject())); } } }
private void saveButtonGroupName() { String oldName = myGroup.getName(); String newName = myNameTextField.getText(); if (!oldName.equals(newName)) { myGroup.setName(newName); notifyListeners(new ChangeEvent(myGroup)); if (myGroup.isBound()) { BindingProperty.updateBoundFieldName(myRootContainer,ButtonGroup.class.getName()); } } }
private static boolean canCreateListener(final ArrayList<RadComponent> selection) { if (selection.size() == 0) return false; final RadRootContainer root = (RadRootContainer)FormEditingUtil.getRoot(selection.get(0)); if (root.getClasstoBind() == null) return false; String componentClass = selection.get(0).getComponentClassName(); for(RadComponent c: selection) { if (!c.getComponentClassName().equals(componentClass) || c.getBinding() == null) return false; if (BindingProperty.findBoundField(root,c.getBinding()) == null) return false; } return true; }
private static void updateBoundFieldType(final GuiEditor editor,componentType).run(); } catch (IncorrectOperationException e) { LOG.error(e); } } }
private void saveButtonGroupIsBound() { if (myGroup.isBound() != myBindToFieldCheckBox.isSelected()) { myGroup.setBound(myBindToFieldCheckBox.isSelected()); notifyListeners(new ChangeEvent(myGroup)); if (myGroup.isBound()) { BindingProperty.updateBoundFieldName(myRootContainer,FormEditingUtil.getNextSaveUndoGroupId(myRootContainer.getProject())); } } }
private void saveButtonGroupName() { String oldName = myGroup.getName(); String newName = myNameTextField.getText(); if (!oldName.equals(newName)) { myGroup.setName(newName); notifyListeners(new ChangeEvent(myGroup)); if (myGroup.isBound()) { BindingProperty.updateBoundFieldName(myRootContainer,ButtonGroup.class.getName()); } } }
private static String[] getFieldNames(final RadComponent component,final String currentName) { final ArrayList<String> result = new ArrayList<String>(); if (currentName != null){ result.add(currentName); } final IRootContainer root = FormEditingUtil.getRoot(component); final String className = root.getClasstoBind(); if (className == null) { return ArrayUtil.toStringArray(result); } final PsiClass aClass = FormEditingUtil.findClasstoBind(component.getModule(),className); if (aClass == null) { return ArrayUtil.toStringArray(result); } final PsiField[] fields = aClass.getFields(); for (final PsiField field : fields) { if (field.hasModifierProperty(PsiModifier.STATIC)) { continue; } final String fieldName = field.getName(); if (Comparing.equal(currentName,fieldName)) { continue; } if (!FormEditingUtil.isBindingUnique(component,fieldName,root)) { continue; } final String componentClassName; if (component instanceof RadErrorComponent) { componentClassName = component.getComponentClassName(); } else if (component instanceof RadHSpacer || component instanceof RadVSpacer) { componentClassName = Spacer.class.getName(); } else { componentClassName = component.getComponentClass().getName(); } final PsiType componentType; try { componentType = JavaPsiFacade.getInstance(component.getProject()).getElementFactory().createTypeFromText(componentClassName,null); } catch (IncorrectOperationException e) { continue; } final PsiType fieldType = field.getType(); if (!fieldType.isAssignableFrom(componentType)) { continue; } result.add(fieldName); } String text = ForminspectionUtil.getText(component.getModule(),component); if (text != null) { String binding = BindingProperty.suggestBindingFromText(component,text); if (binding != null && !result.contains(binding)) { result.add(binding); } } final String[] names = ArrayUtil.toStringArray(result); Arrays.sort(names); return names; }
private static boolean morphComponent(final GuiEditor editor,ComponentItem targetItem) { targetItem = InsertComponentProcessor.replaceAnyComponentItem(editor,targetItem,"Morph to Non-Palette Component"); if (targetItem == null) { return false; } final RadComponent newComponent = InsertComponentProcessor.createInsertedComponent(editor,targetItem); if (newComponent == null) return false; newComponent.setBinding(oldComponent.getBinding()); newComponent.setCustomLayoutConstraints(oldComponent.getCustomLayoutConstraints()); newComponent.getConstraints().restore(oldComponent.getConstraints()); updateBoundFieldType(editor,oldComponent,targetItem); final IProperty[] oldProperties = oldComponent.getModifiedProperties(); final Palette palette = Palette.getInstance(editor.getProject()); for(IProperty prop: oldProperties) { IntrospectedProperty newProp = palette.getIntrospectedProperty(newComponent,prop.getName()); if (newProp == null || !prop.getClass().equals(newProp.getClass())) continue; Object oldValue = prop.getPropertyValue(oldComponent); try { //noinspection unchecked newProp.setValue(newComponent,oldValue); } catch (Exception e) { // ignore } } retargetComponentProperties(editor,newComponent); final RadContainer parent = oldComponent.getParent(); int index = parent.indexOfComponent(oldComponent); parent.removeComponent(oldComponent); parent.addComponent(newComponent,index); newComponent.setSelected(true); if (oldComponent.isDefaultBinding()) { final String text = ForminspectionUtil.getText(newComponent.getModule(),newComponent); if (text != null) { String binding = BindingProperty.suggestBindingFromText(newComponent,text); if (binding != null) { new BindingProperty(newComponent.getProject()).setValueEx(newComponent,binding); } } newComponent.setDefaultBinding(true); } return true; }
private static String[] getFieldNames(final RadComponent component,text); if (binding != null && !result.contains(binding)) { result.add(binding); } } final String[] names = ArrayUtil.toStringArray(result); Arrays.sort(names); return names; }
private static boolean morphComponent(final GuiEditor editor,binding); } } newComponent.setDefaultBinding(true); } return true; }
private static boolean morphComponent(final GuiEditor editor,binding); } } newComponent.setDefaultBinding(true); } return true; }
关于Spring 3-在JSP中访问messages.properties和springboot的jsp怎么访问的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于
本文标签: