Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
How to invoke getter() and setter() methods in struts?
Your question is rather vague. But the typical scenario in Struts2 is: you have an action with some properties which follow the Java bean conventions ( say, a 'myval' property is accesible via getMyval() and setMyval() public methods).
When invoking the action, the default configuration (with default interceptor stack) maps the http parameters calling the setter. Ej, if you call http:/..../myAction.action?myval=xx Struts2 will instance your action and call the method setMyval("xx") (if your property is not a string, struts2 will try to convert it).
After the action execution, when the results are displayed in the view (say,a JSP page), you might write <s:property value='myval' /> and Struts2 will invoke the method getMyval() of your action.
This is the most basic and typical workflow, but I'm simplyfing, everything is much more general and customizable.
See this article regarding general accessors and mutators in Java, and this one for accessors and mutators as specifically applicable to JSP's.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
How to know if a field of the form is edited or not? Is there any method in java? The UI is built with vaadin.
I want to throw an error if a field is not edited, I can throw error I just want an answer how can we check if the field is edited or not using java?
If you have a form and use Binder to bind the fields with the bean, there is a mechanism in Binder that is tracking this and you can use Binder#hasChanges() method to check there is one or more field in the form that has pending changes.
In case your use case is actually to verify that a mandatory field has been entered, you should use asRequired(..) validator to validate that the input is not null / not empty.
If your bean has non-null / non-empty default value, which should be altered, you can use validator that checks the input value is not the default value.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
You know that in spring you can have a method that gets a model as its parameter. I am new to spring and I don't understand where does that parameter come from. Is is some kind of spring default bean or what?
You can check this article!
Generally - as always it depends on your implementation. As #Aniket Warey said Model object can be passed from view - JSP or HTML files.
You have also something like ModelAndView, which works slighthy different from ordinary Model. You can also specify and configurate/implement your own ViewResolver. Spring/Spring Boot uses its own default implementation for Model, but like I said - you can override it.
Leaving the subject a little bit - you don't usually need to use Model parameter. It always depends on problem that you face, but there is for example #RestController, which can get/send you data as JSON. Then you can neatly manipulate it on the client/view side. There is a lot of options. :)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have experience web programing using express js framework
and this is my first time to learn playframework in java
how to make middleware in play framework
as ussualy i use express js just add middleware in front of controller in routes
example like this
router.get('/all/:key' , user_mid.login, ctrl_post.all)
user_mid.login = is my middleware
ctrl_post.all = is my controller method to handle the request
so how to make middleware in play framework
Play does not have a concept called middleware.
In Play Java, Results are returned by classes extending the Action (or Controller) abstract class. Why am I telling you this? Well, because you can compose actions. One action can forward a request to the next action, then to the next, and the other way around with the response. Play has good support for this concept: Action composition .
This goes in three steps:
Define an action by extending (usually) play.mvc.Action.Simple .
Annotate the method in your controller with #With, and your newly crated class. That way you composed two actions. They are called in the order in which the #With annotations appear, if you have multiple.
(Optionally) Define your own annotation for an action.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
My question is how mocks objects are created not how to create a mock object using a library.
I have looked at the Mockito library source code but I didn't understand how its done. I have searched in the Internet but the articles explain what are mock object and how to create them using libraries.
For dynamic programming language perhaps it's simple as we can change methods, variable but how its done in static programming language (Java for example)
Let's begin with what a mock is: an object that you can set expectancies on it regarding methods that expects to be called, and/or parameters on those methods and/or count of calls on those methods.
Mocks are sent to tested objects in order to mimic certain dependencies without having to use the real code (in many cases this is problematic/dangerous, like dealing with payment gateways).
Since mocks will need to intercept calls to all (or some, in case of partial mocks) methods, there are several ways they can be implemented, depending mainly on the features the language provides. Particularly in Java this can be implemented via proxy classes: https://stackoverflow.com/a/1082869/1974224, an approach that kinda forces you (but in a good way) to use interfaces in your code when relying on dependencies.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm going to get Html responses and do some modifications on responses in Java before they reach client.
My idea is writing a servlet-filter but I don't know how to implement that.
What I got is :javax.servlet.ServletResponse resp and javax.servlet.ServletRequest req.
The essentials of filters
check the part on modifying responses
In your servlet filter, you can provide your own subclass of HttpServletResponseWrapper
After the call of chain.doFilter(...), your response wrapper will contain the html content, you'll be able to retrieve and transform it.
You can find a similar servlet filter there as example : http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html
use head first's chapter for filter there is an example of HttpServletResponseWrapper. very nice book for servlet and jsp s.