How to not associate a controller with a view? [Grails] [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am working on a Grails app that only consumes a third-party API and uses Firebase as a datastore. Because of this, I don't want to associate my controller methods with any views in the grails-app/views directory. I keep getting a ServletException: could not resolve view in servlet whenever any controller methods gets called back. How should I stop this from happening?

In Groovy if the last statement of the method is implicitly the return statement. Similarly, in Grails, a controller action method will expect a view with the same name as your method name if you do not explicitly render a view.
With that in mind, you can solve this in two ways.
Create an empty view that matches the method name with nothing in it.
Render an empty string as the last statement in your method as such.
class SomeController{
def index(){
// do stuff
render ""
}
}

If you do not wish to render anything, you likely need to render a status at the end of the method. You can do so like this: render(status: 200)

Related

Trying to think an approach for creating a feature flag in React [closed]

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 11 months ago.
Improve this question
I'm trying to create a feature flag in my react project (I believe I have to add a feature flag in the appsettings.json file), the flag is to hide the features that are currently being developed as we don't want users to have those features when those are yet to be tested fully. So the current approach I have is to wrap the newly developed code with a condition like if(flag){new code} I'm sorry if the approach looks silly but that's all I can come up with as a rookie, so can you guys help with some feasible approach if possible?
So I've tried adding the if condition to an existing feature in the code base as the newly developed code is yet to be committed but it didn't work.
Based on your comment from three hours ago I was able to figure out what exactly you wanted to do.
So: already having the flag all there is to do is to use it. There are at least three ways you can do it:
make it hidden - i think MDN docs explain it well enough
make it transparent - this is what you did: setting opacity to 0
not render it at all
not rendering is achieved like this:
return (
<SomeParentComponent>
{EnableDivision &&
<Division/>
}
</SomeParentComponent>
)
It's not like one of them is better than others: they are all situational.
hidden element is rendered, and therefore has state and can be found in the DOM tree, but doesn't take any space
transparent is like hidden, but takes up space
not rendered on the other hand can't be found in the DOM tree, doesn't take any space, the funcion or class creating it is never run and therefore it also can't have any state
Hopefully this should dispel your doubts about how to do it.
Also if you ever needed use some flags in many different components in various places of your component tree take look at what React Context does.

Properties not being set in prepare method [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am using Struts2 and an action implementing the Preparable interface.
When I submit the form, action properties are not being set in prepare() method of action. I get the values in the action method (eg. execute()), but they are empty in the prepare() method.
How can I get the properties set before running the prepare() method ?
In the default Interceptor Stack, the Prepare Interceptor runs before the Parameters Interceptor. That means that the injection of parameters has not yet occurred when the Prepare Interceptor executes the prepare() method. You need to move the Parameters Interceptor before the Prepare Interceptor, or to duplicate it, putting one declaration before the Prepare Interceptor.
There is a default Interceptor Stack created with that purpose, paramsPrepareParamsStack; read more here and here.
Note that this kind of problem is recurrent in Struts2, you need to understand how an Interceptor Stack works and which business every single Interceptor is taking care of.
For example, it happens when using ModelDriven, or when using Wildcard Mapping. And for sure it happens with your custom Interceptor if you put them in the wrong place.

Organizing Code in Java [closed]

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 8 years ago.
Improve this question
my main.java file has a length of about 1000 lines. My code is getting more and more confused, and I would like to "split" it in different parts (e.g. in one file I would have essential stuff like OnCreate, in another file I would have for instance GetHttpRequest).
I already tried to put GetHttpRequest in a different class, but is there no simpler way? (It would take a really long time to adjust the code if I used this method)
You have to use classes and methods, and optionally packages.
This will solve your problem. There's no simpler way than that.
Please do not hard-code your program. There are several patterns on how to code a program, so it is efficient, everybody can easily read and understand it. I think you also have a "GUI", assuming to this, I recommend you to use the MVC pattern. It means Model-View-Controller, so you organize your program in Packages: "model", "view", "controller" and in those packages you put the classes. For instance, you have a simple Calculator. Then you have a class in view thats called "CalculatorView", where your graphical interface is and in controller you have your "CalculatorController" that works out the things like calculations. (You call the controller from the view) and you do not need model at all.
I hope that helps you. But you will have to rewrite all your code...

JAVA Swing - Update UI (breaks until I move it around) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Im pretty new to SWING and I tried my best but this is what is happening.
I have a interface that looks like this:
https://dl.dropboxusercontent.com/u/17524455/nodelete/1.jpg
From the main thread I call:
FrmMain.settextParticipants(5 + "");
FrmMain.setLaps(5 + "");
FrmMain.setRaceType("standard");
And that goes OK.
I Even manage to update the stoptime and time in the upper part of the GUI.
But as soon as I call (in the next line)
PnlRacers.PnlTransparents[0].setNameAndKartNr("01", "RACER");
My UI breaks like this:
https://dl.dropboxusercontent.com/u/17524455/nodelete/2.jpg
And the only thing that helps to fix the UI is, when I grab the window and move it around (to my second screen for example). That tells me that the "data" or "functions" are working well I guess... But the REDRAWING (or how to call it) is somehow ok for the first arguments and broken for the last class. After moving around it looks like this: https://dl.dropboxusercontent.com/u/17524455/nodelete/3.jpg
I read something about redraw() and validate() and I tried all on all places and on any element I was working with :(.
Maybe someone knows what the problem could be and if the source should be any help, here it is: https://dl.dropboxusercontent.com/u/17524455/nodelete/TEST.rar
Please help :) Im so lost ...
Have you tried calling repaint() to the content pane after the change you implemented?

Spring Roo: Trigger Action on Update – Best Practice [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have played a bit with Spring Roo, now I am asking myself what is the Roo suggested way or best practice way to trigger an action after an object update.
Let me explain it with an example:
Assume I want to implement a web based Bug Tracker (I don’t want to do this, it is only an example). A bug tracker, is about Issues. Each Issue has a state (New, Confirmed, Assigned, In Progress, Resolved.), a title and some other fields.
The user has a web form where it can enter and update all fields (state, title, …). When the state of an issue switches from ‘In Progress’ to ‘Resolved’, the system should send an email to all persons that are interested in the bug (How this list of interested persons is maintained, is out of scope for this problem).
The problem that I have is: How to trigger the email sending process when the state is changed (in a Roo application)? Because there are several problems:
How to determine if the issue state is changed?
We need to make sure, that the message send after the issue is complete updated (for example it would not work, to put the trigger in the setState() method of the Issue, because it is not guaranteed that the other values from the form (title…) are updated before the state is changed.
The mail must only be sended if the form was valid and the Issue is likely to be saved (I do not facing the problem that the transaction cannot be committed – this will be another problem)
Does anybody have a good, testable (unit tests) and maintainable solution? Maintainable means especially that the code to handle this should not be placed in the controller, because it will be used in several controllers and someday somebody will implement an new controller and he will likely forget to handle this email concern.
You can use the #PostUpdate annotation, a JPA life cycle callback listener.
class Issue{
#PostUpdate
protected void onPostUpdate(){
//This method wil run after the update
if(this.state == Resolved){
//...
}
}
Here is more information about the available callbacks.

Categories

Resources