Setting float format in Struts2 for entire application - struts2

I'm using Struts2 to develop an application that needs to display all floats with the following format: "#.00", meaning the integer part, a point as the decimal separator and the first two digit of the decimal part.
Is there a way (maybe using the global.properties file) to set this behaviour for the application?

i think what you should do is to implement HttpSessionListener or ServletContextListener and place your float format in the session or context. You can then use ognl or struts 2 property tags to access them in your jsp.

Related

Struts Jquery Grid load issue after upgrading Struts to 2.5.27 from Struts 2.5.22

Hi We have recently upgraded Struts2 from Struts 2.5.22 to 2.5.27 . In our application we are are using Struts Jquery Grid. We are using struts2-jquery-grid-plugin-4.0.3.jar library.
One of our application need is to assign grid id a dynamic value which is bean property.
My code snippet is below:
<sjg:grid id="%{#tabGrid.gridId}" caption="%{#tabGrid.gridCaption}" gridModel="%#tabGrid.gridData}" href="%{gridUrl}"-------->
Before upgrade above piece of code was working. But after the upgarde we are unable to assign grid id bean property.But we can assign grid caption bean property like shown in above code snippet.Only when we are assigning id a bean property my code is breaking.
I have tried to workaround by assigning grid class value of property bean than id. But this change will impact lot of code changes in my application.
Please suggest what could be the reason for it and possible solution.
Since Struts 2.5.26 you no longer can use %{} to force OGNL evaluation in the Struts tags using public attributes which leads to double evaluation of OGNL expression. This fixture is documented in S2-061.
Some of the tag's attributes could perform a double evaluation if a developer applied forced OGNL evaluation by using the %{...} syntax. Using forced OGNL evaluation on untrusted user input can lead to a Remote Code Execution and security degradation.

Modify the token returned by Struts2 s:token tag

In a Struts 2 webapp (which also uses Spring),
I want to modify the "output" of the <s:token> tag to use my own token-generation algorithm.
It appears the <s:token> tag is handled by a class called org.apache.struts2.components.Token, which is a UIBean. Is there a standard way using either Struts or Spring by which I can "extend" or "modify" or replace the Token class, or the methods it uses to generate tokens?
Alternatively, can I make up my own <mytoken> tag that works in Struts 2?
At the moment in the latest S2 version 2.3.20 there is no simple way of doing that. The TokenHelper class which is responsible for generating tokens is a simple utility class with static methods.
You are better off using your own custom token solution. You need an interceptor which will handle tokens and something that will put token into JSP. For that you can create custom tag or just use a hidden input which calls some method in your base action.
Note: The execAndWait interceptor uses TokenHelper too, so if you are using execAndWait you need to change it as well.

How do Grails dynamic finders handle types?

I'm a bit confused about what is happening when I give a Grails dynamic finder the wrong type.
For instance, if I have class Foo
class Foo {
//long id (implicit id is a long)
Long barValue
}
And I do, Foo.findByIdAndBarValue('1', '2'), I get a result, but I am confused about what is going on here with the string values.
Is it passing these string values directly to the db (potentially ignoring valuable indices due to type mismatch) or is Grails automatically converting the types?
When passing parameters to the dynamic finders on Grails domain classes the parameters are dynamically typed. This allows for automatic type conversion, by Groovy.
In your example, Groovy is seeing that the barValue is of type Long and is casting the String value to a Long.
JN3015-Types explains this behavior of Groovy a bit further with some examples.

Access resource bundle outside struts action class

There are several ways to handle resource bundle using Struts 2.3 framework. This includes using certain UI tags in the View class or getText() method in your Action class.
However, there is no straight-forward mechanism to access this resource bundle in a java class or any other class except View and Action.
I found two ways to access it in a java class,however, they fail to completely replace the old MessageResources of Struts 1.2 framework.
Following are the two ways with drawback of each
Using ResourceBundle class of java.util package.
Locale locale = (Locale)request.getSession().getAttribute(ConstantsFnl.LOCALE_KEY);
ResourceBundle rb = ResourceBundle.getBundle(bundle,locale);
message = rb.getString(key);
The drawback with this approach is you cannot pass an array of arguments which can be replaced in your message text.This functionality was present in Struts 1.2 with MessageReosurces.
Using DefaultTextProvider of Struts 2.3 framework.
DefaultTextProvider dtp = new DefaultTextProvider();
return dtp.getText(key, (String[])params);
Though this approach gives you a way to pass an array of arguments to be replaced in your message text, it does not give you a mechanism to specify the locale or specify the bundle to be searched.Again,this functionality is present in Struts 1.2 with MessageResources class.
Looking for an optimum approach.Any help on this would be great.
You can use methods found in:
com.opensymphony.xwork2.util.LocalizedTextUtil

System.Convert.ToByte

Hi is there any equivalent method in classic ASP for C#.net function "System.Convert.ToByte" ?
basically i am encoding one string in my windows app using c#. and in classic asp it need to be decoded in which it need to use the above function.
Thanks,
Vinod
Perhaps I'm missing something important here but how about int=Val(ch) and ch=Chr(int)?
Also and as I'm sure you already know, converting the characters in a C# string into bytes will fail for any string containing anything outside of the extended ASCII range, i.e. 00=NUL to FF='ΓΏ'.

Resources