1

I have created a search word example but it seems that is not doing the string search when the button is clicked against a constant properly.

HTML:

<h1>Java Dictionary</h1>
<hr>
<h2 data-bind="text: searchPhrase"></h2>
<button data-bind:"click: changeFP">Search</button>

<h2 data-bind="text: foundPhrase, enable:isInCatalog"></h2>

JAVA:

package dew.demo.ko4j;
import net.java.html.json.*;

@Model(className="Dictionary", properties={
  @Property(name="searchPhrase", type=String.class),
  @Property(name="foundPhrase", type=String.class)
})

class Demo {

  @ComputedProperty static boolean isInCatalog(String searchPhrase) {
    if(searchPhrase.equalsIgnoreCase("Hello World!")){
      return true;
    }
     return false;
  }  

  @Function static void changeFP(Dictionary model){
    if( model.isIsInCatalog( ) ){
        model.setFoundPhrase("found");
    }
  }

  static {
    Dictionary model=new Dictionary("Hello World!","please click to search");
    model.applyBindings();
  }
}

PS: Please use DEW to try the example because it's where I tested.

EDIT: Ideal Scenario

  1. the window shows "Hello World!" and "please cick to search" messages.
  2. user clicks button button
  3. "please cick to search" message changes to "found"
Ruslan López
  • 4,433
  • 2
  • 26
  • 37
  • Please edit your question to describe what is actually going wrong. What behavior have you observed? What were you expecting? Are there any error messages? What do they say? – Kenster Nov 14 '15 at 18:30
  • no error messages, as it says the problem is `it seems that is not doing the string search against a constant properly.` so obviously I expected to do the string search – Ruslan López Nov 14 '15 at 18:32

1 Answers1

0

DEW should have shown you one syntax error in your HTML code by highlighting it in red color. The data-bind attribute on button is no valid html. You're using a colon ":" instead of equals "=". Therefore your action is never called.

When using NetBeans it's easier to spot, because NB also gives you the error message explaining what is wrong.

Here's the updated example.

monacotoni
  • 606
  • 5
  • 18