2009-10-28 19 views
10

में जावा ऑब्जेक्ट वैल्यू पास करना मैं एक कस्टम जेएसपी टैग से जावा वैरिएबल पास करने की कोशिश कर रहा हूं (जावा क्लास से वैरिएबल प्राप्त करने के लिए यहां स्ट्रैट्स 2 का उपयोग कर रहा हूं)। मुझे जो त्रुटि मिल रही है वह यहां दी गई है।कस्टम जेएसपी टैग

javax.servlet.ServletException: /pages/editBidForm.jsp(51,8) According to TLD or attribute directive in tag file, attribute parentId does not accept any expressions 
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515) 
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) 
    .... 

यहाँ मेरी jsp पेज (भाग)

<%@ taglib prefix="s" uri="/struts-tags" %> 
<%@ taglib uri="/WEB-INF/taglib.tld" prefix="custom" %> 
... 
... 
<table> 
      <tr> 
      <% 

     String bidformoid=null; 
     bidFormOid=request.getParameter("bidFormOid"); 
     %> 

      <td> <custom:zorancustomtag parentType = "BIDFORM" parentId = "<%= pageContext.getAttribute("bidFormOid") %>" /></td> 


      </tr> 
     </table> 

मैं parentId पैरामीटर सही ढंग से पारित करने में सक्षम नहीं कर रहा हूँ है। मैं पैरेंट टाइप पैरामीटर को सही ढंग से पास करने में सक्षम था क्योंकि इसमें केवल स्ट्रिंग

टैगलिब फ़ाइल है।

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag 
Library 1.2//EN" 
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"> 
<taglib> 
     <tlibversion>1.0</tlibversion> 
     <jspversion>1.1</jspversion> 
     <shortname>custom</shortname> 
    <tag> 
     <name>zorancustomtag</name> 
     <tagclass>com.zoran.action.CustomizedTag</tagclass> 
     <bodycontent>JSP</bodycontent> 
     <info>Tag having a body and attributes</info> 
     <attribute> 
     <name>name</name> 
     <required>false</required> 
     <rtexpvalue>false</rtexpvalue> 
     </attribute> 

     <attribute> 
     <name>parentType</name> 
     <required>true</required> 
     <rtexpvalue>true</rtexpvalue> 
     </attribute> 

     <attribute> 
     <name>parentId</name> 
     <required>true</required> 
     <rtexpvalue>false</rtexpvalue> 
     </attribute> 



    </tag> 

</taglib> 

और कस्टम टैग की जावा क्लास।

public class CustomizedTag implements Tag { 
    private PageContext pageContext; 
    private Tag parent; 
    private String name; 
    private int parentId; 
    private String parentType; 
    List list = null; 




    public String getName() { 
    return name; 
    } 

    public void setName(String name) { 
    this.name = name; 
    } 

/* public CustomizedTag() { 
     super(); 
    } 
*/ 
    public int doStartTag() throws JspException { 
     Session session = SessionUtil.getSession(); 
     session.beginTransaction(); 


     try { 
      JspWriter out = pageContext.getOut(); 
      String parId = getParentId()+""; 
     // out.println(getParent()+"&nbsp;"); 
      String quer = "from ContentBase cb where cb.parentType=? AND cb.parentId=? ";//+parId; 
      Query query = session.createQuery(quer); 

      query.setParameter(0, getParentType()); 
      query.setParameter(1, getParentId()); 

      list = query.list(); 
      ContentBase cb = new ContentBase(); 
      if (null != list && !list.isEmpty()) { 
       cb = (ContentBase) list.get(0); 
      } 

     // pageContext.getOut().print("Sri "+getName()); 

      out.println(cb.getDescription()); 


     } catch (IOException ioe) { 
     throw new JspException("Error:"+ioe.getMessage()); 
     } 
     return SKIP_BODY; 
    } 

    public int doEndTag() throws JspException { 
     return SKIP_PAGE; 
    } 
    public void release() { 
    } 



    public void setPageContext(PageContext pageContext) { 
     this.pageContext = pageContext; 
    } 

    public void setParent(Tag parent) { 
     this.parent = parent; 
    } 

    public Tag getParent() { 
     return parent; 
    } 

public int getParentId() { 
    return parentId; 
} 

public void setParentId(int parentId) { 
    this.parentId = parentId; 
} 

public String getParentType() { 
    return parentType; 
} 

public void setParentType(String parentType) { 
    this.parentType = parentType; 
} 

} 

किसी को भी मुझे पता है कि कस्टम JSP टैग के माध्यम से एक जावा चर पारित करने के लिए कृपया कर सकते हैं।

धन्यवाद, आदित्य

उत्तर

13

अपने TLD में <rtexpvalue> तत्व <rtexprvalue> हो सकता है और true को निर्धारित करने की आवश्यकता चाहिए:

<attribute> 
    <name>parentId</name> 
    <required>true</required> 
    <rtexprvalue>true</rtexprvalue> 
    </attribute> 

इस क्रम भाव विशेषता मान के रूप में आपूर्ति की जा कर सकते हैं। मैं इस बात के बारे में रहस्यमय हूं कि जेएसपी डिज़ाइन टीम के किसने सोचा था कि यह false पर सेट करने की अनुमति देना एक अच्छा विचार था।

+0

धन्यवाद की कोशिश करो। विशेषता के साथ कस्टम जेएसपी टैग सही है? –

+4

एक टाइपो (ओपी के पोस्ट में भी मौजूद था) था, यह 'rtexpvalue' के बजाय' rtexprvalue' होना चाहिए। मैंने जवाब अपडेट किया। – BalusC

+0

यह वास्तव में मेरी समस्या भी थी - बहुत बहुत धन्यवाद! –

-2

$ में parentId मूल्य लपेटकर जवाब के लिए, लेकिन फिर भी 'सही' मैं एक ही त्रुटि संदेश मिल रहा करने के लिए विशेषता सेट करने के बाद {}

<custom:zorancustomtag parentType = "BIDFORM" parentId = "${<%= pageContext.getAttribute("bidFormOid") %>}" /> 
संबंधित मुद्दे