【问题标题】:How to read another Text element value while customising element?自定义元素时如何读取另一个文本元素值?
【发布时间】:2014-05-15 09:10:35
【问题描述】:

我做了什么:

第 1 步:我在“测试”创作模板中制作了两个文本元素(假设元素的名称是 userName 和 UserId)。 第 2 步:我使用 jsp 自定义了第一个元素(用户名)。

但是在自定义第一个元素(userName)时,我需要将第二个文本元素(UserId)的值提取到 userName 中。

我可以使用下面的代码获取第一个文本元素(用户名)的值,但我将如何获取第二个元素值?

<%@ taglib uri="/WEB-INF/tld/portlet.tld" prefix="portletAPI" %>
<%@ page import="com.ibm.workplace.wcm.api.authoring.CustomItemBean" %>

<portletAPI:init />


<% 
CustomItemBean customItem = 
(CustomItemBean) request.getAttribute("CustomItemBean"); 
customItem.setSubmitFunctionName("myoptionsubmit");
String fvalue = (String)customItem.getFieldValue();

%>

<script language='Javascript'>
function myoptionsubmit()
{
document.getElementById('<%=customItem.getFieldName()%>').value = 
document.getElementById('<%=customItem.getFieldName()%>_mycustomoption').value;
}
</script>

<INPUT id='<%=customItem.getFieldName()%>_mycustomoption' value="<%=fvalue%>">

【问题讨论】:

  • 忘记附上代码:

标签: jsp websphere-portal


【解决方案1】:
<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="com.ibm.workplace.wcm.api.exceptions.*"%>
<%@ page import="java.util.*,javax.servlet.jsp.JspWriter,java.io.*"%>
<%  
Workspace myworkspace=null;
try {
DocumentId docId=null;
DocumentIdIterator itemsIterator=null;
myworkspace = WCM_API.getRepository().getSystemWorkspace();  
DocumentLibrary MyLibrary = myworkspace.getDocumentLibrary("LIB_FOR_DEVICE");
DocumentIdIterator docIdIterator = myworkspace.findByName(DocumentTypes.Content,    "RENDER_TEST_CONTENT");
DocumentId docId1;
Content currentContent; 
LibraryRichTextComponent currentContent1; 
Object object=null;
TextComponent textComponent=null;
RichTextComponent richTextComponent=null;
ImageComponent imageComponent=null;
while(docIdIterator.hasNext()) 
{       
docId1 = (DocumentId)docIdIterator.next();
currentContent = (Content)myworkspace.getById(docId1); 

ContentComponentIterator contentComponentIterator=currentContent.componentIterator();
     while(contentComponentIterator.hasNext())
     {
     object=contentComponentIterator.next();
     if(object instanceof TextComponent)
     {
     textComponent=(TextComponent)object;
      out.println("<br/>TC:</br>"+ textComponent.getText());
     }
      if(object instanceof RichTextComponent)
     {
     richTextComponent=(RichTextComponent)object;
      out.println("<br/>RTC:</br>"+ richTextComponent.getRichText());
     } 
     }


 }

myworkspace.logout();

} 捕获(异常 e) {} %>

【讨论】:

    猜你喜欢
    • 2019-12-11
    • 2022-10-15
    • 2022-01-16
    • 2014-08-21
    • 1970-01-01
    • 2016-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多