0

Combobox

asked 2010-06-01 09:19:08 +0800

mguilherme gravatar image mguilherme
132 3

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>

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2010-06-02 14:33:57 +0800

vinhvo gravatar image vinhvo
369 3

Have a look at data binding . http://docs.zkoss.org/wiki/Data_binding. You can set model and selectedItem for combobox.

link publish delete flag offensive edit

answered 2010-06-04 10:10:48 +0800

mguilherme gravatar image mguilherme
132 3

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.

link publish delete flag offensive edit

answered 2010-06-04 11:02:54 +0800

vinhvo gravatar image vinhvo
369 3

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();

link publish delete flag offensive edit

answered 2010-06-07 03:46:12 +0800

mguilherme gravatar image mguilherme
132 3

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>

link publish delete flag offensive edit

answered 2010-06-07 11:47:31 +0800

mguilherme gravatar image mguilherme
132 3

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.

link publish delete flag offensive edit

answered 2010-06-09 05:00:19 +0800

mguilherme gravatar image mguilherme
132 3

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();
  }
  
}

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-06-01 09:19:08 +0800

Seen: 485 times

Last updated: Jun 09 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More