-
FEATURED COMPONENTS
First time here? Check out the FAQ!
How do I get my combo with all the options and the right one selected?
Class Task:
@Entity @Table(name="tasks") public class Task { private long id; private String title; private String owner; ... private TaskState state; //Omitting getters and Setters }
Class TaskState:
@Entity @Table(name="tasks_state") public class TaskState { private long id; private String title; private int value;
detail.zul:
<zscript> <![CDATA[ task = new com.ecosphere.data.dao.TaskDAO().findById(new Long(2)); // Returns a List<?> allStates = new com.ecosphere.data.dao.TaskStateDAO().findAll(); // Returns a List<?> ]]> </zscript> <grid> <columns> <column label="" width="150px" /> <column label="" /> </columns> <rows> <row> <label value="Titulo" /> <textbox value="${task.title}" readonly="true" /> </row> ... <row> <combobox>This is my problem</combobox> </row> </rows> </grid>
I don't think this will solve my problem, I can access the selected item and I can access my states, but what I need is to return my task with attributes, including the states and the one is selected.
I do not quite get you but may be you can have :
<combobox id="cbSite"
model="@{editUserWin$composer.availableSites}"
>
<comboitem self="@{each=site}"
label="@{site.name}" value="@{site}" />
</combobox>
And you can Site s= cbSite.getSelectedItem.getValue();
Can we built the combobox in another way?
My combo already shows the content, I only need the default item:
<combobox selectedItem="${task.state}"> <comboitem forEach="${allStates}" label="${each.title}" id="${each.id}" value="${each.id}" /> </combobox>
Ok, I'm now using data binding.
<combobox model="@{allStates}" selectedItem="@{state}" value="@{state.title}" width="178px" readonly="true"> <comboitem self="@{each=state}" label="@{state.title}" value="@{state.id}" /> </combobox>
Now I need a way to get onChange or onSelect of my combobox to invoke some method on my controller to call my DAO so I can commit on DB.
Here is my controller. I hope it helps someone:
public class TaskDetailController extends GenericForwardComposer{ private static final long serialVersionUID = -8374434488426802707L; public static final String CONTROLLER = "controller"; public static final String TASK_ID = "taskId"; public Task taskBean; public List<TaskState> statesBean; private AnnotateDataBinder binder; @Override public void doAfterCompose(Component win) throws Exception{ super.doAfterCompose(win); win.setAttribute(CONTROLLER, this); taskBean = new TaskDAO().findById(Long.parseLong((String) arg.get(TASK_ID))); statesBean = new TaskStateDAO().findAll(); } public void onCreate$taskDetailWindow(ForwardEvent event) { // get the databinder for later extra load and save // note: binder is not ready in doAfterCompose, so do it here binder = (AnnotateDataBinder) event.getTarget().getAttribute("binder"); } /** * Saves the Task Bean */ public void onClick$save(Event event) { new TaskDAO().saveOrUpdate(taskBean); alert("O estado da tarefa foi actualizado com sucesso."); System.out.println("Bean Updated"); Window win = (Window) event.getTarget(); win.detach(); } /** * Closes the Task detail window */ public void onClick$close(Event event) { Window win = (Window) event.getTarget(); win.detach(); } }
Asked: 2010-06-01 09:19:08 +0800
Seen: 485 times
Last updated: Jun 09 '10