Dynamically include variables...

I have an application that is in 7 different languages. Based on client language setting I serve them up different content on the JSP pages. I basically have 7 resource files that look like this (each has different text for field1):
<%
String field1 = "English Text";
%>
I dynamically include this on each page like:
<%
String inc="includes/resources/"+ pageLang +".jsp";
%>
<jsp:include page="<%= inc %>" flush="true"/>
This all works fine, no errors. The problem occurs when I try and call field1 on the main page:
<%= field1 %>
At this point I get an : Undefined variable: field1
Does anyone have any idea why this would happen? Any ideas how to work around it?
Thanks.

You need to pass all your defined variables as parameters into your included jsp page. For this, you can use the following construct:
<jsp:include page="spanish_content.jsp">     
   <jsp:param name="field1" value="<%= field1 %>" />     
</jsp:include>These parameters can be then read in your included JSP by using the standard request.getParameter()-method. Unfortunately this requires you to convert your values into Strings and parse them back into their respective types inside the included page.
You could also use the HttpSession to relay the parameters, although that may produce a bunch of problems. Do it like this in the including page:
session.setAttribute( "field1", field1 );And in your included page:
String field1 = (String) session.getAttribute( "field1" );For a better alternative for i18n, take a look at this:
http://jakarta.apache.org/taglibs/doc/i18n-doc/intro.html
.P.

