-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Dear All:
I have been enjoying learning ZK framework and trying my best to figure out my questions as I get along.
Now I am having a question which could not really be solved by myself, can anyone offer me a hint?
The question is the following:
My Goal: (similar to database search function)
(done) implement a textbox for user input;
(done) apply a onChanging event listener to capture user input for further processing (database transactions) ;
(stuck) automatically clear the textbox after this;
My Question:
The program does not clear text, unless the user input is not found in the database then next time after the user input
automatic text clear will happen. What change can i make so that the automatic text clear will happen every time after
the user input?
The following is the code snippet:
public void onChanging$itemBox(InputEvent event){
String searched = event.getValue();
Item availiableItem = ItemDao.findById(searched);
if(availiableItem!= null){
TransactionClient(availiableItem);
transactionList.setModel(new ListModelList(transactionsNow));
}
itemBox.setText(null);
}
What went wrong, should I change the onChanging to something else?
Your response will be highly appreciated!!
Jezreel
}
Jezreel,
Try clearing your textbox like this instead:
itemBox.setValue(null);
<textbox value="XXXXXX" onCreate="self.setFocus(true)" onChanging='alert("onChanging=" + self.getValue())' onChanged='alert("onChanged=" + self.getValue())'/>
Hope that helps,
Todd
Thanks Todd for the prompt reply.
I tried
itemBox.setValue(null);
I understand what you mean by the difference between onChanged and onChanging. However when I tried to use onChanged, it does not work at all.
The following is my textbox definition in zul file.
textbox id="itemBox" focus="true"/>
Here is the desired behaviour of the textbox:
> capture input from the user (implemented a onChanging event listener)(maybe another type of listener instead??? onChanged has been tried and not working)
> process on the server side (done)
>generate output to the user (done)
> clear text after user input (problematic, it only clears the input after the user input is not found and the user gives an input again )
> allow for user input (could be same as before but still capture the input) (problematic,
if the user gives the same input, event listener will not be invoked, reason is obvious)
Any more suggestions?
Jezreel
Also I noticed with the original code:
public void onChanging$itemBox(InputEvent event){ String searched = event.getValue(); <b >Item availiableItem = ItemDao.findById(searched);</b> if(availiableItem!= null){ TransactionClient(availiableItem); transactionList.setModel(new ListModelList(transactionsNow)); } itemBox.setValue(null); }
The DAO is implemented simply as following:
public Item findByBarcode(String barcode){ Session sess = currentSession(); return (Item) sess.load(Item.class,barcode); }
It would not return anything but throws an error message if the object is not found, what can i do to fix the problem of clearing text only after an error message and then gives an input which is found in the database instead of clearing the text each time of a user input.
Thanks for your help
If you want to try the other event type, it's called "onChange", not "onChanged".
However, that event is not posted while the user is typing, only afterwards.
Also please note that you cannot reliably read or write the textbox value within "onChanging", because
1. The textbox value has not changed yet so getValue() will return the old value
2. The textbox value will change later (even if you set it to null, it will be overriden later once onChange event is posted)
i try to clear Textbox based my code
http://www.zkoss.org/forum/listComment/18963-Integrate-Spring-MVC-Hibernate-with-ZK
so i modification like this to clear textbox but, i get error
public void onBtnClick(Event evt){ try{ //get form data from zul page String codeValue = code.getValue(); String descriptionValue = description.getValue(); department=new Department(); department.setCode(codeValue); department.setDescription(descriptionValue); departmentService.save(department); //show message box Messagebox.show("Save success"); //clear textbox code = ((Textbox)evt.getTarget().getFellow("code")); code.setValue(""); }catch(Exception e){ e.printStackTrace(); } }
error
SEVERE: org.zkoss.zk.ui.WrongValueException: Enter proper text at org.zkoss.zul.SimpleConstraint.wrongValue(SimpleConstraint.java:365) at org.zkoss.zul.SimpleConstraint.validate(SimpleConstraint.java:336) at org.zkoss.zul.impl.InputElement.validate(InputElement.java:319) at org.zkoss.zul.impl.InputElement.setText(InputElement.java:270) at org.zkoss.zul.Textbox.setValue(Textbox.java:55)
how to clear textbox for my code?
thanks
Asked: 2011-12-20 08:52:25 +0800
Seen: 467 times
Last updated: Mar 22 '12