How do I concatenate strings in JSF expressions (EL)?

So I want to do something like:
<h:outputText id="foo" value="msgs['label.' + prop]" />
"prop" is a variable involved in a loop using a dataTable. It'll have a string value like "firstName" or something. 'msgs' refers to a resource bundle initialized earlier in the JSP.
The above line doesn't work because in JSF, the plus(+) symbol is only for arithmetic and so, exceptions get thrown.
How do I do the equivalent of the above? I can rename my resource bundles to not have the 'label.' prefix, but there's got to be a better way.
Any help one can give would be great. Thanks!
Jimmy Ho

I'm not sure I understand. I have no database interactions. The things I'm trying to concatenate to ".label" is just some list of strings I get from a properties files somewhere in my code.
Ahaaaa, not what I understood...somehow :) sorry
I can see how I can change each String to some Foobar object where I can do blah.label and blah.value, and make that work, but creating a whole new class seems excessive. Is there another way?
I dont know if there is straight forward one, just like + with strings, another idea is to open the properties file and read the strings you need and append to the .label...if that makes any reasonable sense

Similar Messages

  • How to use Type Casting in JSF Expression Language

    I have an attribute CategoryId in my VO of type oracle.jbo.domain.Number. I am trying to use the expression of Boolean item in JSF as #{row.CategoryId != 4}
    Here is the JSF code:
                          <af:column id="s141NewItem3Col" noWrap="true" width="100"
                                     rowHeader="false">
                            <f:facet name="header">
                              <af:outputLabel value="CAtIDDeq4" showRequired="false"
                                              id="ol18"/>
                            </f:facet>
                            <af:inputText id="s141NewItem3"
                                          value="#{row.CategoryId != 4}"
                                          label="CAtIDDeq4" required="false"
                                          readOnly="#{((pageFlowScope.ContractRightCategoriesTable.newRow) and (!(jhsUserRoles['RM, ADMIN, AllButTitl, AllButAdmn']))) or ((!pageFlowScope.ContractRightCategoriesTable.newRow) and (!(jhsUserRoles['RM, ADMIN, AllButTitl, AllButAdmn'])))}"></af:inputText>
                          </af:column>I am getting the run time exception as "Can not convert 4 of type class oracle.jbo.domain.Number to class java.lang.Long".
    I am wondering how the row.CategoryId is treated as Long?. PLease advise. Also, will I be able to use type casting expressions in JSF Expression Language?
    Thanks, Pradeep

    use attributeValue
    Try *#{row.bindings.CategoryId.attributeValue != 4}* ?
    Check this thread for details which discusses about the same:
    El expression to disable  or enable
    Thanks,
    Navaneeth

  • How to split a string around "." expression

    My code is:
    public String removeExtn(String resource){
              String[] splittedName = resource.split(".");
    System.out.println("LENGHT IS: "+ splittedName.length);
              if(splittedName.length >= 3)
                   resource = splittedName[0]+ "." + splittedName[1];
              return resourceName;
         * @param args
         public static void main(String[] args) {
              Test obj = new Test();          
              System.out.println(obj.removeExtn("myfile.xml.sample"));
    But it doesn't split the string around "." and given the arraylength 0. But if I try to use any another character (e.g. "," or ";") it works perfectly fine.
    Please help me.
    Thanks in advance.
    Mansi

    Hi mansi,
    I had a same kind of problem a few days back.
    What I learned was the split() method has a string expression in it, which is usually noted as regex .
    'Regex' is just a short form for 'regular expression'
    You may directly use the string variable you would split around in some cases or may want to use a '\\' before some of the characters.
    I can't place whole information here .So, let me give you that sun site link I read it from.
    This link deals with the whole string class.
    You may want to ctrl+F and split to read on split method.
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.htmlThis link talks about the regular expressions
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html#sumI got his for you from that link :
    \p{Punct} Punctuation: For One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ This is for your knowledge.
    And if you want a quick fix just for your code...
    that'ld be using a
    split(\p{.}) in place where u used a split(.)I have not tried that ...but u may want to!
    Hope that helps.
    Message was edited by:
    Kishorei20
    Message was edited by:
    Kishorei20

  • How to split a string with regular expression

    Hi.
    I need to split a string with a regular expression.
    Example
    String = "this is; a test";rune haavik;12345;
    And I want the output to be:
    "this is; a test"
    rune haavik
    12345
    If I use this code:
    private void test1()
    String str = "\"this is; a test\";rune haavik;12345;";
    int i=0;
    String[] tmp = str.split(";");
    while(i<tmp.length)
    System.out.println(tmp);
    i++;
    Then it splits also in the "" text.
    Regards
    Rune haavik

    Rune haavik:
    The most effective way to achieve the end result is, I believe, to read the characters one by one, using a flag that indicates if we are inside quotation or not.
    Well, if we are in a mind game, then the following should do.
           String[] tmp = str.split(";(?![^\"]*\";)");

  • How to concatenate string with a numeric control ?

    Hi,
    How to concatenate string with a numeric control ?
    Thankyou.
    Solved!
    Go to Solution.

    Its simpler to just use the Format Into String.
    Attachments:
    Format Into String.png ‏11 KB

  • Some strings for which expression pedal is used is recorded well but during esch playback I have to move the modulation wheel. How can I resolve to hear my instrument during playback without twikking on the wheel !

    Some strings for which expression pedal is used is recorded well but during esch playback I have to move the modulation wheel. How can I resolve to hear my instrument during playback without twikking on the wheel !

    I am having the same problems. My guess is that a lot of people are having the same problems and just living with it. Those of us who know where to go on the Internet come here to find a fix.
    It seems Verizon has some explaining to do. Maybe they should try Beta testing new software a little better. I would rather have to wait longer for something that works. I am sure that some manager or director said this is close enough, deploy it and we will see what happens. Well, you are seeing the problems. Time to fix your mistake.
    All of us are telling our friends about the problems. The longer this goes on, the more people we will tell about it.
    Wouldn't you rather us be telling our friends that their is an error in the new interface and that you are working hard to fix it?
    If you want to be up front about this, then just tell us. We are adults and can handle it. If you made a mistake, own up to it and give us some credit for doing your Beta testing in the field.
    Customer Service is all about telling the truth and if you made a mistake, admit it and lets move on with a fix. I do not want to be told again that I should be able to unplug it, power cycle it, try the on-board diagnostics, etc., etc.......
    I am going to be repsonding on a daily basis to keep this topic at the top of the list.
    Time to come clean. You will feel better Verizon.
    Let's talk tomorrow.

  • How to Concatenate Strings in XI !

    Hello..
    I have the scene RFC - XI - JDBC
    insert in SQLServer tables... when i insert in last table i have one proble with concatenate Strings.
    This is the error ocurred in my message monitor:
    Unable to execute statement for table or stored procedure. 'TLINES' (Structure 'statement_TABELA4') due to java.sql.SQLException: [SQLServer 2000 Driver for JDBC][SQLServer]INSERT statement conflicted with TABLE FOREIGN KEY constraint 'FK_TLINES_CRFV'. The conflict occurred in database 'tmp_rfc', table 'CRFV'.
    the problem is refering to TABLE FOREIGN KEY !
    This is the message come from XML:
    I need to concatenate the field TDLINE to insert the Data in only one line in the table because the TABLE FOREIGN KEY relationship !!!
    My question is:
    How to cancatenate the Field TDLINE ??
    thanks...
    Regards...
    Boni

    Hi Vijaya Lakshmi,
    Sorry for delay my response. Thanks for your reply.
    My Input structure is complex structure. here is the example
    Source Structure
    ZEmployee
      Data
         Employee first name
         Employee Last name
         Employee number
         Employee Joining date
         Employee Joining time
         Lines
            Tdline.
    Target Structure is
    ZEmployee
         Employee first name
         Employee Last name
         Employee number
         Employee Joining date
         Employee Joining time
         Employee Notes
    In my scenario i need to concatenate all the TDLINES and pass to Employee Notes in the target for each employee. How to triger UDF for this scenario and I need to change any mappings.
    your help is highly appreciated.
    Regards,
    Srini

  • How to use ternary operator in JSF using EL expression

    how to use ternary operator in JSF using EL expression

    I want to use ternary operator for h:datatable columnclasses attribute like as below
    <h:datatable
    columnClasses="#{booleanExpression ? style1,style2 : style3,style4}"
    />
    But it's not working.Is there any other alternative to do this?

  • Tip : resolve JSF expressions at runtime

    hi
    Sometimes it might be useful to be able to take a look into your application at runtime.
    One way to do this, is to pass JSF expressions into your application and see how they get resolved.
    The simple ExpressionResolver bean and expressionResolver.jspx page below enable you to do this.
    (*) the ExpressionResolver class :
    package view.util;
    import javax.faces.application.Application;
    import javax.faces.context.FacesContext;
    import javax.faces.el.ValueBinding;
    public class ExpressionResolver
         private String fExpression = null;
         private Object fExpressionResult = null;
         public String resolveButton_action()
              FacesContext vFacesContext = FacesContext.getCurrentInstance();
              Application vApplication = vFacesContext.getApplication();
              try
                   ValueBinding vExpressionVB =
                        vApplication.createValueBinding(getExpression());
                   setExpressionResult("unable to resolve expression : "
                        + getExpression());
                   if (vExpressionVB != null)
                        setExpressionResult(vExpressionVB.getValue(vFacesContext));
              catch (Exception ex)
                   setExpressionResult("error resolving expression : ex = " + ex);
              return null;
         public void setExpression(String expression)
              this.fExpression = expression;
         public String getExpression()
              return fExpression;
         public void setExpressionResult(Object expressionResult)
              this.fExpressionResult = expressionResult;
         public Object getExpressionResult()
              return fExpressionResult;
    }(*) the expressionResolver.jspx page :
    <?xml version='1.0' encoding='windows-1252'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core">
      <jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
                  doctype-system="http://www.w3.org/TR/html4/loose.dtd"
                  doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
      <jsp:directive.page contentType="text/html;charset=windows-1252"/>
      <f:view>
        <html>
          <head>
            <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
            <title>expressionResolver</title>
          </head>
          <body><h:form>
              <h:panelGrid columns="1">
                <h:outputText value="expression resolver"/>
                <h:panelGrid columns="2" rendered="true">
                  <h:inputTextarea id="expression"
                                   value="#{expressionResolver.expression}"
                                   rows="4" cols="50"/>
                  <h:commandButton value="resolve" id="resolveButton"
                                   action="#{expressionResolver.resolveButton_action}"/>
                </h:panelGrid>
                <h:outputText value="#{expressionResolver.expressionResult}"/>
              </h:panelGrid>
            </h:form></body>
        </html>
      </f:view>
    </jsp:root>(*) the configuration in faces-config.xml :
      <managed-bean>
        <managed-bean-name>expressionResolver</managed-bean-name>
        <managed-bean-class>view.util.ExpressionResolver</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
      </managed-bean>So if you add these to an application, for example the "Oracle ADF SRDemo Application", you could resolve expressions like these at runtime (or any other expression you can come up with):
    #{data.SRPublicFacade.methodResults}
    #{data.SRPublicFacade.methodResults.SRPublicFacade_dataProvider_findServiceRequests_result}
    #{data.SRPublicFacade.methodResults.SRPublicFacade_dataProvider_findServiceRequests_result[0].problemDescription}
    #{resources['srdemo.version']}
    #{userInfo.userName}
    #{userState.searchFirstTime}All suggestions for improvement are welcome of course.
    One more thing ... a page like this should probably not be part of a production deployment of your application or it should be properly secured.
    regards
    Jan Vervecken

    Jan,
    this looks useful to me, especially if you work in support. Do you have a blog where this tip is mentioned, so we can link to it ?
    Frank

  • How to cast an object in JSF?

    I am working on a travel application. A user can have several bookings and a booking can have several components. A component can be either air or hotel. I want to list the user's bookings on the client using JSF datatable.
    <h:dataTable var="component" value="#{booking.components}">
    Now depending upon the class of component I need to present different information.
    My question is how to cast the variable in JSF ?
    Thanks

    You can use the String value of Object#getClass()#getName() to lookup the classname and evaluate it in the 'rendered' attribute.
    Basic example:
    package mypackage;
    public class Animal {}
    package mypackage;
    public class Cat extends Animal {}
    package mypackage;
    public class Dog extends Animal {}
    package mypackage;
    public class Fish extends Animal {}MyBeanpublic List<Animal> getList() {
        List<Animal> animals = new ArrayList<Animal>();
        animals.add(new Dog());
        animals.add(new Cat());
        animals.add(new Fish());
        return animals;
    }JSF<h:dataTable value="#{myBean.list}" var="item">
        <h:column>
            <h:outputText value="It's a Cat" rendered="#{item.class.name == 'mypackage.Cat'}" />
            <h:outputText value="It's a Dog" rendered="#{item.class.name == 'mypackage.Dog'}" />
            <h:outputText value="It's a Fish" rendered="#{item.class.name == 'mypackage.Fish'}" />
        </h:column>
    </h:dataTable>As far there is no way to cast objects in JSF.
    Edit
    If you find it useful, move the classname request to the superclass:
    public class Animal {
        public String getType() {
            String className = getClass().getName();
            return className.substring(className.lastIndexOf('.') + 1);
    }Which makes life easier without struggling with package names:<h:outputText value="It's a Cat" rendered="#{item.type == 'Cat'}" />
    <h:outputText value="It's a Dog" rendered="#{item.type == 'Dog'}" />
    <h:outputText value="It's a Fish" rendered="#{item.type == 'Fish'}" />Message was edited by:
    BalusC

  • How to refresh components of one jsf from another jsf (partialTriggers)

    This thread begins here:
    How to refresh components of one jsf from another jsf (partialTriggers)
    My apologies for post in other forum and thanks Frank for reply.
    I found a solution before read your post. I'm newbie and I ignore the use of colons. So, for do the problem that I explain in my post I must to change this code:
    public backing_home () {
    content = new RichPanelGroupLayout();
    content.setRendered (true);
    String[] partialTriggers = {"menu:menuItem1", "menu:menuItem2", "menu:menuItem3", "menu:menuItem4"}; //All id's of menuItems of the menuBar in menu.jsp
    this.content.setPartialTriggers(partialTriggers);
    Note that now I don't pass the item ID only. I add "menu:" before the ID. This allows to acces to name container ('menu' is de ID of subview). And that's all. This works!!
    Anyway, I test your propuse Frank. Thank you!
    Westh

    Westh,
    Yes this code appears to be correct. Was that your question?
    --Ric                                                                                                                                                                                   

  • How can I concatenate a currency field (eg: 12.25) with numeric values

    Hi,
    I ma working in ECC6.0.
    How can I concatenate a currency field (eg: 12.25) with numeric and character values into a variable.
    I want to concatenate 12.25  with  "+"  and  "0".
    Regard,
    Divya

    Hi,
    I ma working in ECC6.0.
    How can I concatenate a currency field (eg: 12.25) with numeric and character values into a variable.
    I want to concatenate 12.25 with "+" and "0".
    Regard,
    Divya
    ==================================
    data: l_string type string.
    move l_curr_field to l_string.
    condense l_string no-gaps.     "if needed
    concatenate l_string '+' '0' into l_string.
    now your l_string will have all the values.

  • Need help for "From concatenate string insert to mysql table"

    Well, most of this problem is a question about SQL syntax. In the VALUES clause you put a comma delimited list of the values to go into the new record. You insert one record at a time. How are the columns defined? Have you done any study on basic SQL?
    Mike...

    i nid to insert values from concatenate string into mysql with using LabSQL, but the result come out from conatenate string is like " 2015-07-08 00:00:00 38.933235E-3" , a logged data of "Date Time Wind Speed(m/s). i nid to put these 3 values into 3 different column in mysql which is Date Time and Wind Speed. How can i pick Date to put inside Date's column, Time into Time's column and Wind Speed into Wind Speed's column in mysql ?
    What i do is
    INSERT INTO wind_speed_data (Date, Time, Wind_Speed) The space in Wind Speed can i put a _ in between Wind Speed? without _ and just put Wind Speed it shows errors.
    VALUES( i have no idea wat to key in at this part ) <--- nid help !
    The Mysql table. Date Time Wind Speed
    The result from concatenate string. Have to insert into mysql.
    My labview program.
    The error i facing.
     

  • MDX - function expects a string or numeric expression for the 1 argument. A tuple set expression was used.

    why this query
    select [Measures].[F Events Count] on 0,
    Filter([D Actor Player].[Actor].children,
    ([Measures].[F Events Count],
    {([D Date].[Hierarchy].[Season].[2012 - 2013]),([D Date].[Hierarchy].[Season].[2013 - 2014])},
    [D Result].[Result].&[Goal])
    >=5) on 1
    from [FBA Cube]
    gives this error:
    Query (3, 3) The >= function expects a string or numeric expression for the 1 argument. A tuple set expression was used.
    while the following query works fine
    select [Measures].[F Events Count] on 0,
    Filter([D Actor Player].[Actor].children,
    ([Measures].[F Events Count],
    [D Date].[Hierarchy].[Season].[2012 - 2013],
    [D Result].[Result].&[Goal])
    >=5) on 1
    from [FBA Cube]
    why having set inside Filter's boolean expression generates that error? how can we
    keep the set inside the Filter's boolean expression but
    solve the problem? please explain the reason and solution

    Hi Butmah ,
    I think you should use an aggregation function with the set and the tuple ... adding an AdventureWorks snippet :
    select [Measures].[Order Count] on 0,
    Filter([Product].[Category].children,
    SUM({[Date].[Fiscal].[Fiscal Year].&[2011],[Date].[Fiscal].[Fiscal Year].&[2009]}
    ,([Measures].[Order Count],[Geography].[Geography].[Country].&[United States])
    >=5) on 1 
    from [Adventure Works]
    Regards, David .

  • Is it possible to access a consant attribute with a JSF expression?

    I have a class with constant attributes like this:
    public static final int CONSTANT_VALUE = 111;
    How do I access them with a JSF expression?
    #{myBean.CONSTANT_VALUE} does not work.
    Do I have to write getters for them? I heared somewhere that its not bossible
    to access them directly.
    Thanks!

    just write a get method of this attribute

Maybe you are looking for