-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Dear All,
I wrote a hql query for searching multiple criteria as follows.
@SuppressWarnings("unchecked")
public List<Item> findAllAdvance(String advance) {
String hql = "FROM Item WHERE description = ? and multi = ? and charge = ? ";
return getHibernateTemplate().find(hql, advance);
}
And then wrote a java class and its implementation like this.
public void submit2(){
String advance = ((Textbox)getFellow("advance")).getValue().trim();
Listbox listbox = (Listbox)getFellow("items");
listbox.getItems().clear();
ApplicationContext ctx =
WebApplicationContextUtils.getRequiredWebApplicationContext(
(ServletContext)getDesktop().getWebApp().getNativeContext());
Adminop admin = (Adminop)ctx.getBean("adminop");
List<Item> items = admin.getSearchedItem2(advance);
Iterator<Item> it = items.iterator();
while(it.hasNext()){
Item item = (Item)it.next();
Listitem li = new Listitem();
li.setValue(item);
li.appendChild(new Listcell(item.getFilepath()));
li.appendChild(new Listcell(item.getStrform()));
li.appendChild(new Listcell(item.getDescription()));
li.appendChild(new Listcell(item.getQcmeth()));
li.appendChild(new Listcell(item.getBasisset()));
li.appendChild(new Listcell(item.getInfo()));
li.appendChild(new Listcell(item.getPg()));
li.appendChild(new Listcell(item.getEs()));
li.appendChild(new Listcell(item.getMulti()));
li.appendChild(new Listcell(item.getCharge()));
li.appendChild(new Listcell(item.getEnergy()));
li.appendChild(new Listcell(item.getEnthalpy()));
listbox.appendChild(li);
}
}
The problem is,
If I write the 3 strings, let's say "cysteine 1 0", in the textbox with the id "advance" and run it,
it doesn't recognise it as 3 separated parameters [1] [0] but only as a single parameter [cysteine 1 0].
how could I make it that the strings which I wrote in the textbox can be recognised as 3 parameters, so that hql can know?
@TerryTornado
Thanx for the reply,
Sorry that I posted my thread twice, since I clicked the wrong category.
I would like to do it in three text boxes, but I'm still novice, so I don't know how to do it.
So the only solution is to constraint the input with fixed rule.
If you can tell me how to write three input parameters in three different textboxes, I would be really happy.
I solved the problem yesterday night, that instead of single string, one shall write an array like this in DAO,
public List<Item> findAllAdvance(String[] advance)
and respectively in the implementation,
@SuppressWarnings("unchecked")
public List<Item> findAllAdvance(String[] advance) {
String hql = "FROM Item WHERE description = ? or multi = ? or charge = ? ";
return getHibernateTemplate().find(hql, advance);
}
And the java class to search and list it, and split the strings
public void submit2(){
String advance = ((Textbox)getFellow("advance")).getValue().trim();
String [] temp = null;
temp = advance.split(",");
Listbox listbox = (Listbox)getFellow("items");
listbox.getItems().clear();
ApplicationContext ctx =
WebApplicationContextUtils.getRequiredWebApplicationContext(
(ServletContext)getDesktop().getWebApp().getNativeContext());
Adminop admin = (Adminop)ctx.getBean("adminop");
List<Item> items = admin.getSearchedItem2(temp);
Iterator<Item> it = items.iterator();
...etc.
You have do it with ONE testbox, so you can try with 3 textboxes too and give the 3 values as params to your backend service methode.
<textbox id="tb_description"> <textbox id="tb_multi"> <textbox id="tb_charge">
@SuppressWarnings("unchecked") @Override public List<Order> findAllAdvance(String aDescription , String aMulti , String aCharge ) { DetachedCriteria criteria = DetachedCriteria.forClass(Item .class); criteria.add(Restrictions.eq("description", aDescription )); criteria.add(Restrictions.eq("multi", aMulti )); criteria.add(Restrictions.eq("charge", aCharge)); return getHibernateTemplate().findByCriteria(criteria); }
best
Stephan
@Stephan
Großartig! vielen Dank Stephan.
It works well. But why did you write List<Order> instead List<Item>?
I still have one problem, I would like to separate that search window to another .zul file, say "search.zul". So by clicking a special button from the main site, a window will show up with those three text boxes. And if one enters 3 parameters it will search, and show the results again in the main window. How could I realise this?
Again many thanks for you!
Hi Joh,
yes i mean List<item>. (The method are copy / paste and modified). I forgot to change 'Order' to 'Item'
You can have a look at my sample app here and test it online and checkout the codes.
The customer modul have an own special modal search dialog with a few textbox fields that you can adapted to your needs.
best
Stephan
Hi Stephan,
I solved the problem yesterday using Path.getComponent(etc...) and doModal Window for the search function.
I found an interesting part from your sample application. If one double click the customer list and click the edit button, the information from the list will be showed up in the edit window.
But since I'm still newbie, I can't understand fully your code. How did you do this actually?
I tried like this but failed,
My AdminWindow.java
public void onEdit() throws SuspendNotAllowedException, InterruptedException{
Listbox listbox = (Listbox)getFellow("items");
Listitem lt = listbox.getSelectedItem();
String filepath = ((de.qcdb.lmu.domain.Item)lt.getValue()).getFilepath();
Textbox tb_filepath = new Textbox();
tb_filepath.setValue(filepath);
Window win = (Window)Executions.createComponents("edit.zul", null, null);
win.doModal();
}
And the main window "Root.zul" consists a button
<button label="Edit" onClick="adminWnd.onEdit()" />
And my edit.zul
File Path:
<textbox value="${editWnd????}" id="tb_filepath" />
How to pass the value of the selected things to the textbox?
Thanks in advance
Hi JoH,
The sample codes (2 projects = frontend + backend) are fully configured eclipse projects. You must only checkout and imported in your eclipse workspace.
Than you can start the zk_sample_gui with 'Run as', 'Run on server'. So you can debug all things.
The construction for all modules are equal.
menu(calls) --> listController + ItemRenderers (calls) --> DialogController
Unlike your construction i do overhanded a Map with parameters when i call Executions.createComponents() . So if i select or doubleClicked a listboxes row
the ListItem is casted to the object i.e. Customer and put it as a parameter in the Map.
In the DialogWindow onCreate$Window() i read back the params and in the case of a Customer object i set the zul-component values with the customers attributs.
That's all. Please have a look at the codes for such a menu entry like 'Branches'
All codes are working without databinding.
If you are new to ZK please read first all texts about Composers.
Stephan
PS: Hope that the complete refactoring of the sample app is ready before christmas.
Asked: 2009-12-10 08:38:09 +0800
Seen: 911 times
Last updated: Dec 15 '09