How to open a form created on GWT using QRcode? - java

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.

Related

Github Copilot + Angular - Single File approach

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.

Add confirm (Yes /No) dialog box inside Model class in Adempiere

I want to create confirm dialog box inside Model class.
I created window which has several text boxes and after entering the values user can save data. At the point of saving data I want to add a confirm dialog box asking "Are you sure to save these data ?"
So inside Model class I tried to put
org.adempiere.webui.window.FDialog.ask(1,null,"Are you sure to save these data ?");
When I add this into my code, it will give errors and I can't build the project.
If anyone knows how to add confirm dialog box in model class? Please help me to do this...
In Adempiere
For Swing Class (i.e.) model class you can use by below
int response = JOptionPane.showConfirmDialog(null, Are you sure to save these data ?
"", JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.YES_OPTION)
;
else
;
or
Adialog in Client modules cann't used in Base modules
ADialog.ask(WindowNo, null,"Are you sure to save these data ?");
FDialog Should be used only in ZKWebui package, never use zk classes in base/client modules
org.adempiere.webui.window.FDialog.ask(1,null,"Are you sure to save these data ?")
In window/tab before save you can use "Commit Warning" column in Window,Tab & field (Application Dictionary)
Hope it will helps you.
You can use JOptionPane but not ADialog or FDialog.
Usage of ADialog throws build error. As its is defined in client folder, you cant use it in the upper hierarchy.
You can find the build order from here

GWT - History.getToken() is always returning blank value

I tried to get the last visited page in my GWT application. I want to skip particular page if that comes in history. To get last visited page, I tried History.getToken() to get current token as described in docs. But it is always returning blank token.
Please help. I am beginner level developer at GWT.
Please have a look at Coding Basics History - GWT Project.
For example, a history token named page1 would be added to a URL as follows:
http://www.example.com/com.example.gwt.HistoryExample/HistoryExample.html#page1
When the application wants to push a placeholder onto the browser's history stack, it simply invokes History.newItem(token).
When the user uses the back button, a call will be made to any object that was added as a handler with History.addValueChangeHandler().
It is up to the application to restore the state according to the value of the new token.
Please validate below points in your application.
To use GWT History support, you must first embed an iframe into your host HTML page.
<iframe src="javascript:''"
id="__gwt_historyFrame"
style="position:absolute;width:0;height:0;border:0"></iframe>
Then, in your GWT application, perform the following steps:
Add a history token to the history stack when you want to enable a history event.
Create an object that implements the ValueChangeHandler interface, parses the new token (available by calling ValueChangeEvent.getValue()) and changes the application state to match.
Question : GWT - History.getToken() is always returning blank value?
Please check the URL again and confirm that you have added new history tokens to the history stack and most important is to include the history frame in your host page.
Look at the source code to understand that why you are getting blank value?
// History.class
public class History {
private static HistoryImpl impl;
static {
impl = GWT.create(HistoryImpl.class);
if (!impl.init()) {
// Set impl to null as a flag to no-op future calls.
impl = null;
// Tell the user.
GWT.log("Unable to initialize the history subsystem; did you "
+ "include the history frame in your host page? Try "
+ "<iframe src=\"javascript:''\" id='__gwt_historyFrame' "
+ "style='position:absolute;width:0;height:0;border:0'>"
+ "</iframe>");
}
}
public static String getToken() {
// impl is null if you have not included the history frame in your host page
// if impl is null then it return blank value
return impl != null ? HistoryImpl.getToken() : "";
}
}
Find a sample code here on History Management in GWT.

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

Categories