"dynamic" String concat in Expression language

I would like to do something like (in Java)
String s = flag? "this" : value + "that";in EL it would be #{flag ? 'this' : value + 'that'} but this leads to an error because it tries to add as numbers and not concat as strings.
how can I do this?
thanks

maurozoom wrote:
thanks
I've been googling for the whole day with no answer.You are terrible at it then.
>
I think there's no solution for my problem in ELHere are two search results which contain solutions to your problem from the search I posted:
http://www.velocityreviews.com/forums/t133287-el-concat-strings.html
http://marc.info/?l=myfaces-user&m=114123737923937&w=2

Similar Messages

  • Simple question - compare Strings with SSIS expression language

    SSIS variables - strOne = YES, strTwo = YES. I want to compare strings using ssis expression language (ie inside a variable's expression box, constraint of task flow arrow etc).
    Will @strOne == @strTwo be true ? I hope its not like programming languages where you need to do
    @strOne.Equals(@strTwo) instead of ==. Also is @strOne == "YES" true ?

    ([User::strOne] == [User::Strtwo] ? True : False)
    The third variable created should be of type boolean if you're using above expression. if its of type int return 0 and 1 instead of False and true
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Text/expression-language-based paradigma continues?

    i've been working with jsp and struts for a while. the most significant drawback of jsp, custom tags/jstl and struts is its "runtime" binding caused by the heavy use of string-attributes and interpreted expressions.
    it makes the coding itself harder (loss of compiler support and strong typing), it increases the amount of testing (automated tests, regression tests) extremely, it makes jsp-apps very hard to mantain, it is error-prone when changed or refactored, it is slower in execution and last but not james requires extra developement tools (such as struts-editors) to effectively maintain the applications.
    but i like the paradigma of a web application that keeps a view state, handles "events" etc.
    the only thing i can't understand is why jsf builds on the error-prone jsp/custom tag paradigma instead of compiled server side ui components. it obviuosly still tries to follow the myth, that web-designers and application developers can share their source (i.e. js-pages) by using tags. imo this is a degeneration of the good idea to leverage html by some custom tags. these tags empower designers to make their pages dynamic. (enterprise) software developement ist very different: complex use cases, business logic and often ui-"logic", integration issues etc...
    the life cycle of a jsp with custom tags is weird (even more in struts):
    - objects (variables in scriptlets) already existing in the scope of the jsp-execute-method are wrapped into attributes of page, request or application scope.
    - tags are defined using string-based attributs, such as <html:write name="pinky" property="brain" />
    - the implementation of the tag tries to look up the object in any of the scopes, starting with page scope
    - if the object exists, it tries to read/set its property via reflection
    so you lose strong typing, compile time checks and performance.
    there are several frameworks that do not build upon jsp and tags but put in an extra layer. this layer is similar to a rich client "form" and renders the output into html or any other format.
    so i'm not preferring any framework, just looking around and curious why this architecture has been chosen for jsf.
    thanks
    tom

    the most significant drawback of jsp, custom tags/jstl and struts is its "runtime" binding
    caused by the heavy use of string-attributes and interpreted expressions.I second this heartily.
    but i like the paradigma of a web application that keeps a view state, handles "events" etc.
    the only thing i can't understand is why jsf builds on the error-prone jsp/custom tag
    paradigma instead of compiled server side ui components. The JSF - JSP connection is a major problem. More and more developers are starting to express reservations about it, because the two technologies don't play well together. But I think you've hit on an even deeper fundamental flaw in the equation -- the evils of runtime binding. The heavy JSF/JSP reliance on runtime evaluation is a reliability nightmare. Developers choose Java, in part, because of the robustness provided by compile-time checking. We give that up when it comes to JSF/JSP or Struts web applications, and that's an unacceptable state of affairs.
    Winer says that "JSF has taken a major step in the right direction with the <managed-bean> and <referenced-bean> configuration elements. These give some hope for development tools to finally provide real code insight (and even error reporting) for EL expressions, because they define both what keys are used in the expression language and what types of objects may be at those keys." However, this will help with only the simplest EL expressions. As soon as an EL expression reaches into nested properties and maps that aren't defined in the config file, we're back to runtime binding and error reporting. The addition of generics to the language with 1.5 might have made it possible to introduce strong EL type checking at page compile time, but Sun's short-sighted type-erasure implementation of generics rules this out permanently.
    Look at what Microsoft is doing with ASP.NET. It's not perfect, but the fundamental technology is based on compiled server side ui components. There are places in that framework where you can write expressions aren't evaluated until runtime, but it's certainly not the fundamental basis of the model as it is with JSF/JSP. And the .NET implementation of generics may make it possible to have these dynamic expressions type-checked at page compile time in a future implementation of .NET.
    I keep reading comments from the JSF proponents who say things to the effect of "yes, we know JSP doesn't play well with JSF, but JSF allows you to plug in a different rendering technology." Well, we need one, and we need it urgently. ASP.NET has been out for two years now, and was far more polished and useable at its release than JSF is now after a very long development cycle.
    Rightly or wrongly, people will judge JSF on the merits of the reference implementation. And I fear that a lot of developers are going to throw up their hands after a taste of the JSF/JSP world and move to .NET.
    Stephen Schaub

  • Dynamic execution of boolean expression

    Hi folks,
    I want to execute a boolean expression dynamically, can you pls help me how to do it.
    For example,
    String str = " ( X & ( Y | Z ) ) " ;
    They value of X , Y or Z will be either true or false.
    After replacing their value, I will get string as follow
    String result = "( true & (false | true ) ".
    Now I want to execute the String as boolean expression in order to get
    a result as a true or false.
    So, i need a solution to implement this. The expression may be simple or compound . It is so urgent waiting for your reply.
    Appreciated if you provide sample code.
    Thx !
    With regards,
    Rahul

    Java is a compiled language (well, strictly, a semi-compiled language.) This means that stuff like parsing expressions only happens at compile time. Variable names don't exist at run time, neither does the code which analyses expressions.
    If you really need to do this kind of thing, therefore, all the code for parsing these expressions has to be a part of your program, and stuff like values for variable names will have to be set explicitly by your program, not in regular variables but in variable list for the "scripting engine" you invoke.
    You can either write your own expression analyser (not a trivial task if you haven't done it before) or you can search arround the web for one someone else has written and find out if it covers your requirements. BeenShell has been suggested. Find it on the web and study it's documentation.
    Incidentally when the new release of Java comes out it will include serveral such "Scripting engines" for languages like JavaScript or Jython, and such things will be less hastle.

  • Expression language

    Hi,
    I need some help on clarifying the expression language. I have this code
    <h:outputText value="variable"/>I want to replace the variable with a value from the database. How can I do this using the expression language? Or do I need to use the JSP scriplet and call a bean function?
    clarenceloh

    Basically:<h:outputText value="#{myBean.variable}" />MyBeanprivate String variable; // + getter + setter
        loadVariable(); // Can also use constructor or static block for this.
    private void loadVariable() {
        variable = getVariableFromDatabaseSomehow();
    }

  • Calling dll-library using Oracle Express Language

    I call my dll-library from Express Language 6.32, but it can't locate my library function.
    How can I create a dll-library, suitable for Express.
    btw, creating dll I used EXTCALL.c example and I have done all in such a way as in this example. -- but... :(
    Please give me advice,
    Thanks for listening.

    tbd wrote:
    Hi rkpat,
          You might check-out this thread on building WIN32 DLLs - expecially the bit re: "mangles names" under the paragraph titled "C Language Source File".  My recollection is that 'extern "C"' directive in the header file for the DLL solved the name-mangling problem, but it's been a few years!
    Cheers!
    Message Edited by tbd on 03-01-2007 11:19 PM
    tbd is right. You have to first disable name mangling as it creates all kind of troubles. Other issues might be that your Visual Studio 2003 or .Net edition links in dynamic runtime libraries that are not standard available on every Windows PC so that you need to redistribute the according runtime library installer together with your app for the DLL to be even loadable.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Dynamic equivalent of the Java language CAST operator

    Hello,
    Here is what I want to do:
    I have an Object that contain "something" (I don't know at compilation time). And I want to do this call:
    Object myObject = new String("Hello");
    myMethod (myObject);
    having declared these:
    public void myMethod (Integer dInt);
    public void myMethod (String sString);
    I want the second method to be called. How can I do that?
    I'm looking for something like a dynamic equivalent of the Java language cast operator:
    ??? myMethod ( (myObject.getClass())myObject ); ???
    or ?? myMethod ( (myObject.castTo(myObject.getClass()) ) ; ??
    Thanks.

    How 'bout using the instanceof operator?
    Like this:
    public myMethod(Object obj)
    if (obj instanceof String)
    //do String stuff
    else if (obj instanceof Integer)
    //do Integer stuff
    }

  • Dynamic string array

    I need to make a dynamic string array.
    Deeper explanation:
    I am trying to use a FOR loop to send a series of commands to an 8-channel device.  Each channel requires 7 (actually, 1/2 need only 5, the other 1/2 need 7) strings to set them up and the entire sequence needs to be performed 8 times.  I started a test .vi by simply using a constant array of type sting.  I can sequentially pick each string and program my device perfectly.  Now I'd like to do things like add the channel # somewhere in the mix, use variable values based on other controls in my .vi to set the parameters of the channel.
    EXAMPLE:
    The user sets certain values that determine delays and width for an 8-channel DDG (Digital Delay Generator, to some, a pulse generator).  These values then need to be loaded into the DDG.  The Strings will look something like this:
    ULSE1TATE 1
    ULSE1:WIDTH 0.009 000           *NOTEpaces behind decimal are for better viewability only
    ULSE1ELAY 0.000 000
    ULSE1YNC T0
    ULSE1:CMODE DUTY
    ULSE1COUNTER 1
    ULSE1:BCOUNTER 1
    ULSE2TATE 1
    ULSE2:WIDTH 0.000 300
    ULSE2ELAY 0.008 700
    ULSE2YNC T0
    ULSE2:CMODE NORMAL
    So widith and delay params change, the pulse# changes, and whether it's on certain channels decides if the mode is duty or normal and duty comes with the subsequent params pcount and bcount.
    help?
    PS - I am going to move the state, sync, and cmode to a common, initialize loop run only at program start, but I still need to use width, delay, and (variably) pcount and bcount.
    PPS - I am trying to edit post to diable smilies.  Commands should read:"colon, P (or D)" not ,
    PPPS - Success, at least for me.  I disabled smilies in my settings, I don't know if that means my posts won't show smilies or if just what I am looking at won't show smilies, any responders let me know how it's showing for you.
    Message Edited by Radiance_Jon on 07-16-2007 01:48 PM
    Message Edited by Radiance_Jon on 07-16-2007 01:52 PM

    smercurio_fc wrote:
    Well, in my experience I have found that dealing with errors early on is the best course of action as it leads to less headaches down the road...
    Auto-indexing is one of the more powerful features of LabVIEW. If you're familiar with text-based languages it's equivalent to the "foreach" statement. Basically it allows you to wire an array into a for-loop and the size of the array tells LabVIEW how many times the loop needs to execute. Inside the loop LabVIEW peels of each element of the array in order for each iteration of the loop. Looks like this:
    My comment regarding not needing the sequence frame was related to using the error cluster since that wire would allow you enforce data dependency like so:
    Note that the VISA resource wire does the same thing.
    "I got a little aggravated at how NI seemed to handle the loops in those two frames concurrently".  That's because LabVIEW is a data-flow language, and not a sequenced language like C or VB. In fact, that's one of the things that makes LabVIEW so powerful.
    Message Edited by smercurio_fc on 07-16-2007 04:48 PM
    MAN!  I KNEW that!!!!  GGRRRRR!!!  That makes sense.  Actually that's WHY I connected the error lines in the first place was to aide in flow control.  OH!!!  Still getting used to LabVIEW. 
    But I still have a question related to flow control.  Check out the pic below.  LabVIEW runs everything in a seemingly random order... well at least where it STARTS each chain of data.  It obviously starts with the static constants or the earliest data in each chain, but I can't figure out how in the world it's deciding WHICH chain to start first.  It kind of seems to go with the lower right and work it's way to top-left, but it doesn't exactly do that either.  I dunno if it's worth you answering this concern or not, but if you got one for me I'd be much obliged. 
    I should take a LabVIEW class!  Yeah right, as if they'd let me... R&D means I won't need it tomorrow ;( which stinks cause I'm liking LabVIEW the more I learn it.  (I was not fond of it in the beginning, but that was my stubborness). 
    thanks again so much for all your help!!!!
    Also, I am using all those strings to make my display appear as I want it to... I wonder if there is another way?  I am aware of system labels, but I like the look of the recessed, grayed control boxes better.
    Message Edited by Radiance_Jon on 07-16-2007 05:06 PM

  • Expression language oa.current.FieldName meaning?

    I've seen this in existing codes property inspector window
    ${oa.current.FieldName}.The syntax closely resembles that of jstl
    I only know the format to display the attribute of the current row of the given VO:
    ${oa.SomeNameVO1.voAttribute}What does oa.current mean?
    Where can I get more information about the different objects available in this expression language?
    Help is much appreciated.

    Hi,
    Refer PPR and Tables of the developer guide.
    You can also fire row-level PPR events for items in a table, including advanced tables and table-in-table. First and foremost, configure the items as described above.
    Note: If you are working with a table-in-table or HGrid that uses view links, you need to modify your SPEL syntax as shown: ${oa.current.viewAttrName}. The inclusion of current keyword lets you say "get the value from whatever row BC4J is using to render the current row" since you won't know how to access the view
    objects and row sets created dynamically for these complex components.Regards,
    Gyan

  • Problem in accessing object using Expression Language

    Hello All,
    Im using Tomcat 5.5 and I am learning Expression language.Im using one servlet page as login.java i.e,
    package common;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import Database.DatabaseObject;
    import valueobjects.login1;
    public class login extends HttpServlet {
         public static final long serialVersionUID = 8707690322213556804l;
         public void doPost(HttpServletRequest req, HttpServletResponse res) {
              String name = req.getParameter("username");
              String password = req.getParameter("password");
              RequestDispatcher dispatch = null;
              ResultSet rs=null;
              Statement st=null;
              login1 log=null;
              Connection con = null;
              String sql=null;
              try
              con=new DatabaseObject().getConnection();
              st = con.createStatement();
              sql="select * from login";
              System.out.println(sql);
              rs=st.executeQuery(sql);
              while(rs.next())
                   log=new login1(rs.getString("User_Name"),rs.getString("user_Password"));
              req.setAttribute("login",log);
              req.setAttribute("username",name);
              req.setAttribute("password",password);
              dispatch = req.getRequestDispatcher("/jsps/el.jsp");
              dispatch.forward(req, res);
              catch(Exception e)
                   e.printStackTrace();
    That login1 customized object is set as ,
    package valueobjects;
    public class login1{
         String Name;
         String Password;
         public login1(String name, String password) {
              super();
              // TODO Auto-generated constructor stub
              Name = name;
              Password = password;
         public String getName() {
              return Name;
         public void setName(String name) {
              this.Name = name;
         public String getPassword() {
              return Password;
         public void setPassword(String password) {
              this.Password = password;
    then im using one jsp as el.jsp that is,
    <%@ page isELIgnored="false"%>
    <%@ page import = "java.util.*,valueobject.*"%>
    <html>
    <jsp:useBean id="login" class="valueobjects.login1">
    <jsp:setProperty name="login" property="name" value="username"/>
    <jsp:setProperty name="login" property="password" value="password"/>
    </jsp:useBean>
    <body>
         <center>
         username=${login.Name}<br><br>
         </center>
    </body>
    </html>
    but when i execute this code it is giving error as
    /jsps/el.jsp(4,0) The value for the useBean class attribute valueobjects.login1 is invalid.
    But that login1.java is in correct package that is valueobjects.but im not getting why it is giving such error.Plz help me.

    hi
    to use java bean u MUST follow the two conviosions:
    1. the class u want to make a bean from it must have no-argument constructor
    2. u must provide setter and getter for every instance variable , the name of instance varible must begin with small letter and its setter and getter must be like setXxx() and getXxx()
    the correct bean is :
    package valueobjects;
         public class login1{
         String name;
         String password;
         public String getName()
                   return name;
         public void setName(String name)
                   this.name = name;
         public String getPassword()
                    return password;
         public void setPassword(String password)
                    this.password = password;
         }where is my duke's $ ???

  • Question about expression language

    Hello,
    I have a question about expression language - is it possible to access one variable using abother EL as variable name? For example?
    ${applicationScope[${sessionScope.project.name}]}Or is there any other way of achieving that?
    Thanks a lot for your help
    Cheers,
    Maciej
    Edited by: swider on Oct 29, 2008 2:12 AM

    I ran some other tests and I found out that following expression does not return value:
    ${applicationScope[sessionScope.project.aclId]}but this one is working
    ${applicationScope[sessionScope.aclId]}It is very strange. Project class ia simple JavaBean, has two members (Long and String).
    Any ideas what can be wrong with that?
    Cheers

  • Expression Language - Beyond binding (mini-tutorial)

    Expression Language - Beyond binding (mini-tutorial)
    Creator has a binding logic that is very easy to use. You right click on a component and choose which properties to bind onto your backing beans. Then you manipulate the backing bean property to change the bound property of your component. Or users input information into your app and the component writes through that input to your backing bean. It's cool.
    But sometimes you find yourself binding things to other things and you wonder if this is the simplest way to do things. A classic example is the old "how do I highlight a row of this table based on some datafield?" question. This has been answered by Tor Norbyte and the method works but to me it looks a little disjointed and clumsy.
    The classic solution involves binding your tableColumn's style property to a String type bean. Then inside the bean you write the logic that selectively returns a "background-color:'yellow'" string or something similar (Tor used css). The problem is that within the bean you still need to figure out what is the current row of your table. To do this you need to invoke and EL expression from the Java code which, if you were trying to avoid EL, is circular logic. Worse still, imagine you want to color columns separately.
    Here's an alternative solution using only Expression Language. It's self contained, easy to debug and maintain and once you've taken a look at it is pretty simple.
    Here's the JSP tag that does this:
    <ui:tableColumn binding="#{myHomePage.tableColumn7}"
    headerText="Expired" id="tableColumn7" 
    style="#{currentRow.value['expired']>0?'background-color: red':''}">To make it work I had to manually type the expression in the JSP file. The property editor will work with some EL statements but not all. Sometimes it mangles your EL expression and this can take a bit of debugging. <tip>Use the JSP editor...</tip>
    The bit I had to manually type is this:
    style="#{currentRow.value['expired']>0?'background-color: red':''}"All it does is check if some field in my TableRowGroup called 'expired' is greater than zero and if so highlight the cell. The construction is #{[condition]?[true value]:[false value]}
    You can also mix text and expressions in an EL expression:
    <ui:staticText ....  text="#{SessionBean1.userName}'s Home Page"/>If "Milo" is logged in he'll see "Milo's Home Page" where I placed this static text component.
    Here's an example I've got that's part of a Button tag in my JSP:
    visible="#{currentRow.value['d2.ReplacedBy']!=null}"In this case I don't want users pressing the button if the field is null, so I hide it for rows where the field is null.
    Bean or EL?
    Well strictly speaking it's not either or! In order for a Bean to be bound to a component you need an EL expression! So the question is do you implement you logic in a bean or an EL? Well that's pretty easy -- if the logic is simple and can be expressed in one line then use an EL only. Advantages: less dependencies and Bean properties floating around. If the logic is more complex use a backing bean and simple binding.
    More to explore
    Tor's blog entry:
    http://blogs.sun.com/roller/page/tor/20050113#creator_how_to_highlight_specific
    Winston's Blog entry
    http://blogs.sun.com/roller/page/winston?entry=setting_table_column_style
    [How do I add row numbers to a table?]
    http://forum.sun.com/jive/thread.jspa?threadID=112916&tstart=0
    [How do I use EL to bind to an Object's public property or field?]
    http://forum.sun.com/jive/thread.jspa?threadID=112434&tstart=0
    Addendum 1-Dec-06 Highlighting every 2nd row in a table
    The above thread on how to add row numbers to a table also exposes a pretty simple method to highlight every nth row in a table (a fairly common request)
    Something like this should work:
    <ui:tableColumn ...... style="#{currentRow.tableRow.rowId%2==1?'background-color: yellow':''}">Message was edited by:
    yossarian

    Hi Yossarian,
    Thanks for posting the simple but elegant solution. I liked the solution.
    To make it work I had to manually type the expression in the JSP file.
    The property editor will work with some EL statements but not all.
    Sometimes it mangles your EL expression and this can take a bit of
    debugging.Please file a bug against this at
    http://www.netbeans.org./community/issues.html
    Use visualweb as the sub category.
    Thanks
    - Winston
    http://blogs.sun.com/winston

  • Expression language Calling Map

    Hi Expert,
    I am trying out the following in the expression language.
    #{pageFlowScope.manageSecurityMB.dataMap[ 5]}"
    where the dataMap is a map in the backing mean. It is working fine. However i would like to change the key (in this case the 5 ) with another expression. How can i code that in expression language.
    looking forward ur suggestions.
    - t

    Hi,
    If you pass in an expression then the only way to get this working is to resolve the passed in EL string in the HashMap bean as part of the get(key) method
    Frank

  • Help needed in JSP Expression Language

    Hi all,
    I have been working for JSP Expression Language Sample execution since past 5 days. I am using the application server as "Jboss Server" and web server as "Tomcat".
    I have been included the jsp-api.jar file in my lib directory of application server as well as source folder's lib directory.
    When i am trying to build the source code, i am getting this build error.
    [javac] D:\eclipse\workspace\esolvProject\development\src\com\esolv\taglibs\
    web\classes\SetSupport.java:186: cannot resolve symbol
    [javac] symbol : method getExpressionEvaluator ()
    [javac] location: class javax.servlet.jsp.PageContext
    [javac] ExpressionEvaluator evaluator = pageContext.getExpressionEvaluator();
    In my jsp-api.jar , there are two classes called,
    PageContext and JspContext, Both are abstract classes.
    PageContext inherits JspContext class. JspContext class have the method getExpressionEvaluator() , returns ExpressionEvaluator.
    PageContextImpl - class . it has been called internally when we are trying to call PageContext class. In PageContextImpl class, there is one comment before, the method's definition. that is
    " Since JSP 2.0 "
    But we have the JSP 2.0 version. But it won't work.
    Please help me ont this.
    Thanks in Advance,
    Natraj

    >
    If the pblm was due to setting the classpath.
    The error should be showed for all files in the jar
    file.
    why i am getting the error for particular method ?
    it is accessing the other methods of same class
    'JspContext' . but it is not accessing that method.
    Thats my question.
    Just check that your .jar file is 2.0 compliant and that you do not have any other jars(for servlet or jsp api) in the classpath.
    Probably you have an older version of .jar file in your path. So the errors will appear only for those methods that have been added since 2.0, all other methods would compile fine.
    Please tell me the jar files to work out the
    expression language. so that i can cross check my
    list of jars.Hmmm...I dont use jboss. In tomcat the jar file name is jsp-api.jar. But it would have been the same even for jsp1.1, going by jar file names wouldnt help. Just look at your cp as if with a microscope to identify redundant jars.
    cheers,
    ram.

  • String concat PROBLEM??? Please Help

    I have this strange Question regarding String concat
    If I say:
    String str = "Welcome";
    str.concat(" to Java");
    System.out.println(str);
    The output is: Welcome.
    How do I get the output to Welcome to Java??

    I have this strange Question regarding String concat
    If I say:
    String str = "Welcome";
    str.concat(" to Java");
    System.out.println(str);
    The output is: Welcome.
    How do I get the output to Welcome to Java??
    The problem is that String is immutable, The String you have held in str does not change, rather a new Srtring is returned. So all yo have to do is grab the new String
    str = str.concat("to Java");
    or use the new String without keeping it.
    ie
    System.out.println(str.concat("to Java"));

Maybe you are looking for