我正在填充<p:selectOneMenu/>
数据库,如下所示.
<p:selectOneMenu id="cmbCountry"
value="#{bean.country}"
required="true"
converter="#{countryConverter}">
<f:selectItem itemLabel="Select" itemValue="#{null}"/>
<f:selectItems var="country"
value="#{bean.countries}"
itemLabel="#{country.countryName}"
itemValue="#{country}"/>
<p:ajax update="anotherMenu" listener=/>
</p:selectOneMenu>
<p:message for="cmbCountry"/>
Run Code Online (Sandbox Code Playgroud)
加载此页面时,默认选择的选项是,
<f:selectItem itemLabel="Select" itemValue="#{null}"/>
Run Code Online (Sandbox Code Playgroud)
转换器:
@ManagedBean
@ApplicationScoped
public final class CountryConverter implements Converter {
@EJB
private final Service service = null;
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
try {
//Returns the item label of <f:selectItem>
System.out.println("value = " + value);
if (!StringUtils.isNotBlank(value)) {
return null;
} // Makes no difference, if removed.
long parsedValue …
Run Code Online (Sandbox Code Playgroud) 我在Spring应用程序中遵循此方案.
我在另一个问题中询问,在填充请求的参数之前,准备对象的最佳方法是什么.答案是最好的方法是使用转换服务,而不是在@ModelAtribute注释方法中或在initBinder中使用编辑器.
所以我试图使用转换器,但我没有找到类似的例子,我有点卡住了.我编写了如下代码:在init binder中我注册了转换服务.因此,在填充User对象上的值之前,会调用convert()方法从数据库加载对象.问题是这个配置不起作用,因为它将对象用户的id(用户名字段)转换为Object用户,但是它尝试用对象创建一个setUsername(),所以我得到一个"java.lang" .IllegalArgumentException:参数类型不匹配".
任何人都可以给我一个线索或使用ConversionService获得所需行为的方式的示例吗?
谢谢.
@Autowired
private ConversionService conversionService;
@InitBinder("user")
public void initBinder(@RequestParam("username")String username, WebDataBinder binder){
binder.setConversionService(conversionService);
}
@RequestMapping(value="/user/save", method=RequestMethod.POST)
public String save(@ModelAttribute("user") User user, Model model) {
...
}
Run Code Online (Sandbox Code Playgroud)
有类似的东西:
@Component
public class UserConversionService implements ConversionService{
...
@Override
public Object convert(Object name, TypeDescriptor arg1, TypeDescriptor arg2) {
return userService.find((String)name);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个拾色器工具,对于HSL滑块,我需要能够将RGB转换为HSL.当我搜索SO以进行转换的方法时,我发现这个问题HSL到RGB颜色转换.
虽然它提供了从RGB转换到HSL的功能,但我没有看到计算中实际发生的事情的解释.为了更好地理解它,我在维基百科上阅读了HSL和HSV.
后来,我使用"HSL和HSV"页面中的计算重写了"HSL到RGB颜色转换"的功能.
如果R是最大值,我会坚持计算色调.请参阅"HSL和HSV"页面中的计算:
这是来自荷兰语的另一个维基页面:
这是从"HSL到RGB颜色转换" 的答案:
case r: h = (g - b) / d + (g < b ? 6 : 0); break; // d = max-min = c
Run Code Online (Sandbox Code Playgroud)
我已经用几个RGB值测试了所有三个,它们似乎产生了类似的(如果不是精确的)结果.我想知道的是他们表演同样的事情吗?对于某些特定的RGB值,我会得到不同的结果吗?我应该使用哪一个?
hue = (g - b) / c; // dutch wiki
hue = ((g - b) / c) % 6; // eng wiki
hue = (g - b) / c + (g < b ? 6 : 0); // SO answer …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将虚拟键码映射到char.
我的代码使用ProcessCmdKey来监听WM_KEYDOWN,这使我可以访问按下的键.例如,当我按单引号时,我得到一个222的密钥,我希望它映射到keychar 39代表...你猜对了......单引号.
我的开发上下文是: - .net Framework 2.0 - UserControl放置在很多地方
你知道问题的答案吗?
我使用带有AJAX REST API的AngularJS/jQuery/Bootstrap构建HTML应用程序.
是否可以为Windows操作系统创建可执行文件/安装程序?
没有任何第三方软件,它应该看起来像本机应用程序,但HTML.
例如,Slack messenger有web/mac/windows版本,它们看起来相同.
有任何想法吗?
// UPD
我可能需要一个包装器(webview),但我需要EcmaScript5/CSS3的所有功能.
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [referencedata.ABDeadlineType] to type [referencedata.DeadlineType]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:324)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:206)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:187)
at org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.convert(ResultProcessor.java:256)
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter$1.convert(ResultProcessor.java:201)
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter.convert(ResultProcessor.java:212)
at org.springframework.data.repository.query.ResultProcessor.processResult(ResultProcessor.java:149)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:121)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:106)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:483)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy143.findAllSummarizedBy(Unknown Source)
at
Run Code Online (Sandbox Code Playgroud)
DeadlineType
@Data
public class DeadlineType extends DefaultIdAndText …
Run Code Online (Sandbox Code Playgroud) 我需要将HTML文档转换为有效的XML,最好是XHTML.最好的方法是什么?有没有人知道工具包/库/样本/ ......什么能帮助我完成任务?
为了更清楚一点,我的应用程序必须在运行时自动进行转换.我不寻找可以帮助我手动将某些页面移动到XHTML的工具.
如何将没有分隔符的String转换为ArrayList<Character>
.
我的字符串是这样的:
String str = "abcd..."
Run Code Online (Sandbox Code Playgroud)
我知道这样做的一种方法是将String转换为char[]
first,然后将其转换char []
为ArrayList <Character>
.
有没有更好的方法来做到这一点?喜欢直接转换?考虑时间和性能,因为我正在使用大型数据库进行编码.
我有一个实现的类,IValueConverter
旨在用于将布尔值转换为Brush
.我正在尝试使用IValueConverter
绑定到Control 的BorderBrush
属性Border
:
<Window x:Class="DomPicker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:CustomControls;assembly=CustomControls"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
DataContext="{Binding Path=Domains, RelativeSource={RelativeSource Self}}"
Height="350"
Title="My Title"
Width="525">
<cc:CarSystemWindow.Resources>
<cc:BooleanToBrushConverter x:Key="BrushConverter" True="Black" False="Transparent" />
<DataTemplate x:Name="DomainTemplate" DataType="DomainViewModel">
<Border BorderBrush="{Binding Converter=BrushConverter, Path=IsSelected}">
. . .
</Border>
</DataTemplate>
</cc:CarSystemWindow.Resources>
<Grid>
<ListBox . . . Name="DomainListBox" />
</Grid>
<Window>
Run Code Online (Sandbox Code Playgroud)
以下是代码中的Domains属性的代码:
public static readonly DependencyProperty DomainsProperty =
DependencyProperty.Register( "Domains", typeof( ObservableCollection<DomainViewModel> ), typeof( MainWindow ), new PropertyMetadata( null ) );
public ObservableCollection<DomainViewModel> Domains {
get { …
Run Code Online (Sandbox Code Playgroud)