I've implemented a MatchPage which displays the following informations:
MatchStatus (OPEN/CLOSED)
Winner (Name of the Winner)
Form to upload files
(follow the link to see how it looks like, [1]: http://www10.pic-upload.de/25.04.13/klmy9fe8cgk3.png)
Now here comes the problem. Let's assume, someone is reporting a result while another one has currently open the specific MatchPage. When the report is done, the MatchStatus will change from OPEN to CLOSED, the color will change from OPEN=green to CLOSED=red, the Winner will be set and the Form for uploading files will disappear (see [2]: http://www7.pic-upload.de/25.04.13/9diu5bcbws9.png).
The player who reported the result will see the updated MatchPage while the other one will still see the old version of the MatchPage, even if he refreshed the browser.
I could solve the problem with OPEN/CLOSED by using my own LoadableDetachableModel:
#Override
public String load()
{
Match m = dao.getMatchFromID(match_id);
String result = "OPEN";
if (m.getClosed())
{
result = "CLOSED";
reportForm.setVisible(false); //does not work
colorBehavior.setColor("red"); //does not work
}
return result;
}
Label on my MatchPage:
matchStatus = new Label("matchStatus", new MyMatchModel(m.getMatch_id(), matchDAO, reportForm));
As you can see on the load() method, setting the reportForm invisible and setting the color to red does not work.
Any idea how i can solve such kind of problem? How can i make the form disappear and change the color to red when the user pressed F5/refresh the browser.
You should override the "isVisible()" method of the form like this:
public boolean isVisible() {
return !yourModel.getObject().getClosed();
}
Related
I have automated a new customer form for work, but there are a lot of options and based on how questions are answered , different fields need to be filled out. Rather than just make a copy of the code and make a different script for each option, I'd like to do this by passing values to a class that determines what options are chosen based on what is passed in. I'm trying to figure most of this out myself and I'm somewhat of a n00b, but if someone can get me past the first hurdle, I'd like to tackle the rest of the hurdles myself.
So I want to start by just doing one line of the script this way, and eventually I will do more. Up front, it is going to seem like a lot of code just to do this, but here is the line:
driver.findElement(By.id("OrganizationName")).sendKeys("The Rolling Stones");
Here is what I have so far:
ncformPage1 skifootz = new ncformPage1("Rolling Stones");
skifootz.getOrgname();
That is the part that is in the script. Here is the class I wrote:
public class ncformPage1 {
private String orgName;
public ncformPage1(String on) {
orgName = on;
}
public String getOrgname() { return "driver.findElement(By.id(\"OrganizationName\")).sendKeys(\""
+ orgName + "\");";
}
}
So when I run this, it goes right past that organizationName element and leaves it blank, does all the other elements, and then fails because organization name is a required field. So I added this bit of code here to see what it prints out to the console:
System.out.println( skifootz.getOrgname());
Sure enough, it prints out
driver.findElement(By.id("OrganizationName")).sendKeys("Rolling Stones");
Which is exactly what I want returned. (I think the last semicolon is extraneous in this case, but at least it returned what I wanted!) But it doesn't execute that. I've tried all kinds of stuff to get it to execute, such as removing driver from what is returned and appending it here instead:
driver.skifootz.getOrgname();
but that gives me skifootz cannot be resolved or is not a field. I tried this:
String a = skifootz.getOrgname();
driver.a();
But that just made a get underlined in red saying method a() is undefined for the type Webdriver. So then I changed String a to Webdriver a:
WebDriver a = skifootz.getOrgname();
driver.a();
But now skifootz.getOrgname(); is underlined saying "type mismatch: cannot convert from String to WebDriver." I've been messing around with it for a few days now, and I haven't gotten any closer. Maybe this is an easy solution, but if I can just get this part working then perhaps I can move on to the next phase? This n00b thanks everyone in advance for any help anyone can give.
The method is returning a String type and you expect it to act like a driver object. That part is incorrect.
I think you can write methods to be more like
public WebElement getOrgname(WebDriver driver, String OrganizationName) {
return driver.findElement(By.id(OrganizationName));
}
WebElement a = skifootz.getOrgname(driver);
a.sendKeys("Rolling Stones");
OR
public void TypeText(WebDriver driver, String OrganizationName, String TextToType) {
driver.findElement(By.id(OrganizationName)).sendKeys(TextToType);;
}
in your context this should probably work.
ncformPage1 skifootz = new ncformPage1();
skifootz.getOrgname(skifootz.driver, "OrganizationName");
skifootz.sendKeys("Rolling Stones");
public class ncformPage1 {
private String orgName;
public WebDriver driver = new ChromeDriver(); // I'm assuming this part.
public ncformPage1(String on) {
orgName = on;
}
public WebElement getOrgname(WebDriver driver, String OrganizationName) {
return driver.findElement(By.id(OrganizationName));
}
}
I'm not really sure if i have understood the principe of the DataFlavors correctly, but how can i actually set the DataFlavor(s) of a JComponent?
Every time i call the getDataFlavor method the output is this:
java.awt.datatransfer.DataFlavor[mimetype=application/x-java-file-list;representationclass=java.util.List]
My problem is, that i want to drag images from the desktop or any other place right into my JPanel. It's working through the DataFlavor.javaFileListFlavor, but is there no way that i can create a custom flavor which only accepts PNG and JPG Files for example?
(I know that it is actually possible to create Custom Flavors but i have no clue how i can "enable" the new created flavors for my components)
Or is there a way to ensure whether the dragged in Item is a PNG or JPG with the javaFileListFlavor?
I hope that i could explain my question well enough (I'm not a master of this language, but i'm trying my best ;) )
Or is there a way to ensure whether the dragged in Item is a PNG or JPG with the javaFileListFlavor?
Take a look at the Swing tutorial on Top Level Drop. It shows how to drag a file from the desktop to a JTextArea.
Take a look at the canImport(...) and importData(...) methods of the TransferHandler. The canImport(...) method currently only checks that you have a FileListFlavor. So you would need to add extra logic to see the actual File is a PNG or JPG.
If you look at the importData(...) method you can see how to get the File object from the TransferSupport object so you can implement the above check.
Edit:
but as described the Exception pops up
I just ignore the Exception. Here is the modified code for the tutorial that only allows your to copy ".java" files into the text area.
private TransferHandler handler = new TransferHandler() {
public boolean canImport(TransferHandler.TransferSupport support) {
if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
return false;
}
Transferable t = support.getTransferable();
try
{
java.util.List<File> l = (java.util.List<File>)t.getTransferData(DataFlavor.javaFileListFlavor);
File file = l.get(0);
String fileName = file.getName();
if (!file.getName().endsWith(".java"))
return false;
}
catch (Exception e)
{
// ignore
}
if (copyItem.isSelected()) {
boolean copySupported = (COPY & support.getSourceDropActions()) == COPY;
if (!copySupported) {
return false;
}
support.setDropAction(COPY);
}
return true;
}
Works fine for me using JDK8 on Winodow 7.
I'm using gxt 2.0.3 in Java and I have created a SimpleComboBox which I then populate with 2 strings.
final SimpleComboBox<String> accessedComboBox = new SimpleComboBox<String>();
accessedComboBox.setTriggerAction(TriggerAction.ALL);
accessedComboBox.setEmptyText("Select a type");
accessedComboBox.add("Method 1");
accessedComboBox.add("Method 2");
I also have a listener attached to a different SimpleComboBox and depending on what is selected I need to either add or remove the value from the above accessedComboBox
if (typeComboBox.getSimpleValue() == "Type 1")
{
//Remove desktop app option
accessedComboBox.remove("Method 2");
}
else
{
if (accessedComboBox.??) { // <--- Check to see whether desktop app is an option
//if not then add it
accessedComboBox.add("Method 2");
}
}
I can't work out what function to use to check the see whether an option already exists in the SimpleComboBox. I have looked in this documentation but I've still had no luck.
Can anyone help?
Not sure if you got this yet. It's a little funky, but you can get the String values from the ListStore. Something like this:
for (SimpleComboValue<String> value : accessedComboBox.getStore().getModels()) {
if (!value.getValue().equals("Method 1")){
accessedComboBox.add("Method 1");
}
}
I have a boolean inside a Checkbox and i want to validate if it is set to True.
So my entitie object looks kind of like this
#Validate("required,min=1")
private int Int1;
In my tml File (im using Tapestry 5.3.8) there is a Textfield which allows me to set a value for Int1
this works perfectly. If i put something else then an numeric number (or an int small 1) it shows me an error dialog.
but i can't figure out how to do that with a boolean. It needs to be checked an the user should get the same behauvior as with Int1 on a false entry.
Think of it like an Agree to the TOS checkbox which allways has to be checked to proceed.
Greetings Ilja
If I'm not mistaken a checkbox works with a boolean. So the following should achieve your result:
#Component(id = "agreeCheckbox")
private Checkbox agreeCheckbox;
#OnEvent(component = "agreeCheckbox", value = EventConstants.VALIDATE)
private void handleAgreeValidate(boolean agree) {
if(!agree) {
throw new ValidationException("Hey there! You have to agree or we can't do business with you.");
}
}
Disclaimer: I have not tested this code.
I'm looking for a PrimeFaces 4.0 Component to provide little messages like Facebook does in the upper right corner by clicking on the earth symbol.
Any idea?
You could adapt Primefaces Notification Bar for your needs, but to be honest it rather looks like a job for this famous "do-it-yourself" component to me.
In fact, there really seemed to be no ready-to-use component. I'n experimenting with dynamic menues which seems to offer the right functionality. But I'm currently fighting with presenting it as cute as possible ... which of course is the real challenge.
In the facelet it's nothing more than
<p:menu model="#{nachrichtTeaserController.unreadMenu}"/>
and the controller looks soemthing like
...
private List<Nachricht> unread;
private MenuModel unreadMenu;
...
public void initUnread() {
unread = nachrichtFacade.findAllUnread(
personLoginController.getCurrentUser().getMandant(),
personLoginController.getCurrentUser());
unreadMenu = new DefaultMenuModel();
Integer menuItemId = 1;
for (Nachricht nachricht : unread) {
menuItemId++;
DefaultMenuItem menuItem = new DefaultMenuItem(nachricht.getTeaserText());
menuItem.setId(menuItemId.toString());
String nachrichtIdString = nachricht.getId().toString();
menuItem.setCommand("#{nachrichtTeaserController.show('" + nachrichtIdString + "')}");
//menuItem.setCommand(String.format("#{nachrichtTeaserController.show('%d')}",unread.indexOf(n)));
unreadMenu.addElement(menuItem);
}
}
...
public String show(String nachrichtIdString) {
Long nachrichtId = Long.valueOf(nachrichtIdString);
Nachricht nachricht = nachrichtFacade.find(nachrichtId);
return show(nachricht);
}
Two points:
It's important to use menuItem.setId(menuItemId.toString());
otherwise you'll get an NullPointerexception somewhere deep in
PrimeFaces ...
and please consider how to do "row selection" - I mean: It's easy
to call show() but it's necessary to get some information in
show() about which MenuItem was clicked. Unfortunately one cannot pass a reference to the nachricht so I use the primary key.