JSF tag inside another JSF tag

Hi,
Note: It's a bit of a long post but I will try to cut to the point without leaving behind any pertinent details.
I've created some simple custom JSF tags in the past. The tags usually consisted of one or two attributes that would be beans. The tags would then print out the data for those beans or process them and then output the results.
What I am trying to do now is a bit more complicated for me. I have a JSP page with a scriplet on it. It iterates over a bean containing a list of items. The loop adds those items to an HTML select menu one at a time. The outline of the code looks similar to this,
<% extract data List from the bean and store it in variable called dataList %>
<select>
<%
  for (int i=0; i<dataList.size(); i++;){
    ListItem item = dataList.get(i);
    String name = item.getName();
    String value = item.getValue();
%>
<option value="<%=value%>">
  <%=name%>
</option>
<%}%>
</select>
<h:commandButton id="gobtn" action="go_to_page" actionListener="#{action.fetch}" value="Go"/>What I want to do is take all the above code and put it into a custom JSF tag. This tag would contain all the scriplet code, output the HTML code and also the commandButton code at the end.
All of that is pretty easy except for the commandButton part. I am not sure how to output a commandButton from a custom JSF tag. How do I pass it the action.fetch part for the actionListener attribute? Can I create a commandButton object in my custom JSF tag and pass it this information?
I've followed a tutorial at this site in the past but it doesn't go into too much detail
http://www.exadel.com/tutorial/jsf/jsftutorial-customcomponents.html
Any help is appreciated,
Nick

I guess I missed some information. The dataList in the bean is stored in a HashMap. So some work has to be done with the bean before hand to determine what list to pull out and then "massage" it a bit for viewer consumption. This is not easily accomplished with the standard JSF html tags, hence my going with a custom tag approach.
Processing this bean and getting a list from the Hashmap in the bean before displaying it is easy, so is outputting the HTML. The hard part is rendering the commandButton with all the attributes I listed previously.
Is there a way in general to have other JSF tags nested inside a custom JSF tag?

