Java Struts2使用toString方法而不是TypeConverter

Java Struts2使用toString方法而不是TypeConverter,java,struts2,Java,Struts2,我有一个Struts2应用程序,我正在尝试使用自定义类型转换器 <s:a action="documentView"> <s:param name="documentTag" value="constructTag(#aDocumentIndex)"/> view </s:a> 当呈现页面时,使用toString方法代替类型转换器。为什么? PS:调用documentView操作时,类型转换器正常工作。我很困惑,您想要呈现什么?目前,do

我有一个Struts2应用程序,我正在尝试使用自定义类型转换器

<s:a action="documentView">  
  <s:param name="documentTag" value="constructTag(#aDocumentIndex)"/>  
  view  
</s:a>
当呈现页面时,使用
toString
方法代替类型转换器。为什么?


PS:调用
documentView
操作时,类型转换器正常工作。

我很困惑,您想要呈现什么?目前,documentTag.toString方法正在调用documentTagConverter.convertToString。然后程序正常工作。问题是为什么struts调用documentTag.toString而不是documentTagConverter.convertToString.Type转换器应用于设置动作而不是视图的属性。constructTag()返回一个字符串,您正在使用OGNL表达式调用该字符串,操作参数的设置通过ParamsInterceptor(?)完成,无论名称如何,在OGNL执行过程中不涉及拦截器,因此需要toString。您可以使用s:bean标记手动创建类型转换器的实例,然后在value属性中调用其方法,也可以向转换器添加静态方法,允许静态方法访问并更直接地调用它。
public DocumentTag constructTag(DocumentIndex documentIndex) {  
  return new DocumentTag(documentIndex);  
}