Github Copilot + Angular - Single File approach - java

I'm trying to build a simple ToDo App with Angular using two approaches:
At first I tried to develop on each file (asking code with short comments in .html, .css, .ts) and receiving as output small code snippets. Everything works as expected until now.
Second approach is trying to put a single long detailed comment in a unique file where I explain all I need in terms of component and interactions as shown in the example below*. Is there a way to obtain this code in a single session.ts file with the path attached before each code snippet so that I can move the code into the related file?
*Insufficient Comment Example to provide a clearer idea of the expected output:
I need two Angular Components: Login and Todo.
The Login Component has a form with two input fields: Username and Password.
The Login Form is implemented using ReactiveForms.
The submit button directly redirects to TodoComponent.
The TodoComponent shows a table with the ToDo List.
The List is empty at first.
The table has the following columns: Id(number), Title(string), Completed(boolean) and Actions.
The TodoComponent has a button to Add a Todo.
Etc.
Thanks in advance!
I tried to put the comment in a session.ts file but it's not working as it previously did with Java, I expected to receive a path /todo.component.ts and the related code, /todo.component.html and the related code and so on with the rest of the generated project.

Related

How to open a form created on GWT using QRcode?

I have created a form that show details of a student (using GWT). I want to create a link of that form that should be opened using QR Code.
So basically you need an URL to open a particular form.
First I suggest you to read documentation about History Mechanism. One of it's main feature is:
It’s “bookmarkable”. I.e., the user can create a bookmark to the
current state and save it, email it, et cetera.
So you will be able to create a link to a specific application state. In your case a student form.
In the EntryPoint class, in onModuleLoad() method add this:
if(History.getToken() == "student_form")
// show student form
else
// proceed as normal
Now just add a history token at the end of yous normal URL (after a # sign) like this: http://host.com/#student_form or http://host.com/page.html#student_form.

replacing Result's html

I have an URL which shows me a coupon form based on id:
GET /coupon/:couponId
All the coupon forms are different and submit different POST params to:
POST /saveCoupon/:id
I want to have a convenient way of debugging my coupons and be able to have a way of viewing actual POST params submitted.
I've made a controller on URL POST /outputPOST/saveCoupon/:id which saves nothing, but prints to browser POST params received.
Now I want to have an URL like GET /changeActionUrl/coupon/:couponId which calls GET /coupon/:couponId and then substitutes form's action URL POST /saveCoupon/:id with POST /outputPOST/saveCoupon/:id .
In other words I want to do something like:
Result.getHtml().replace("/saveCoupon/","/outputPOST/saveCoupon/");
With this I can easily debug my coupons just by adding "/outputPOST" in the browser.
You could just use a bookmarklet and javascript to replace all of the forms' action attributes. That way your developer can do it with one click instead of changing urls.
Something like this will prefix all form actions on the page with "/outputPOST".
javascript:(function(){var forms=document.getElementsByTagName('FORM');for(i=0;i<forms.length;++i){forms[i].setAttribute('action','/outputPOST'+forms[i].getAttribute('action'));}})();
I don't understand, at least not everything ;)
In general you can debug every piece of Play app using debugger (check for your favorite IDE tips how to do that) - this will be always better, faster, etc etc, than modifying code only for checking incoming values.
I.e. Idea 13+ with Play support allows for debbuging like a dream!

how to forward back to JSP page without losing the data entered in fields?

I have a simple MVC-based JSP application. Something like:
*.jsp -> ControllerServlet -> *Command.java -> *Service.java -> *DAO.java -> Oracle db
A typical link in the application looks like this:
myapp/controller?cmd=ShowEditUser&userid=55
Which causes ShowEditUserCommand.java execute() method to run and will forward to editUser.jsp
In editUser.jsp, they fill in the fields, then click Save which posts to myapp/controller?cmd=ModifyUser which runs ModifyUserCommand.java execute() method which modifies the user data and forwards to viewUser.jsp.
Everything works fine.
The problem is, in ModifyUserCommand.execute() I'm checking to see if the username is unique. If they try to enter a username that already exists, I set an error value to true and errorMessage value to Already in use.
Then because of the error I forward to the original editUser.jsp (not viewUser.jsp) and the error is displayed above the form.
MY PROBLEM IS (finally! ;) -- when the user is returned to editUser.jsp with the error message displayed, the data they entered in the fields is all blanked out. How can I set it so whatever they entered in the fields is still in place?
Any suggestions or advice are greatly appreciated!
Rob
Simplest way would be to pass the form fields back to your editUser.jsp in your forward action in ModifyUserCommand.execute(). You can do that with individual parameters i.e.
editUser.jsp?field1=1&field2=2
Alternatively, you could pass data with other methods - i.e. encoded JSON.
You can then process your fields in your editUser.jsp via the page's request object and set your form field values accordingly.
There may be other ways to do this depending on what underlying framework (if any) you are using. But this is a basic way of approaching it.

Calling Java method from HTML link

I'm currently building a Twitter client in Java using the Twitter4J API. To create a Twitter "timeline", I am currently pulling data from Twitter such as profile images, tweets and usernames, then displaying them in a JTextPane, formatted using HTML. Code example below:
StringBuilder out = new StringBuilder();
try {
List<Status> statuses = HandleEvents.instance().twitter.getHomeTimeline();
out.append("<html>");
for (Status status : statuses)
{
out.append("<img src=\"").append(status.getUser().getProfileImageURL())
.append("\" width=30 height=30><b>").append(status.getUser().getName())
.append(":</b> ").append(status.getText())
.append("<br><br>");
}
out.append("</html>");
tweetsTextPane.setText(out.toString());
This displays a timeline of 20 tweets, separated by two line breaks. Under each tweet, I would like to place a simple hyperlink, called "Retweet", which calls one of my Java methods - HandleEvents.instance().twitter.retweetStatus(status.getId())
How would I got about doing this? Can the call be made directly between the tags, or do I have to make the call using JavaScript?
Any help would be appreciated. Many thanks.
You don't really need to have a hyperlink do you? Since it's a Swing app you could just add a JLabel that only looks like a hyperlink (but if you put in a little effort, it could behave like one as well). Add a listener for mouse clicks on that JLabel and you've can hook your current handler there.
On the other hand, if you do want actual HTML links, what you can do is implement your own HyperlinkListener.
Here are a couple of examples:
http://www.java2s.com/Tutorial/Java/0240__Swing/HyperlinkListenerExample.htm
http://www.java2s.com/Code/Java/Event/DemonstratingtheHyperlinkListener.htm
http://www.devx.com/tips/Tip/12997

Java side validation (xwork2) does not work from input error page (Struts2)

I am using Struts2 with jsp pages and xwork validation. My problem is in java side validation, when I first land in input-page due to input errors and after that I leave those errors there and submit again. The very same errors should be shown but they aren't. Java file contains field errors and those are not shown anymore after second try.
What is the problem? Missing interceptor or bug in struts2? I have the following interceptors:
- com.opensymphony.xwork2.interceptor.I18nInterceptor
- com.opensymphony.xwork2.validator.ValidationInterceptor
- com.opensymphony.xwork2.interceptor.PrametersInterceptor
I read from another thread that input landing page does omit the validation somehow. How can I enable the validation also when making calls from that page?
You also need the DefaultWorkflowInterceptor, which is responsible for detecting validation errors and re-showing the form.
For any additional troubleshooting, you will need to provide your action code so that we can see what's up.

Categories