Similar Messages

  • Is possible to write a custom tag inside another custom tag ??

    Hi
    I�m trying to reduce the time needed to code mi app presentation layer, it uses some custom tags with certain configuration, i would like to know if its possible to do something like this inside my custom tag doAfterBody().
    public int doAfterBody() throws JspException {
              JspWriter writer=bodyContent.getEnclosingWriter();
              try {
                   writer.print("<customTag:myAnotherTag someEspecificConfigurationParams="someEspecificValues"/>");
              } catch (IOException e) {
                   pageContext.getServletContext().log("Error: "+e.getMessage());
              }return SKIP_BODY;
         }The goal is to simplify the jsp code because the configuration params for the custom tags (css styles and similar) are allways the same.
    That don�t work, it simply prints <customTag:myAnotherTag/> in screen but the tag is not evaluated, i�ve tried too something like
    public int doAfterBody() throws JspException {
              if (repeat) {
                   JspWriter writer = bodyContent.getEnclosingWriter();
                   try {
                        writer.print("<customTag:myAnotherTag/>");
                   } catch (IOException e) {
                        pageContext.getServletContext().log("Error: " + e.getMessage());
                   repeat = false;
                   return EVAL_BODY_AGAIN;
              return SKIP_BODY;
         }And it doesn�t worked worked. Maybe using the taghandler classes and calls to the doAfterBody could make it work, but when you need to nest tags it could be a little hell of coupling calls, so before doing it i would like to know if what i want is possible. After reading some books i tought it could work because the stack of out objects, but i can�t make it work.
    Another idea is to inherit from tagHandler and override some properties in the tags, but i don�t like the idea to much.
    So, can anyone help me??
    Thanks.

    You cannot do that and I have listed out the reason and a possible solution in this post http://forum.java.sun.com/thread.jspa?threadID=697243 from yesterday.
    cheers,
    ram.

  • Insert html form tag inside another form tag

    Hi all, this is my issue. I have a xhtml page structured as following:
    <h:form id="mainForm">
    ....... some stuff........
    <form id="fileForm" action="myServlet" method="post" enctype="multipart/form-data">
         <input type="file" onchange="fileForm.submit()" />
    </form>
    </h:form>
    When uploading a file, I wanna submit only 'fileForm'. But "fileForm.submit()" doesn't work because fileFom is null. Looking at the page source, I realized that only one form is seen client-side (the mainForm):
    <form id="mainForm">
    ....... some stuff........
         <input type="file" onchange="fileForm.submit()" />
    </form>
    Any idea on how to implement it?
    Thanks in advance...

    I think so too.
    I tried creating a custom fileUploader component but, as expected, it didn't work.
    Here http://balusc.blogspot.com/2009/12/uploading-files-with-jsf-20-and-servlet.html they create a completely custom renderer which would solve my issue but it works only with j2ee6 and for company reason I must use j2ee5.
    I think I have to refactor the page and figure out a new approach.
    Thanks for your reply.

  • How to use h:selectOneRadio tag  inside h:dataTable tag

    Hi All,
    Can any one tell me how to use <h:selectOneRadio> tag inside <h:dataTable> tag and how to get selected radio button value in bean ?

    JSF<h:selectOneMenu value="#{myBean.selectedItem}">
        <f:selectItems value="#{myBean.selectItems}" />
    </h:selectOneMenu>MyBeanprivate String selectedItem;
    public String getSelectedItem() {
        return selectedItem;
    public void setSelectedItem(String selectedItem) {
        this.selectedItem = selectedItem;
    public List getSelectItems() {
        List selectItems = new ArrayList();
        selectItems.add(new SelectItem("key1", "value1"));
        selectItems.add(new SelectItem("key2", "value2"));
        selectItems.add(new SelectItem("key3", "value3"));
        return selectItems;
    }String selectedItem should contain the key (key1, key2 or key3) when selected. The values (value1, value2 and value3) are the options as shown in the list.

  • Why would someone use the meta utf-8 tag inside the script tag?

    I have run into a number of sites that use the <meta utf-8> tag inside the <script> tag what is the use of it.
    How dose one write the utf-8 inside the script tag?

    csteinola wrote:
    > If I CFINCLUDE that cache file, the characters come out
    munged (non-utf-8
    > encoded).
    try prepending a <cfprocessingdirective
    pageencoding="utf-8"> to the file.

  • C:forEach tag inside another c:forEach tag

    Hi,
    I've got en error when I tried to use <c:forEach> inside another <c:forEach> to display a vector of String arrays.
    The error message is:
    javax.servlet.ServletException: The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.
    The concerned section of the javabean mybean.java is:
    //connect to database to get the resultset
    ResultSet rs = cst.getResultSet();
    if (rs != null) {
    myVector = new Vector();
    while (rs.next()) {
    String myArray[] = new String[10];
    myArray[0]=rs.getString(1);
    myArray[1]=rs.getString(2);
    myArray[9]=rs.getString(10);
    myVector.addElement(myArray);
    rs.close()
    The concerned jsp calling the bean is:
    <jsp:useBean id="theBean" scope="session" class="mybean" />
    <jsp:setProperty name="theBean" property="..." />
    <%
    Vector myVector=theBean.getResultFromDatabaseIntomyVector();
    pageContext.setAttribute("myVector",myVector);
    %>
    <table>
    <c:forEach var = 'vectorItem' items='${myVector}'>
    <tr>
    <c:forEach var = 'arrayItem' items='${vectorItem.value}'>
    <td><c out value='${arrayItem}'/></td>
    </c:forEach>
    </tr>
    </table>
    Can anyone show me what's the right jsp for displaying a vector of String arrays?
    Thanks in advance.
    Geraldine

    I think your problem is with the second forEach loop.
    The first for loop goes through the items in "myVector"
    Each item "vectorItem" should be of type String[]
    Accessing ${vectorItem.value} is what creates the error.
    JSTL converts this as
    vectorItem["value"] , can't turn the string "value" into an integer (to use as an array index) and thus throws an error.
    To fix: use ${vectorItem} rather than ${vectorItem.value}
    (nb you would use {vectorItem.value} if you were iterating over a Map, as the iterator exposes an object of type Map.Entry
    Also in your code, I only see one closing tag for a forEach.
    I think it should be like this (indented for readability)
    <table>
    <c:forEach var = 'vectorItem' items='${myVector}'>
    <tr>
      <c:forEach var = 'arrayItem' items='${vectorItem}'>
        <td><c out value='${arrayItem}'/></td>
      </c:forEach>
    </tr>
    </c:forEach>
    </table>Cheers,
    evnafets

  • Using a custom tag inside another tag's attribute value?

    Hi all,
    I have a custom tag, mytag:link, whose use currently looks like this:<mytag:link path="/images/logo.gif"/>Nevermind what the tag does. Here's its TLD:<?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>
        <tlib-version>1.1.1</tlib-version>
        <jsp-version>1.2</jsp-version>
        <short-name>My custom tags TLD</short-name>
        <tag>
            <name>link</name>
            <tag-class>test.MyLinkTag</tag-class>
            <body-content>empty</body-content>
            <description>...</description>
            <attribute>
                <name>path</name>
                <required>true</required>
                <rtexprvalue>true</rtexprvalue>
            </attribute>
        </tag>
    </taglib>I want to replace the path argument of the mytag:link tag to the result of the evaluation of another tag (a SiteMesh decorator tag) like this:<mytag:link path="<decorator:getProperty property="meta.logo"/>"/>This, of course, doesn't work, as I get the following error:org.apache.jasper.JasperException: /decorator.jsp(34,92) equal symbol expected
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:86)
         org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:193)
         org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:143)
         org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1328)
         org.apache.jasper.compiler.Parser.parseElements(Parser.java:1564)
         org.apache.jasper.compiler.Parser.parse(Parser.java:126)
         org.apache.jasper.compiler.ParserController.doParse(ParserController.java:211)
         org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
         org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:146)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         com.opensymphony.module.sitemesh.filter.PageFilter.applyDecorator(PageFilter.java:156)
         com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:59) If I replace the call to the other tag with
    <mytag:link path="<%=someVariable%>"/>then it all works fine. This behavior seems correct, as the SiteMesh getProperty tag is writing its output to the Writer returned by pageContext.getOut() as it should. As such, this seems to be a design question, then. How are you supposed to do this?
    Thanks in advance,
    Matthew

    Note that I've also posted a question to the SiteMesh user forums about this. It has more information about the motivation of this question.
    See http://forums.opensymphony.com/thread.jspa?threadID=8561
    I'm still looking for an answer, though.
    --matthew                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Prob when there is any HTML tag inside netui:label tag

    Hi,
    When i am displaying content in a script directly and if some HTML tag is there in the content like <b> or <i> tag then that particular property is reflected in the displayed content
    Eg: In code: <%=headline %>
    Headine=This is a <b><i>beautiful </i></b>flower
    Output: This is beautiful flower
    When I displayed same headline using <netui:label>
    Eg: In code: <netui:label value=”<%=headline %> ”>
    Headine=This is a <b><i>beautiful </i></b>flower
    Output: This is a <b><i>beautiful </i></b>flower
    So is there any workaround by which I can get same output(as for normal script) with <netui:label> tag
    Thanks

    Hi,
    When i am displaying content in a script directly and if some HTML tag is there in the content like <b> or <i> tag then that particular property is reflected in the displayed content
    Eg: In code: <%=headline %>
    Headine=This is a <b><i>beautiful </i></b>flower
    Output: This is beautiful flower
    When I displayed same headline using <netui:label>
    Eg: In code: <netui:label value=”<%=headline %> ”>
    Headine=This is a <b><i>beautiful </i></b>flower
    Output: This is a <b><i>beautiful </i></b>flower
    So is there any workaround by which I can get same output(as for normal script) with <netui:label> tag
    Thanks

  • JSF page loading another JSF in iframe from same domain with diff port

    I was wondering if anyone has experienced this issue. I'm using ADF 11g and weblogic 10.3.2. Here's the scenario
    1. two ADF 11g application, app1 and app2
    2. app1 is deployed on managedserver1 running on port 7001
    3. app2 is deployed on managedserver2 running on port 7002
    4. page1 on app1 loads page2 from app2 inside an iframe.
    5. When a button is clicked on page1 that does a ppr or even a complete postback, the following message from the browser appears:
    Because of inactivity, your session has timed out and is no longer active. The page will automatically be reloaded in 10 seconds; if not, click here.
    When i check the log file on managedserver1 its has the following error:
    SEVERE: Could not find saved view state for token <some token>
    I did some research and came across oracle.adf.view.rich.security.FRAME_BUSTING, but this is not the issue here, the iframe loads fine, but after loading when i tried to do something on page1 it seems that the state of the page is messed up.
    Any idea would be helpful.
    Edited by: user8663354 on Jun 20, 2010 7:05 PM

    Hi,
    chances are that the iframe is not isolated as you think it is and the state management of the two overrides each other. I think its best to file a service request with customer support to ensure this scenarion is supposed to work
    Frank

  • How to do a jsp:include inside a noscript tag??

    I am new to JSP and I need help to do a <jsp:include page="pageName" /> inside a <noscript> tag. My goal is to include another jsp if the user has javascript disabled on its browser.
    I am using a JSP template that retrieves content from the Database, so I need to pass a parameter also, like:
    <noscript>
    <jsp:include page="/include/template.jsp" flush="true"/>
         <jsp:param name="pageName" value="holidays_onboard_html"/>
    </noscript>
    My code doesn't seem to work. I found an explanation that says that the noscript tag is interpreted after the servlet already tried to compose the original page, so I can't use a <jsp:include> tag inside the noscript tag. Is it true? Is there any other solution for what I am trying to accomplish?
    Thanks a lot!

    Java indeed runs at the server side, not at the client side. Java runs at the server side and produces a HTML page. HTML only runs at the client side.
    The <noscript> tag is not a Java/JSP tag, it is a HTML tag. What you want is only possible when you checked in Java if the client has JS enabled, e.g. using a request parameter, or by loading the page template using a HTML tag, e.g. <iframe>.

  • Tags inside tags in InDesign

    Hello,
    I have a problem with InDesign tags. I hope I've mapped tags to styles correctly, but suppose this: you have a tag inside another tag, like superscript inside italics, I then need the superscript to be italics as well. And if it's not inside italics then I need it to be regular.
    <i>Ba<sup>r</sup>nabas</i> would have to be Barnabas
    NO<sup>2+</sup> would have to be NO2+
    This seems to be a bit of a problem for InDesign (CS3). Would there be a ready solution for this?
    Many thanks,
    Ervin

    Possibly your expectations are too high. ... Scratch that "possibly".
    XML, in general, cannot be "rendered". It's just an abstract data format. Compare it to common markup such as *asterisks* to indicate emphasized words -- e-mail clients will show this text in bold, but InDesign, and the vast majority of other software, does not.
    To "render" XML, HTML, MathML, or LaTeX -- you seem to freely mix these *very* different markup formats, unaware of the fact that they are vastly different from each other! -- in the format you "expect", you need to apply the appropriate software to each of  the original data files. None of these markup languages are supported natively by InDesign.

  • Send a back bean to another jsf

    Hi to everyone,
    can anyone tell me, how i can send a back bean of a jsf page to another jsf page.
    For example JSF1 send his to bean to JSF2.
    It's like a session variable?
    Thanxs, Fabio

    Hello,
    If the backing bean is defined as the managed bean in the faces-config xml, then you can retrieve the backing bean which is in the session context from the sessionMap as follows:
    facesContext.getExternalContext().getSessionMap().get("YOUR BACKING BEAN NAME");
    Also, you can create a value binding with the name of your session bean and get it from the faces context.

  • How to use HTML tags inside JSF pages

    I am creating a Menu using dataTable and outputLink in a JSF page.
    <div class="bodyarea">
    <div id="location">
    <ol>
    <h:dataTable value="#{menuItem.breadCrumb}" var="bread" >
    <h:column>
    <li>
    <h:outputLink id="crumbID" value="#{bread.menuLink}">
    <h:outputText id="crumpName" value="#{bread.menuLabel}" style="width: 165px;"/>
    </h:outputLink>
    <li>
    </h:column>
    </h:dataTable>
    </ol>
    </div>
    </div>
    I want to use <li> HTML tag as shown in code above before and after every <tr> tag formed, but when i run it and see view source, this is how it shows:
    NOTE: you can see it has thrown out of <table> tag itself.
    <div class="bodyarea">
    <div id="location">
    <ol>
    <li>
    </li>
    <table>
    <tbody>
    <tr>
    <td><a id="_id0:0:crumbID" href="/eApps/admin/loginPage.jsp?MenuItem=-1"><span id="_id0:0:crumpName" style="width: 165px;">Home</span></a></td>
    </tr>
    <tr>
    <td><a id="_id0:1:crumbID" href="/eApps/admin/loginPage.jsp?MenuItem=3~-1"><span id="_id0:1:crumpName" style="width: 165px;">HIM Admin</span></a></td>
    </tr>
    </tbody>
    </table>
    </ol>
    </div>
    </div>
    Can some one help me, how do i use HTML tags inside <h:dataTable>.
    Or is their any other way i should form my Menus, to fully utilize to HTML tags.
    Thanks
    Ravi

    Hello,
    You can embed the verbatim elements in your datatable, ie,
    <h:dataTable value="#{menuItem.breadCrumb}" var="bread" >
      <h:column>
        <f:verbatim><li></f:verbatim>
        <h:outputLink id="crumbID" value="#{bread.menuLink}">
          <h:outputText id="crumpName" value="#{bread.menuLabel}" style="width: 165px;"/>
        </h:outputLink>
        <f:verbatim></li></f:verbatim>
      </h:column>
    </h:dataTable>

  • How to add raw HTML tags inside JSF tags...

    Hi
    I would like to use <input type = text > inside my project in some area..The following code hides the input = type html tag and forwards the click event to jsf command button...After selecting the file,it should forward the value to jsf textfield....
    My code seems as below.
    <h:form id="detailForm" onsubmit="printElements(detailForm,this)">
    <f:verbatim>
    <input id="uploadFile" type="file" style ="dispaly:none"size="100" />
    </f:verbatim>
    <h:inputText id="docName" style="width:650px;" maxlength="100"/>
    <h:commandButton id="visibleBrowseButton" value="Select File..." onclick="'detailForm:uploadFile'.click();callClick();">
    </h:commandButton>
    </h:form>
    <script type="text/Javascript">
    function callClick()
    var val = document.detailForm.uploadFile.value;
    document.getElementById('detailForm:docName').value = val;
    </script>
    While running this page it works fine in IE but in Mozilla firefox it troubles me during detailForm:uploadFile'.click().
    I suspect the jsf page cannot able to detect the raw html tag inside jsf tags...Eventhough i tried using inside<f:verbatim> it wont works..
    I would like to know
    1.Whether the code is right,,if the code goes wrong why it got runned in IE not in firefox....
    2.How can raw html tags can be integrated inside JSF tags....

    First of all, why are you ignoring valuable answers about a JSF fileupload component in your previous topic?
    Second, you can just nest raw HTML anywhere in your JSF page. Your problem is rather related to JavaScript. It has completely nothing to do with Java nor JSF. Learn JavaScript -there is a nice tut at w3schools.com- and look for a JavaScript forum if you still stucks. There are ones at webdeveloper.com and dynamicdrive.com.
    The f:verbatim is only required if you was using JSF 1.1 or older, which is not the case. You would have occurred completely different problems.

  • Mixing HTML and JSF or better pure JSF Tags?

    I'm relatively new to JSF, but i can say, i work with all the Web Standards in HTML and CSS.
    So the HTML Render Results of JSF may not fit into a Web Developers Dreams of perfect HTML/CSS.
    An Option i see is to use HTML and put only the dynamic parts in there as JSF Components.
    What are the Pro's and Con's using HTML?
    some stuff i can image:
    Using pure JSF:
    - May many components have impact to the performance?
    - Mixed with HTML: What if the application should be rendered to another client pc (e.g. Mobile)?
    What are your experiences?

    The one downfall of mixing html with jsf, unless you use the f:verbatim tag, that the page is not properly represented in the component tree. Also depending on certain technologies you use (when I used ajax4jsf it worked this way) that the jsf component tree was rendered and then all the html was rendered at the end. This caused html tags and text that I had inside a jsf tag to be improperly displayed.
    This though was the case when I was originally using jsf 1.1, so it may have been improved in later editions, but since I have become accustomed to writing the entire page in jsf tags I have not really tested that limit in the current version.

Maybe you are looking for

  • Do I have to re-by App add on's?

    Recently my Ipad Mini was reset to its original settings and was supose to back up my old info. It when back to its original settings just fine, but come to find out my ipad ubs cord is bad and it keeps saying its plugged in and then it says its not

  • Querying for large number of objects... searchspec limitation

    As part of a product i'm developing i may come across a scenario where i need to query for 100+ specific objects based on ids. I know the query input for WS 2.0 has a "searchspec" string field, but based on the sheer number of specific objects i need

  • How to add an embedded report to custom UI?

    Dear colleagues: Since now I am doing investigation on this:How to add an embedded report to custom UI , so do you have some guideline doc for this? Requirement is: Customer want to add a custom report to a custom FS page. And it has some standard fi

  • ASM instance fail CRS-1028

    Dear All In progressing DBCA then 'Fail to start ASM instance'. CRS-1028 Dependency nalysis fail. because of CRS-0223. How can i solve that

  • Good Books/Readings on SEM-BPS?

    Hello gurus, Can anyone tell me some good books on SEM-BPS? Any material will also be appreciated. Thanks a lot! Sri