我解释我的问题:为什么portlet是renderRequest.setAttribute返回最后一个变量?
我使用的是Liferay 6.1,我试图理解Documents and Media控制面板的功能。
在我的portlet视图中,我有一个显示文档列表的表格,其中一个字段是修改日期。默认情况下,这个日期是文件修改日期。
在java代码中,我需要检查这个日期字段(可选),如果它是空的,我保留旧代码(显示文档的修改日期)如果它不是空的,那么我想显示它的值相反(可选日期的值)。
我创建了一个文档类型,并在称为date(可选)的文档类型中添加了一个字段来手动添加日期。
其中一件事我不明白,当试图添加一个字段ddm-date类型的日期字段应该有一个默认值,它不能为空 我错了吗?
我的第一个问题,如何设置ddm-date类型为空?
在创作现场的时候,我把没有的首选值的CMS自动更改为默认值,并在表格(添加新文件时)可选日期的选择数据不包含我看到一个空的值(默认情况下它包含今天的日期)。
所以我用文本字段作为类型。
我的主要问题:
我显示了可选的日期,但它会覆盖所有的创建日期。在显示屏中,我只获取可选日期和最后一个。我解释了何时从“文档和媒体”控制面板添加文件,并使用可选日期字段(例如值为“2012/08/01”),表中的所有值均由此值替换。
我用java代码使用renderRequest.setAttribute
发送了我的变量,我用JSTL - Core <fmt: formatDate value = "$ {optionalDate}" pattern = "MMM yyyy" />
标记在我的视图中显示了它。我的portlet也从MVCPortlet扩展而来。
为什么doView呈现renderRequest.setAttribute
返回最后一个变量?
在我的Java代码:
for(DLFileEntry file : listFiles){
try {
Map<String, Fields> fieldsMap = file.getFieldsMap(file.getFileVersion().getFileVersionId());
if(fieldsMap.values().size() <= 0)
listContextFiles.remove(file);
for (Fields fields : fieldsMap.values()) {
if(...){
if(...){
}
else{
if(fields.get("optionaldate") != null) {
DateFormat dateFormat1 = new SimpleDateFormat("yyyy/MM/dd");
String _optionalDate = (String) fields.get("optionaldate").getValue();
Date optionalDate = dateFormat1.parse(_optionalDate);
file.setModifiedDate(optionalDate);
renderRequest.setAttribute("optionalDate", optionalDate);
System.out.println(file.getModifiedDate());
listDate.add(dateFormat.format(file.getModifiedDate()));
}
else{
renderRequest.setAttribute("optionalDate", file.getModifiedDate());
if(!listDate.contains(dateFormat.format(file.getModifiedDate()))){
listDate.add(dateFormat.format(file.getModifiedDate()));
}
}
//other conditions
}
...
在我view.jsp的:
<liferay-ui:search-container iteratorURL="<%=actionURL%>" delta="10"
emptyResultsMessage="no-documents">
<liferay-ui:search-container-results total="<%=list.size()%>"
results="<%=ListUtil.subList(list,
searchContainer.getStart(),
searchContainer.getEnd())%>" />
<liferay-ui:search-container-row modelVar="file"
className="DLFileEntry">
<!--other code-->
<liferay-ui:search-container-column-text name='date'
cssClass="txt-capitalize width-10">
<fmt:formatDate value="${optionalDate}" pattern="MMM yyyy" />
</liferay-ui:search-container-column-text>
<!--other code-->
</liferay-ui:search-container-row>
</liferay-ui:search-container>
有没有干净的方式来做到这一切的?
有人能告诉我我的代码有什么问题吗?
你好,我可以找到一个解决方案。我的问题仍然存在[搁置]。 –
有人能告诉我我的代码有什么问题吗? –