Hi I have a struts 1.X app, and in order to show errors detected in an action class, I use:
errors.add("Error Global", new ActionMessage("some_string_in_properties_file"));
Which works just fine.
My problem is that now the string I need to send to the jsp page as error has a session variable in it (like "You have 3 more valid attempts", being 3 the session variable).
How can I accomplish this ?
Thanks.
Try to use ActionMessage constructor of 2 arguments. According to JavaDoc:
public ActionMessage(java.lang.String key,
java.lang.Object value0)
Construct an action message with the specified replacement values.
Parameters:
key - Message key for this message
value0 - First replacement value
In your case:
errors.add("Error Global", new ActionMessage("some_string_in_properties_file", sessionVariable));
some_string_in_properties_file should look like this:
some_string_in_properties_file=You have {0} more valid attempt(s)
Related
I know how to validate property if its match regexp:
regex = "^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$"
for guid, but if its not send in payload - receiving error, is it a simple way to check if property exist and do validate only then?
As per now I check with choice if its exist and if so then do validation, but interested if its more smarter way to do such as if I will have 20 properties to check its becomes very messy flow.
For example 3 validations at the moment:
You could use the Validations Module All validator which seems to cover this use case. Note that you can not customize the exception or message. If this is not acceptable then you could use individual validations in the flow instead.
Example:
<validation:all doc:name="Validation">
<validation:validations>
<validation:is-not-empty doc:name="Validation" value="#[payload.firstName]" message="Firstname cannot be empty"/>
<validation:is-not-empty doc:name="Validation" value="#[payload.lastName]" message="Lastname cannot be empty"/>
<validation:is-number message="Not an adult" value="#[payload.age]" minValue="18" numberType="INTEGER"/>
<validation:is-email email="#[payload.email]" />
<validation:matches-regex message="Invalid SSN" value="#[payload.ssn]" regex="^(?!000|666)[0-8][0-9]{2}-(?!00)[0-9]{2}-(?!0000)[0-9]{4}$"/>
<validation:validate-size value="#[payload.ssn]" min="11" max="11" message="SSN too short"/>
</validation:validations>
</validation:all>
I have a Problem in compiling play 2.1 application ,in main.scala.html I called javascriptRouters
javascriptRouter("jsRoutes")(
routes.javascript.Authentication.authenticate
For this I have defined (request: play.api.mvc.RequestHeader) on top level
so its working fine now I got request object in this page but when calling
#main("title")
Unspecified value parameter content.
[error] #main(title = "Create Job",status,role){
how to pass request object ????
`
I solved my problem by passing it in the new parenthesis but have a new questions
why it is not working when passed it with content
The first one I understand that whenever I am calling #main I have to passs three string
what does second parenthesis mean (content :Html) are we passing the caller html here
that what does this mean?
#(title:String, status:Option[String],role:String)(content: Html)(implicit request: play.api.mvc.RequestHeader)
I am trying to figure out how to implement session management in wso2 esb.So i have written a class mediator which generates session_ID that i want to store.For storing the session id I am using following code as:
org.apache.axis2.context.ServiceContext serviceContext = org.apache.axis2.context.MessageContext
.getCurrentMessageContext().getServiceContext();
serviceContext.setProperty("SessionIDGlobal", uuid);
But while running it in my esb's proxy it throws null pointer exception at getCurrentMessageContext part.I have followed another approach where-in i am storing the sessionID in property mediator and tried to get its value but when i click postRequest operation after generateSessionID operation from try-it. all the property gets reset and my sessionID property gives me null value. What should i do to rectify this problem? Is there any alternate way?
You have to create servicecontext like this;
ConfigurationContext cfgCtx =(((Axis2MessageContext) synCtx).getAxis2MessageContext(). getConfigurationContext();
cfgCtx.getOperationContext().getServiceContext();
You should store in the Message context but you have stored in the service Context. please refer this to understand how you can set the properties at different scopes. Synapase (default), Axis2, Transport etc.
Please refer this blog post for complete details.
http://blog.facilelogin.com/2011/02/wso2-esb-property-mediator-different.html
I am making an app for Windows Phone and since I need some login cookies that are saved in Web browser control, I am using the code from here: Grabbing Cookies in Web Browser Control - WP7 to create a HTTPWebRequest and get some JSON data for parsing but I am getting two errors on the last line of this snippet
Dim browser = New WebBrowser()
Dim brwhttp = GetType(WebRequestCreator).GetProperty("BrowserHttp")
Dim requestFactory = TryCast(brwhttp.GetValue(Browser, Nothing), IWebRequestCreate)
Dim uri = New Uri("some-url")
Dim req = requestFactory.Create(uri)
req.Method = "GET"
req.BeginGetResponse(New AsyncCallback(request_CallBack), WebRequest)
(1). 'WebRequest' is a type and cannot be used as an expression.
(2). Delegate 'System.AsyncCallback' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor.
How to fix?
UPDATE 1: Fixed Error (2) by adding 'Address Of' before 'request_CallBack' but Error (1) still remains.
UPDATE 2: Fixed all errors but not getting any response (empty). What's wrong with my code?
THe problems are two do with the line req.BeginGetResponse(New AsyncCallback(request_CallBack), WebRequest) This has two problems.
VB.Net does not have true first class functions so you have to use the AddressOf operator the create a delegate. Also the compiler will infer the delegate type so you don't need the constructor
BeginGetResponse takes a state object as the second parameter not a type expression. This is whatever you need in the callback
so:
req.BeginGetResponse(AddressOf request_CallBack, Nothing)
If you need to pass a type to the request callback use
req.BeginGetResponse(AddressOf request_CallBack, GetType(WebRequest))
However this looks like a copying change and what you want may be
req.BeginGetResponse(AddressOf request_CallBack, req)
I am using RestSharp in ASP .NET MVC 2 project. Trying to create RestRequest (using POST method) and add two enum values (my enum type -- OrderStatusFlags) to request body -- using build-in RestSharp XmlSerializer:
var request = new RestRequest("orders/{vendorID}/{number}", Method.POST);
request.AddBody(previousOrderStatus);
request.AddBody(newOrderStatus);
But after calling AddBody method in request parameters can see only empty but no value. And while calling MVC action method an error occurs:
The parameters dictionary contains a null entry for parameter 'previousStatus' of non-nullable type 'OrderStatusFlags' for method 'RestResponse PostOrderStatus(Int32, System.String, OrderStatusFlags, OrderStatusFlags)' in 'OrdersResourceEndpoint'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Enum look like this:
public enum OrderStatusFlags : long
{
Pending,
Confirmed,
...
}
Does anybody occurs a similiar situation?
A couple issues here. First, you can only call AddBody() once or the last call will take precedence. AddBody() is also only for sending XML as the request body. What is the required XML schema that you need to send to that URL? Can you post some sample XML that you're trying to generate?
I think more likely you actually want to use AddParameter() to add some POST parameters since that is far more common than XML request bodies.