prehlb Posted February 7, 2007 Share Posted February 7, 2007 Hi All,We've moved into the stage of developing reports after developing our rendering and job management engine that will work well for our customers. We came across a situation where we need to create letters. These letters need to contain various wording. Instead of writing one report for each wording variation we are looking to replace the text with styled text that the user can predefine as a parameter before submitting the request for the report to be generated. We're planning on allowing the user to use the FCKEditor to create the wording. But, in addition to the Bold, Italic and Underline feature we would give them the ability to place references to query fields for the report such as LAST_NAME or FIRST_NAME fields. This means we need to allow them to specify references like $F{LAST_NAME} but that won't word because JR is treating the string in the REPORT_PARAMETERS map as a plain string and not a JRExpression such as done with the Default Expression of a parameter. Does anyone have an idea of how we could pass an expression to a parameter instead of as string to a parameter? Therefore, we would pass a string that's to be interpreted as a string that would have strings embedded. Just as we can do with the Default Expression of a parameter but this time the information passed inside the REPORT_PARAMETERS map would be treated as an expression? I was thinking of trying to specify the class of the parameter as a JRExpression. Thanks in advance for any suggestions or knowledge. Bill Link to comment Share on other sites More sharing options...
lucianc Posted February 7, 2007 Share Posted February 7, 2007 There is no built-in support for evaluating dynamic/runtime expressions in JasperReports. Report expressions are collected at report compile time into a Java class which is then used to evaluate these expressions. Hence, the expressions must be known at report design/compile time. An alternative approach would be to use the built-in msg() function (which uses java.text.MessageFormat) to obtain parametrized messages. The disadvantage of this approach is that MessageFormat uses positional arguments, so the users would need to write "blabla {0} etc {1}" and know that you will pass $F{FIRST_NAME} as the first argument and $F{LAST_NAME} as the second argument. Another approach would be to implement your own interpreter, either from scratch or by using something like OGNL or maybe a Java scripting interpreter. Regards,Lucian Link to comment Share on other sites More sharing options...
lucianc Posted February 7, 2007 Share Posted February 7, 2007 One more approach: design a generic report, take the user text/expression, alter the report design to include the user-defined expression, compile the report and then fill it. Link to comment Share on other sites More sharing options...
prehlb Posted February 9, 2007 Author Share Posted February 9, 2007 Hey thanks for the reply. We did figure out that we could build our own parser into a scriptlet and it works like a charm. So, you're theory was on the same route and it does work. Thanks for the ideas! Bill Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now