Similar Messages

  • Dynamic include in a custom tag, called from a jsp

    Hello, I would like to be able to dynamically include other jsp's from within a custom tag that I create. is this possible?
    in a jsp page i would just write <%@ include file="file.jsp" %> and all would be ok... but if i do an out.println( "<%@ include file=\"file.jsp\" %>" ); inside a custom tag bean then it doesn't work. it just prints out the command to the page as plain text.
    I do understand why this is happening, but can anyone offer me a way around this problem?
    Thanks in advance,
    Randy

    That's actually the same result as you get with a normal include - The method I suggested is a dynamic include similar to the <jsp:include> tag, not the <%@ include %> tag.
    When you use a dynamic include, the included page is compiled and 'invoked' as serarately, and the result is what gets included, not the actual source. To get the behaviour you want would require an include directive (the <%@ include %> tag) which I don't think has an equivalence you can use inside a custom tag.
    What you can do is pass attributes from the tag class like this:
    pageContext.setAttribute(<name>, <object>, pageContext.REQUEST_SCOPE);
    and then remove them after the include using pageContext.removeAttribute.
    I'm not certain, but this implies that if you declare your variables with a <jsp:usebean> tag with request scope, instead of normal Java variable declarations, you should be able to use them in the page included by the custom tag.
    *** in the jsp ***
    <jsp:useBean id="myVar" scope="request" class="java.lang.String" />
    <% myVar = "Something"; %>
    // Now call the tag which uses the pageContext.include() mehtod.
    *** end ***
    *** in the include ***
    <jsp:useBean id="myVar" scope="request" class="java.lang.String" />
    <%= myVar + " something else" %>
    *** end ***
    Let me know if it works.

  • Include variables with minor difference in a loop

    How can I include variables with minor change inside a loop instead of hard code each one?
    For example
    aList = ""A", "B", "C", "D"]
    repeat with i = 1 to 4
      temp = aList[i]
      Variable[temp] = 1 (some calculation)
    end repeat
    The variables would be VariableA, VariableB, VariableC, VariableD...
    It's similar to Actionscript's
       this["q" + i + "_mc"]._x = this["dragTxt" + i]._x - 20;
       this["q" + i + "_mc"]._y = this["dragTxt" + i]._y + 14;
    then the instance is q1_mc, q2_mc etc..
    I remember that I could do similar things in Director but forgot how!
    Thanks for the help,

    Wow. Talk about not seeing the forest through the trees. There's never any good reason to create variables at runtime like that, regardless if there are ways to do it in the scripting language (which there invariably are). Your "on test" handler above uses a whole slew of lists to set up and create a bunch of "dynamic" variables when you should be stopping at lists and property lists (arrays and associative arrays) to do what you want, which is to store your data. The method you currently have conjured up is excessive at best, and bad programming practice at worst (See this link for some good discussion on why it should be avoided: http://programmers.stackexchange.com/questions/103083/how-can-variables-be-created-at-runt ime)
    So, I would do what you want like this:
    -- initialize the property list (associative array, in other scripting languages)
    gUserStatus = [:]
    -- add an entry
    gUserStatus["Bob"] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    -- print the property array to the message window
    put gUserStatus
    -- ["Bob": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
    add a few more users:
    gUserStatus["Mary"] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    gUserStatus["Sue"] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    gUserStatus["Paul"] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    -- get value from property list, based off name
    put gUserStatus["Bob"]
    -- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    -- set value in value list, based off name, then put to message window
    gUserStatus["Bob"][3] = 1
    put gUserStatus["Bob"]
    -- [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
    so, I can add as many users as I want... as long as they're identified with unique properties (or keys, in other languages). I can even get the count or number of users:
    put gUserStatus.count
    -- 4
    I can easily iterate through them and get/set information:
    cnt = gUserStatus.count
    repeat with i = 1 to cnt
      put "Name: " & gUserStatus.getPropAt(i) & ", Status: " & gUserStatus[i]
    end repeat
    In your example you don't know how many users you have because your variables are being dynamically created at runtime. You could create yet another variable to keep track of that, but why when you have lists and property lists that are perfect structures for this type of associative data?
    There's a huge gap in your understanding how to structure, keep track of, and manipulate data, and it's important to fill it now by learning about lists and property lists (arrays and associative arrays). Doing it now will truly open up a whole new way of programming to you.

  • Acces dynamic configuration variable (e.g. filename) in ABAP mapping class

    Hi experts
    I am searching for a possibility to acces a dynamic configuration variable (DCV) in an ABAP mapping class. Since I could not find a solution in SDN and other sources, I hope somebody in this forum can help me.
    What I already found is the following code which can be used to set a DCV, but what I would be interested in is how to read a DCV.
    Any help is appreciated.
    Markus
    METHOD if_mapping~execute.
    DATA l_record type mpp_dynamic.
    * copy payload
    result = source.
    * add an adapter specific attribute
    l_record-namespace = 'http://sap.com/xi/XI/System/File'.
    l_record-name = 'FileName'.
    l_record-value = 'test.xml'.
    dynamic_configuration->add_record( l_record ).
    ENDMETHOD.

    Hi Markus,
    you can find everything in my blogs
    /people/michal.krawczyk2/blog/2007/04/26/xipi-throwing-generic-exceptions-from-any-type-of-mapping
    Regards,
    michal

  • How can I do a dynamic include of a page fragment?

    I have a technical support website with a lot of simple html pages. What I want to do is hyperlink from the index page to another page, which would display these html pages as a page fragment, dynamically based on a session bean set by the hyperlink.
    I basically want to do this, if it was possible:
    <jsp:directive.include file="#{SessionBean1.pageToDisplay}"/>
    Now the FAQ's has a topic "How can I do a dynamic include of a page fragment?", which would seem to answer my question.
    But this is all it says, and it makes no sense to me. Could someone please translate? :)
    "Using a page fragment file (but using instead of the usual Creator approach) will accomplish a dynamic include."

    Here is 1 solution:
    First add this to the jsp:root tag:
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    Then surround the page fragment directive with something like this:
                            <div style="position: absolute; left: 24px; top: 408px">
                                <c:if test="${SessionBean1.count > 0}">
                                    <jsp:directive.include file="testPF.jspf"/>
                                </c:if>
                            </div>

  • Creation of Dynamic Date Variables to be used in WebI reports

    What we are trying to achieve is to create 4 optional filters (Current Day, Current Week, Last Week, Last Month) on 4 different dates which will allow the users to use them in WebI reports.
    When using an optional SAP Customer Exit variable in BEx and creating a Universe on top, the filter becomes mandatory (i.e. the whole Universe is filtered by the SAP Exit, irrespective of whether the filter is used in the WebI report). Even if the filter is flagged as optional at the Universe level, it still behaves as mandatory.
    If each filter becomes mandatory then we'll have to create 16 different Universes (for each optional filter and date combination)! This is not feasible.
    I've seen in other posts that MDX Statements are not currently supported for Universes base on BW and SAP Exit should be utilized.
    So with the existing BO version, is it possible to create optional dynamic date variables or is that a product limitation?
    We are on XI3.1 SP3 FP3.1
    Thanks

    Hi Adam,
    In BEx, I would create this query very easily using the "Amount" key figure twice in my results and restricting each with a different SAP standard out-of-the-box delivered variable. For your reference, the variables in BEx are: 0FPER and 0FYTLFP.
    If I expose these variables in my OLE DB for OLAP query, they are not transfered into the universe, but rather act as filters on the entire universe. I've seen in documentation that only "Ready for Input" variables can be transfered as options into the universe which is not something that I have seen mentioned in this thread.
    >> In the BEx Query you have the option to either make the variable "ready for input" or not. The behavior is the same in Bex or in the Universe / Web Intelligence. "Ready for input" means the user can actually provide an input and without the flag the user can not provide an input. Yes those variables are supported in the Universe.
    Why this is a problem: I can't create separate universes based on potential variable periods that users might want to see. Additionally, many financial reports require concurrent use of these measures in the same report. Also, in reality it's not 2 variables, but dozens.
    >> Which is a decision you make already on the BEx query level. if you decide that the variable is not ready for input then the user can change the timeframe in BEx either.
    Also, I don't have a good way to mimic the standard out-of-the-box functionality given with BEx in BO. If I custom create all my variables in the universe, how do I do a lookup from the system date to the fiscal calendar that is stored on the BW server? In other words, how does BO know which date belongs in which period? (the same would be true with factory calendars for a different functional area).
    >> Variable are created in the BEx query and the Universe will leverage those.
    If you want a dynamic date range then EXIT variable as part of the BEx query - ready for input or not - is the solution.
    regards
    Ingo Hilgefort
    The only work around I can see is to require users to enter the current fiscal period and have the BO reports filter based off that user entered value. This is unfortunate as the entire purpose of SAP Exit variables is to avoid having to require user input at report time.

  • How to include variable in the text column in report painter?

    Dear Expert,
    Would like to seek for your help to include How to include variable in the text column in report painter?Please advice.
    Thank you.
    Regards,
    Karen
    Edited by: Karen Swee Ping Ho on Jun 17, 2011 2:48 AM

    Hi,
    Thank you for the promt reply.
    1) How I include the variable in the column header to display fiscal year which I have selected from the selection screen?
    which variable should i use?
    2) Where can i find more information about the characteristic and which variable to be use base on the characteristic?
    For example: I would like to display the fiscal year from the selection screen/input screen when execute the report which also will reflected to the element definition and will display the fiscal year also in the column text?
    3) Kindly advise base on question 2, the variable that i use in element definition it will also display  in selection screen?
    4) When execute the report the first selection screen input parameter it obtain from where it is from element definition?
    5) Please advice how to be done when report execute with first screen input selection will also reflect the element definition of column and rom with the selection of the fiscal year?
    Please help.
    many thanks
    Edited by: KH on Jun 18, 2011 7:18 AM

  • Trying to dynamic include HTML into a JSP

    All,
    I am trying to include an HMTL file into a JSP file. I wish to do this dymanically. So, the following is not an option:
    <%@ include file="relativeURL" %>
    So, I am forced to resort to such measures as the following:
    <jsp:include page="<%=myPath%>"/>
    However, I get the following error:
    java.lang.IllegalStateException: Response has already been committed
         at java.lang.Throwable.fillInStackTrace(Native Method)
         at java.lang.Throwable.fillInStackTrace(Compiled Code)....
    I tried it like this:
    <jsp:include page="<%=myPath%>" flush="true"/>
    I encoutered the same result. I have JSP 1.2 running Tomcat 3.1 with Apache 1.3.14, all on SunOS. Thanks in advance for any help.
    Nicholas

    One of the worst error messages you can get is the IllegalStateException. It simply means that an attempt has been made to forward or include but only a portion of the include was sent. In a situation like this the best way to handle the dynamic page content is to include it from a Servlet by sending the information you need through beans. Including the Servlet rather than the dynamic path would clear those errors right up. One thing to keep in consideration is that you can't just get the page and display it, you have to buffer it in so the state can be kept alive without timing out like it does with the dynamic include.
    Hope that helps. Been there, done that, I know how frustrating the error was.

  • Dynamic configuration variable lifetime?

    We are migrating from PI 7.1 to PI 731 and one of our applications uses dynamic configuration variable. It is a custom dynamic config variable saved in the first message (IDOC to PI BPM). We have asynch to synch scenario and  send a synchronous message from BPM.
    Once the response is received, the message is sent back from BPM (Second send step). During this message, we have a receiver determination (which uses the previously defined dynamic config variable). When I look at this message in sxmb_moni, I see no 'Dynamic Configuration '  and my receiver determination fails.. This used to work in PI 7.1 before and was curious if something was changed in PI 7.31?
    I had noticed previously that dynamic configuration variable was removed when the logic went in exception processing of the BPM (even in PI 7.1).

    As I had indicated, I was creating a custom dynamic configuration variable (with custom namespace and custom name). It was not a standard...
    Essentially, a short cut to store the variable from input message (which will no longer be available in my response). 

  • How to set a lable as the dynamic session variable ?

    I have created a dynamic session variable in admin tool and then I want to create a prompt in dashboard and set label to use this session variable
    I try to use the @{variable} or @{system.variable} in the label text ,but it is not work ,so what is the correct way or does the obiee not support to do like this?

    thx, for responded
    but I have read a topic said if left the label text empty the reference a presentation variable , then it can work , you can see it below:
    http://obiee101.blogspot.in/2009/04/obiee-multi-lingual-prompt.html

  • How to create a dynamic include

    I would like to construct a dynamic include depending on URL searchstring data. In my mind it looks like this:
    <%@ include file = request.getParameter("subnav")+".jsp" %>
    but for my Server it�s more like this :-))
    index.jsp(110,25) Attribute value should be quoted
    It might be a problem on the execution time of the include command but I don�t know how to get around it.
    Elmar

    The JSP's include directive (<%@ include) can be used to include files at the translate stage. So, you can't parameterize the file name. But the JSP's include tag (<jsp:include...) includes the file at runtime and hence you can parameterize it as I have shown in my earlier reply.
    Hope this helps. And this is the solution I believe.
    Sudha

  • Spry XML data set and dynamic post variables

    Hi,
    I am trying to create an XML data set that has dynamic post
    variables.
    Everytime something is pressed on the page a variable changes
    and I then want to reload the XML data set using the new variable.
    I know I can just pull in an XML with all possible variables
    and filter client side but this would make it way too large.
    Does anyone know what I may need to do.
    I tried this:
    var myVar = 0;
    var dss = new Spry.Data.XMLDataSet (
    '../../cgi-bin/server_details.pl' , 'top' , { method: 'POST' ,
    postData: sid=ajaja21&ip=127.0.0.1&cid=' . myVar ,
    subPaths: [ "auth" , "plugins" , "plugins/plugin" ] , keepSorted:
    "true", sortOnLoad: "plugins/plugin/order", sortOrderOnLoad:
    "descending", useCache: false, loadInterval: 10000 } );
    onclick="myVar=1";
    But the script doesn't understand the post variables sent (it
    does when I remove the . myVar part and put in a static value). I
    think it isn't sending that dynamic variable with the post
    variables.
    Any ideas anyone?
    Thanks

    Well I had it working when I stripped back everything and
    just had the dss data set and a single onclick function, but now
    that I put it back together it hash foobared again.
    Here are the relevant bits of code that I've changed.
    The function to change server id:
    //function to run when changing the server id
    function changeServer ( sid ) {
    //set the url to use the current server id
    dss.setURL = ( '../../cgi-bin/server_details.pl' , { method:
    'POST' , postData:
    'sid=7gv1m3vjvagfl7h7qeefb8iodj8evhmb&ip=127.0.0.1&cid='+sid
    //force a reload of the server data
    dss.loadData();
    The inital load of the data set
    var dss = new Spry.Data.XMLDataSet (
    '../../cgi-bin/server_details.pl' , 'yams' , { method: 'POST' ,
    postData:
    'sid=7gv1m3vjvagfl7h7qeefb8iodj8evhmb&ip=127.0.0.1&cid=0' ,
    subPaths: [ "auth" , "plugins" , "plugins/plugin" ] , keepSorted:
    "true", sortOnLoad: "plugins/plugin/order", sortOrderOnLoad:
    "descending", useCache: false, loadInterval: 10000 } );
    And the part that changes the server id
    <td align="left" style="cursor:default; width:174px;"
    onclick="changeServer({dsv::servers/server/@id})">{dsv::servers/server/name}</td>
    I checked that the function is receiving the correct server
    id and I even tried hard coding the cid variable to 2 in the change
    function but it still wasn't changing on the server side.
    Any ideas?
    Thanks

  • OBIEE | Using Dynamic Session Variable in Physical Layer

    Hi All,
    Any idea if we can use Dynamic Session Variables (I think they are also called Repository Variables) in our physical layer. I basically need to set the value of this variable from dashboard when a link is clicked, and then use this in my SELECT query at physical layer so that OBIEE does not pull all the data from the database tables.
    Regards
    Adeel Javed
    Edited by: user10642426 on Apr 6, 2009 2:03 AM

    Christian,
    Thanks for the quick response, ok we have actually moved to a different solution now, we are actually using Direct Database Request because one of our reports is supposed to be accessing direct transactional system i.e. for this report we are using OBIEE as a reporting tool. We are able to do that and even create links between different reports i.e. based on prompt in Report A filter Report B, but the scenario now is that we need to set a presentation variable from Report A when a navigation link gets clicked, because so far according to our knowledge direct SQL only allows presentation variables in its WHERE clause. So, any ideas how can we set a presentation variable when a navigation link is clicked. Thanks.
    Regards
    Adeel Javed
    Edited by: adeeljaved on Apr 6, 2009 11:43 PM

  • Dynamic include inside custom tag body

    I am trying to perform the dynamic include of another JSP from within the body of a custom tag using JSP1.1. It cannot be done using <jsp:include> since flush=true is required and thus an exception is thrown when called from inside the body of a custom tag - it can be done in JSP1.2 since flush does not have to be set to true but upgrading is not possible at this time.
    Does anyone know of any custom tag or the code needed to perform this function with JSP1.1?
    I am using Tomcat 3.2.3.
    Using a RequestDispatcher and calling include() does not have the desired effect since the output is witten directly to the response and does not go into the correct position in the calling JSP.
    I think the solution involves making a call to the included JSP (is it possible to use a RequestDispatcher that doesn't write directly to the page output stream?) and then append the response to the BodyContent object which is buffering the body content of the custom tag until the doAfterBody() method is called. Is it possible to create a dummy ServletResponse object to pass to the RequestDispatcher and then obtain the HTML response from the internal buffer?

    I don't know if there is a solution to the problem you are having with JSP 1.1. If you look in the spec, it actually warns you that dynamic includes can not be done inside a body tag. The spec actually states that the included code shout write directly to the response and not to the BodyContent.
    I was excited to find out they had fixed this in JSP 1.2, but they seem to have foiled me again. If my tag calls PageContext.include(), the spec says that include must call the flush method, which causes BodyContent to throw an exception since flush is not a valid call.

  • Iterate through all dynamic text variables

    Hello,
    I'd like to be able to iterate through all of the dynamic
    text variables in my flash movie, and I'd like it so that if I add
    new text to this movie, it will show up in the iteration.
    Essentially, I want to do something like this:
    for (i in _root) {
    trace(i);
    While this seems to print out all the variables in root, it
    prints more than just the dynamic text variables, and also doesn't
    iterate down through various objects to find the dynamic text
    variable.
    Is there any way I can accomplish this in action script?
    Thanks!

    Great! That code helps me a lot.
    There are still two weird issues.
    1) the test for tl[obj].text seems to always turn out to be
    false. However, if I trace the value of text, I'll see the text.
    Example:
    trace(tl[obj].text); // This will display the value in the
    text field
    if (tl[obj].text) // This is always returning false.
    Any ideas?
    The 2nd issue might be more difficult - some of my text
    objects don't appear until later in the movie (i.e. frame 10). It
    sort of looks like this looping doesn't see objects that appear in
    the future. Do I need to advance the frame 1 by 1 and repeat this
    looping process until the text appears? Maybe instead I can always
    have the text in the first frame, but have it be invisible or
    something?

Maybe you are looking for

  • Applet does not load in IE when hosted in form via SHDocVw.dll

    Hi I have a signed applet that usually works well in IE and Mozilla FireFox. It shows a popup window with the security question Yes/No/Always and works great thereafter. However We have now developed a Vb.Net application which hosts the SHDocVw.dll a

  • Passing parameter in a method

    hi i have a situation where i have to pass parameter to my method i don't what to pass the parameter define from the viewO because am not using parameter to query from the view,i just what to pass it to my procedure,my method is                 publi

  • Using smart forms

    hi all, How to include a smart form into webdynpro abap view?can any one provide me step by step procedure or sample code for this.. Thanks in advance, Regards, Anusha

  • How do I migrate settings in Illustrator after updating from CC to CC 2014?

    I have just updated from CC to CC 2014 and was not given the option to migrate settings for Illustrator as I was for Photoshop. How can I do this?

  • Page redirecting in jsf

    Hi all Could you please tell me how can i redirect from .jspx page to another web application. regards sasasa