Deferred expressions inside JSP tags

Hello!
I want to include custom JSP 2.0 tag into page.
Something like
<!-- Page.jsp -->
<jsp:root version="2.0"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:pk="urn:jsptagdir:/WEB-INF/tags">
    <jsp:directive.page language="java"
        contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" />
<f:view>
<pk:custTag bean="${beanInstance}"/>
</f:view>
</jsp:root>inside that tag I want to access my bean in JSF 1.2 way:
<!-- custTag.tag -->
<jsp:root version="2.0" xmlns:h="http://java.sun.com/jsf/html">
<jsp:directive.tag body-content="empty" language="java"
        pageEncoding="ISO-8859-1" />
<jsp:directive.attribute name="bean" required="true" type="com.my.Bean"/>
Runtime way:
${bean}
${bean.prop}
Deferred way:
<h:outputText value="#{bean}"/>
<h:inputText value="#{bean.prop}"/>
</jsp:root>So ${} renders as expected, but <h:outputText> renders nothing as #{} evaluates to null. What should I do to make outputText and inputText work, if that's possible at all?
I use Tomcat 6.0.2 and JSF-RI 1.2_03.
Thanks,
Alexey

Oh, I see now.
But is there a way to trick JSF by explicitly putting bean into request scope? Something, like Tomahawk's aliasBean?
Actually, I did try to implement it. The following code was supposed to create a variable in EL-context:
ValueExpression     expr = _value instanceof ValueExpression
                   ? (ValueExpression)_value
                   : facesContext.getApplication().getExpressionFactory().createValueExpression(_value, Object.class);
ELContext   ctxt = facesContext.getELContext();
VariableMapper varMap = ctxt.getVariableMapper();
if ( varMap == null ) {
    ((ELContextImpl)ctxt).setVariableMapper( new VariableMapperImpl() );
    varMap = ctxt.getVariableMapper();
if ( varMap != null ) {
    varMap.setVariable(_alias, expr);
    _active = true;
    log.fine("makeAlias: " + _alias + " = " + expr.getExpressionString());
} else {
    log.warning("makeAlias: " + _alias + " = " + expr.getExpressionString() + " failed");
}But resolving #{...} still returned null.

Similar Messages

  • HtML inside JSP Tag

    How much HTML can be inside a JSP Tag? I created a tag which set few variables. Now on the JSP page, if the variable A is not null, then only display value and show a link next to it.
    So is it OK, if I take the link html (href code) and concatenate with the vale of A
    Thanks in advance

    <ed:TableIterator resultId="calist">
      <tr class="altrow">
        <td class="center" style="vertical-align:top;">
          <input type="checkbox" onchange="ca.value='1';" class="cb" name="cadel" value="<ed:getColumn column="idx"/>"/>
          <input type="hidden" name="cadate" value="<ed:getColumn column="date"/>"/>
        </td>
        <td style="vertical-align:top;">
          <input type="text" onchange="ca.value='1';" class="text" name="caoms" value="<ed:getColumn column="title"/>"/>
        </td>
        <td>
          <textarea class="text" onchange="ca.value='1';" name="camemo" cols="40" rows="4"><ed:getColumn column="memo"/></textarea>
        </td>
      </tr>
    </ed:TableIterator>Loads :)
    This is a small sample, building the rows of a table with 3 columns (a checkbox, an inputfield and a textarea) for each row.
    I've built larger structures where I nest the same tags to create select controls in each row.
    I wouldn't actually create HTML inside the java class for the tag, as that violates the separation of code and presentation (that's not to say I haven't done it, but I've learned better since <GRIN> and now try to avoid it where possible and minimise it where not).

  • JSP ${} expressions in JSF tag attributes

    Does anyone know why the expert group decided not to allow ${} style expressions within JSF tag attributes? I understand that a different syntax is needed to implement the 'late binding' #{} expressions used to link input controls to form beans, but not why the JSF tags actually prevent the use of immediately evaluated ${} expressions for accessing variables in the page scope in JSP 2.0.
    I know there has been a lot of discussion about this and other threads mention a security loophole that would be opened up by allowing expressions like #{blah.${someProperty}}, but I'm not sure why this sort of thing would cause a problem. Is there any way to enable this behaviour, such as editing the JSF tag library descriptors to allow runtime expressions (horrible though that sounds)? Or perhaps another JSF implementation that supports both immediately evaluated and late-binding expressions? It seems a rather unnecessary restriction that is going to cause much confusion and mistyping for all...
    Thanks in advance,
    Keith.

    Thanks Adam, I see the problem now. It's a fairly obscure loophole but serious nonetheless. Of course, this problem could also be avoided by not using request parameters within JSF tags as it doesn't affect the majority of legitimate uses for expressions.
    I have to disagree with you about mixing ${} and #{} expressions though. The majority of developers will be used to writing ${} expressions in JSTL and JSP text and so will expect them to do work the same in JSF tags. Judging by the number of posts in this forum about being unable to use page scope variables in JSF tags this issue is already confusing a lot of people.
    As a rule of thumb, "use ${} for expressions that are output to the page and #{} for binding controls to backing beans and invoking methods" (which perform clearly distinct functions) is a lot simpler and easier to learn IMHO than the current one, which is "use ${} for expressions that are output to the page except within a JSF tag, where you use #{} for the same thing and also to update form values and invoke action methods"! (OK, I'm exaggerating a little for effect, but you get the point... :-)
    I agree that mixing both types of expression in the same attribute might be a little confusing, but this is an unlikely edge case that should probably be prevented in value binding or action attributes anyway. It's more of an issue for label values where mistyping one for the other is already very common and, although not especially difficult to debug, is just another pitfall awaiting the unwary JSP developer. I'm not sure that JSP expressions would be much more difficult to debug anyway as the value and method bindings will simply not work, which is pretty obvious as soon as you try and test the thing.
    Is this something that the EG would be prepared to reconsider for the next release of JSF, or perhaps getting the security loophole addressed in the next JSP spec? In the meantime, is there any reason that developers shouldn't enable runtime expressions in the TLD file provided that they're willing to live with the consequences?
    (Sorry to harp on about it, but I've already had several complaints about this after recommending JavaServer Faces for a major development project at ingenta.com.)
    Many thanks,
    Keith.

  • Calling methods from inside a tag using jsp 2.0

    My searching has led me to believe that you cannot call methods from in the jsp 2.0 tags. Is this correct? Here is what I am trying to do.
    I have an object that keeps track of various ui information (i.e. tab order, whether or not to stripe the current row and stuff like that). I am trying out the new (to me) jsp tag libraries like so:
    jsp page:
    <jsp:useBean id="rowState" class="com.mypackage.beans.RowState" />
    <ivrow:string rowState="${rowState}" />my string tag:
    <%@ attribute type="com.mypackage.beans.RowState" name="rowState" required="true" %>
    <c:choose>
         <c:when test="${rowState.stripeToggle}">
              <tr class="ivstripe">
         </c:when>
         <c:otherwise>
              <tr>
         </c:otherwise>
    </c:choose>I can access the getter method jst fine. It tells me wether or not to have a white row or a gray row. Now I want to toggle the state of my object but I get the following errors when I try this ${rowState.toggle()}:
    org.apache.jasper.JasperException: /WEB-INF/tags/ivrow/string.tag(81,2) The function toggle must be used with a prefix when a default namespace is not specified
    Question 1:
    Searching on this I found some sites that seemed to say you can't call methods inside tag files...is this true?...how should I do this then? I tried pulling the object out of the pageContext like this:
    <%@ page import="com.xactsites.iv.beans.*" %>
    <%
    RowState rowState = (RowState)pageContext.getAttribute("rowState");
    %>I get the following error for this:
    Generated servlet error:
    RowState cannot be resolved to a type
    Question 2:
    How come java can't find RowState. I seem to recall in my searching reading that page directives aren't allowed in tag files...is this true? How do I import files then?
    I realized that these are probably newbie questions so please be kind, I am new to this and still learning. Any responses are welcome...including links to good resources for learning more.

    You are correct in that JSTL can only call getter/setter methods, and can call methods outside of those. In particular no methods with parameters.
    You could do a couple of things though some of them might be against the "rules"
    1 - Whenever you call isStripeToggle() you could "toggle" it as a side effect. Not really a "clean" solution, but if documented that you call it only once for each iteration would work quite nicely I think.
    2 - Write the "toggle" method following the getter/setter pattern so that you could invoke it from JSTL.
    ie public String getToggle(){
        toggle = !toggle;
        return "";
      }Again its a bit of a hack, but you wouldn't be reusing the isStriptToggle() method in this way
    The way I normally approach this is using a counter for the loop I am in.
    Mostly when you are iterating on a JSP page you are using a <c:forEach> tag or similar which has a varStatus attribute.
    <table>
    <c:forEach var="row" items="${listOfThings}" varStatus="status">
      <tr class="${status.index % 2 == 0 ? 'evenRow' : 'oddRow'}">
        <td>${status.index}></td>
        <td>${row.name}</td>
      </tr>
    </c:forEach>

  • Jsp expression inside a onclick event

    onClick = "send(<%=layerColl.GetItem(i).GetObjectId()%>)" .... where is expression'll return a alphanumeric id... i want to receive it as a string in a JSP function public send(String a ){}

    on my understanding you are calling a javascript function onclick event. eventually you pass the variable as number or object on the function.
    like:
    <%
    String sample = "1";
    %>
    onClick = "send(<%=sample%>)"the value of the sample string is 1 so the function will be
    onClick = "send(1)"and you got error on the javascript in IE like Object Expected
    so you need to put the expression inside single quotes like
    onClick = "send('<%=sample%>')" correct me if i'm wrong. that is my understanding

  • Error compiling expressions in custom JSP tags

    We had the same problem and we have found the same solution. Not to nice.
              Jan
              

    Here is what I have set up:
    custom.jsp:
    <%@ taglib uri="/WEB-INF/tlds/mytags.tld" prefix="my" %>
    <!-- <%@ taglib uri="myTags" prefix="my" %> -->
    <HTML>
    <HEAD>
    <TITLE>Custom tag example</TITLE>
    </HEAD>
    <BODY>
    <H1>Custom tag Example</H1>
    <my:wrapper style="k001">
         <b>hello!</b>
    </my:wrapper>
    </BODY>
    </HTML>
    Under WEB-INF/tlds, I placed mytags.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/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>MyTags</short-name>
    <tag>
    <name>wrapper</name>
    <tag-class>mytaglib.WrapperTag</tag-class>
    <body-content>JSP</body-content>
    <attribute>
    <name>style</name>
    <required>true</required>
    </attribute>
    </tag>
    </taglib>
    I've seen examples for jsp-version 1.1 and 1.2. Can you suggest what should be placed in <uri>...</uri>
    Do you think I have a problem with my tomcat config or compiling the java class?
    Thanks.

  • Using scriplets in jsp-tag attribute

    I have a strange problem with a custom taglibrary that I'm trying to write.
    When I use the tag in a jsp like underneath the first outputs the right value (Welcome Hans), but the output of the second time shows: Welcome <%= test %>
    This is a part of the JSP:
    <% String test = "Hans"; %>
    <arto:hello name="Hans" />
    <arto:hello name="<%= test %>" />
    I realy don't know how to let the tag display the value of the string in my jsp.
    Can anyone give me some advice?
    Thanks,
    Hans
    The files are:
    import java.io.*;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    public class HelloTag extends TagSupport {
    private String name;
    public void setName(String name) {
    this.name = name;
    public int doStartTag() throws JspException {
    try {
    pageContext.getOut().print("Welcome " +name);
    } catch (IOException ioe) {
    throw new JspException("Error: IOException while writing to client");
    return SKIP_BODY;
    public int doEndTag() throws JspException {
    return SKIP_PAGE;
    The JSP:
    <%@ taglib uri="arto" prefix="arto" %>
    <%
    String test = "Hans";
    %>
    <arto:hello name="<%= test %>" />
    <arto:hello name="Hans" />
    The TLD:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
    "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
    <taglib>
    <tlibversion>1.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname></shortname>
    <uri></uri>
    <info></info>
    <tag>
    <name>hello</name>
    <tagclass>HelloTag</tagclass>
    <bodycontent>empty</bodycontent>
    <info>Tag with Parameter</info>
    <attribute>
    <name>name</name>
    <required>false</required>
    <rtexprvalue>false</rtexprvalue>
    </attribute>
    </tag>
    </taglib>

    In the tld for the name attribute, use
    <rtexprvalue>true</rtexprvalue>
    This specifies that the attribute value can be a run-time expression. Otherwise, the value is taken as a literal.

  • What is the standard on using some jsp tags?

    Has it become an industry standard to not use scriplets, expressions and declarative tags in jsp or is it all dependant on the scale of the application and the preference of the developer. I have seen the arguments for not using these tags and while I can see how they can become problematic for large applications with many developers I never had a problem developing a small application just by myself.
    I would like to know how many of you jsp developers still use these tags and how many don't and your reasons why you do or why you don't?
    I wonder if most people actually see these problems for themselves or do they just join the in crowd because it's the new thing
    And if it is a standard why aren't they just phased out of exiistance. Stuff like that makes it hard for people to learn. I can't tell you how many tutorials i've seen teaching scriptlets and expressions

    I started with scripting, etc. but early on switched to CTLs. They can be bundled and distributed very easily.
    I had read many, many times how hard it was to maintain a site that used a lot of scripting, etc. but gave it only a little heed. Like you, I was a one man show, certainly I could remember what I was doing.
    It didn't take long before I could see that they were right. I immediately ceased what I was doing, repackaged nearly all of the logic into tag libraries (8 in all), redesigned the existing applications to use the tag libraries (which was a pain in the beginning, but worth it big time).
    I am now redesigning our company website to include things like order status, event calendars and a lot of neat web-based stuff. I will have this website done in half the time of our old static html website.

  • Servlet with no dynamic code inside jsp pages

    Hello,
              I saw that a servlet is created even if there is no dynamic code inside jsp pages (scriplets & tags). Is it possible to avoid it on bea side ? (I am using portal 8).
              By the way, do you know if is it possible to define apache in order to avoid to send to bea the jsp which have no dynamic code inside ?
              thank you !

    JSP's always generate a servlet on all web containers. Apache/Tomcat is no
              different. If you have static content, make it an HTML page.
              Bill
              "hournon jc" <[email protected]> wrote in message
              news:22255787.1103297053148.JavaMail.root@jserv5...
              > Hello,
              >
              > I saw that a servlet is created even if there is no dynamic code inside
              jsp pages (scriplets & tags). Is it possible to avoid it on bea side ? (I am
              using portal 8).
              >
              > By the way, do you know if is it possible to define apache in order to
              avoid to send to bea the jsp which have no dynamic code inside ?
              >
              > thank you !
              

  • Using jsp variables within JSP tag

    I have a variable defined within a JSP:
    <%
    String cust_id = request.getParameter("cust_id");
    %>
    I want to use this variable as a parameter to a custom tag:
    <%@ taglib uri="/tlds/DBTags.tld" prefix="db" %>
    <db:MultiColumnSelect columns="c.id, c.po" name="ccar_id" table_name="ccar_headers c, ccar_rmas r" selectString="r.ccar_id = c.id AND c.cust_id = <%= cust_id %>"/>
    The selectString value that is passed to my tag is:
    r.ccar_id = c.id AND c.cust_id = <%= cust_id %>
    The <%= cust_id %> is not replaced by the actual variable value.
    How would I accomplish using this variable within my JSP tag?

    Your definition of the selectString attribute must indicate that it can accept runtime expressions.
    <%
    String cust_id = request.getParameter("cust_id");
    String selectString = new String("r.ccar_id = c.id AND c.cust_id = " + cust_id);
    %>
    <%@ taglib uri="/tlds/DBTags.tld" prefix="db" %>
    <db:MultiColumnSelect columns="c.id, c.po" name="ccar_id" table_name="ccar_headers c, ccar_rmas r"
    selectString="<%= selectString %>"/>

  • Using expressions in jsf tags

    I have a problem with using expressions in jsf tags! I know this
    topic was discussed before but it doesn`t work.
    I want to use the following jsf-code:
    <h:panel_data id="tab" var="vari" modelReference="Bean.varis">
    <h:output_text id="Id" modelReference="vari.id"/>
    <h:command_hyperlink id="hyper" href="next.jsp" label="Detail">
    <f:parameter id="Param1" name="id" value="vari.id"/>
    </h:command_hyperlink>
    </h:panel_data>
    The value of the parameter should have the value of vari.id!! Why doesn`t it work?? I also tried to use value="${vari.id}" and value=<%= vari.id %>.
    I have also changed the jsf_core.tld from
         <rtexprvalue>false</rtexprvalue>
    to
         <rtexprvalue>true</rtexprvalue>
    Does anybody know what to do? Where should the .tld-files be localized when i deploy the webapplication??

    On May 19th, 2003 HydraD == "HD" wrote:
    HD> I have a problem with using expressions in jsf tags! I
    HD> know this
    HD> topic was discussed before but it doesn`t work.
    HD>
    HD> I want to use the following jsf-code:
    HD>
    HD> <h:panel_data id="tab" var="vari" modelReference="Bean.varis">
    HD> <h:output_text id="Id" modelReference="vari.id"/>
    HD> ...
    HD> <h:command_hyperlink id="hyper" href="next.jsp" label="Detail">
    HD> <f:parameter id="Param1" name="id" value="vari.id"/>
    HD> </h:command_hyperlink>
    HD> </h:panel_data>
    HD>
    HD> The value of the parameter should have the value of
    HD> vari.id!! Why doesn`t it work?? I also tried to use
    HD> value="${vari.id}" and value=<%= vari.id %>.
    HD>
    HD> I have also changed the jsf_core.tld from
    HD>      <rtexprvalue>false</rtexprvalue>
    HD> to
    HD>      <rtexprvalue>true</rtexprvalue>
    HD>
    HD> Does anybody know what to do? Where should the
    HD> .tld-files be localized when i deploy the
    HD> webapplication??
    If you want your parameter's value to be pulled from the model, you must
    use modelReference instead of value. Try that and see if it works.
    Ed

  • Regular expressions using jsp

    Hello Techies,
    I am having a text area inside a jsp file. When ever the end user gives input it must be submitted to the server.
    The real problem is when the end user gives special characters and double-quotes in this text area, jsp is preforming in abnormal way.
    Can u guys tell me how to resolve this issue. i.e how to solve regular expressions in jsp.
    Even though the end user gives special characters or double quotes we should take only the content.
    Looking forward for u reply.
    regards,
    Ramu

    The real problem is when the end user gives special characters and double-quotes in this text area, jsp is preforming in abnormal way.What do you mean with "jsp is preforming in abnormal way" ?
    A arbitrary JSP does not care about double-quotes.
    Can u guys tell me how to resolve this issue. i.e how to solve regular expressions in jsp.Usually the same way as you do it in a poj class.
    Nobody here knows how your JSP looks like and who handles the request when the form is submited or even who generates the model of the data displayed by your JSP.
    You have to provide us with more details.

  • New JSP Tags in WLS 7

              Hi!
              Can someone summarize for me additional custom WebLogic JSP tags available in
              WLS 7, compared to WLS 6.1 or changes in functionality of existing custom WebLogic
              JSP tags from WLS 6.1 to WLS 7.
              Thanks,
              Rahul.
              

              I am afraid not. Becuase if you don't buy their product, they even don't let you use their classes of that product.
              I tried to use a class inside CommerceServer, but they asked for the license all the time.
              My suggestion is you can get some idea from that, but don't use it directly except you have their license.
              "KhurramZ" <[email protected]> wrote:
              >Hi all,
              >Am experimenting with WL server 5.1 (eval version) and ejbs,jsp's.
              >Also came across documentation of JSP Tag libraries of WL personalization
              >server (in BEA website). (like <pz:..> , <cm:..>, <es:...>)
              >
              >Can I use those WLPS jsp tag libs in WLserver? Though I havent got WLPS ,and
              >in fact will not be using it in future.
              >
              >Thanx in advance
              >Khurram Z
              >[email protected]
              >
              >
              

  • JSP tag extention  problem

    All,
    We have jsp code:
    <olr:pageNavigator href="<%=href%>" ccsClass="text" />
    It works with SP2, but not with SP3. SP3 does not process <%=href%>,
    instead, it pass string <%=href%> itself to the Tag class.
    It is a bug !!

    This isn't legal JSP syntax. If the SP2 compiler let you get away with
    it, it shouldn't have. (This sp3 compiler is much more strict than the
    old compiler.)
    The error is more obvious when you look at the code in XML syntax:
    <olr:pageNavigator href="<jsp:expression>href</jsp:expression>
    ccsClass="text" />
    Just try to get that one through an XML validator. So the bug is not in
    iAS, it's in your code !! :-)
    Seriously though, the right thing to do would be to write your custom
    tag library so that it looks like this:
    <olr:pageNavigator ccsClass="text">
    <olr:NavigatorHREF>
    <%=href%>
    </olr:NavigatorHREF>
    </olr:pageNavigator>
    David
    default wrote:
    All,
    We have jsp code:
    <olr:pageNavigator href="<%=href%>" ccsClass="text" />
    It works with SP2, but not with SP3. SP3 does not process <%=href%>,
    instead, it pass string <%=href%> itself to the Tag class.
    It is a bug !!

  • Why does people use JSP Tag for their JSP page? (Urgent)

    I don't know what benifit if I am using JSP Tag.
    If anyone knows, pls give me an idea and the advantage of using JSP Tag in JSP Page!
    Thanks in advance!

    You have to read a little about JSP, JSP stands for JavaServer Pages, you can use jsp tags and you can use java code. If you dont want to use jsp tags then you should just write html file, if you just want to use java, then write java class or a servlet.
    The need for jsp arised because people were inserting html code inside a servlet class..a big no no..and a headache. JSP separate model from the view...read a little about MVC-2 model view controller pattern.
    Also read some tutorial on this website...good luck
    K

Maybe you are looking for