0

java.lang.IllegalStateException: Access denied: component, <Listbox addressLb>, belongs to another d

asked 2010-03-11 04:34:04 +0800

xnguyen gravatar image xnguyen
30 3

updated 2010-03-11 04:53:31 +0800

I'm getting the following exception when I leave my editPatientDemographics.zul page and come back to that same page to add/delete another row in my addressLb listbox. Notice that I have not declared any static variables:

org.zkoss.zk.ui.impl.UiEngineImpl handleError:1114
SEVERE: >>java.lang.IllegalStateException: Access denied: component, <Listbox addressLb>, belongs to another desktop: [Desktop g0k61:/secure/patient/editPatientDemographics.zul]
>> at org.zkoss.zk.ui.impl.UiVisualizer.checkDesktop(UiVisualizer.java:218)
>> at org.zkoss.zk.ui.impl.UiVisualizer.getAttrRespMap(UiVisualizer.java:271)
>> at org.zkoss.zk.ui.impl.UiVisualizer.addSmartUpdate(UiVisualizer.java:226)
>> at org.zkoss.zk.ui.impl.UiEngineImpl.addSmartUpdate(UiEngineImpl.java:255)
>> at org.zkoss.zk.ui.AbstractComponent.smartUpdate(AbstractComponent.java:1362)
>> at org.zkoss.zul.Listbox.smartUpdate(Listbox.java:1605)
>>...

EditPatientDemographicsController.java

package com.loquatic.cerescan.controller.patient;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.zkoss.zk.ui.event.MouseEvent;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Label;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;

import com.cerescan.api.entities.Address;
import com.cerescan.api.entities.Patient;
import com.cerescan.api.persistence.managers.PatientManager;
import com.loquatic.cerescan.view.ErrorLabel;

public class EditPatientDemographicsController extends GenericForwardComposer {
	private static Log log = LogFactory
			.getLog(EditPatientDemographicsController.class);
	private Patient patient;
	private ErrorLabel errLbl;
	private Label successLbl;
	// patient

	// address
	private Listbox addressLb;
	private Textbox street1Tb;
	private Textbox street2Tb;
	private Textbox cityTb;
	private Textbox stateTb;
	private Textbox zipCodeTb;
	private Textbox cityCodeTb;

	public boolean isValid() {
		List<String> errs = new ArrayList<String>();
		if (patient.getLastName() == null
				|| patient.getLastName().trim().equals("")) {
			errs.add("Please Enter the Patient's Last name");
		}
		if (patient.getFirstName() == null
				|| patient.getFirstName().trim().equals("")) {
			errs.add("Please Enter the Patient's First name");
		}
		if (patient.getMrNumber() == null
				|| patient.getMrNumber().trim().equals("")) {
			errs.add("Please Enter the Patient's Medical Record Number (MR#)");
		}
		if (patient.getGender() == null
				|| patient.getGender().trim().equals("")) {
			errs.add("Please Enter the Patient's Gender");
		}
		if (patient.getDateOfBirth() == null) {
			errs.add("Please Enter the Patient's Date of Birth (DOB)");
		}
		// check to see if MR already exist for another patient
		Patient _patient = PatientManager.findByMrNumber(patient.getMrNumber());
		if (_patient != null && (_patient.getId() != patient.getId())) {
			errs.add("Patient MR# " + patient.getMrNumber() + " already exist");
		}

		if (errs.isEmpty() == false) {
			errLbl.setVisible(true);
			errLbl.setErrs(errs);
		} else {
			errLbl.setVisible(false);
		}
		return errs.isEmpty();
	}

	public void persistPatient() {
		if (isValid()) {
			PatientManager.merge(patient);
			log.debug(patient);
			successLbl.setValue("Successfully Updated Patient Information");
			successLbl.setVisible(true);
		}
	}

	public void onClick$addAddressBtn(MouseEvent event) {
		Address address = new Address();
		address.setStreet1(street1Tb.getValue());
		address.setStreet2(street2Tb.getValue());
		address.setCity(cityTb.getValue());
		address.setState(stateTb.getValue());
		address.setZipCode(zipCodeTb.getValue());
		address.setCityCode(cityCodeTb.getValue());
		List<Address> addresses = (List<Address>) addressLb.getModel();
		addresses.add(address);
		patient.setAddresses(addresses);
		persistPatient();

		street1Tb.setValue("");
		street2Tb.setValue("");
		cityTb.setValue("");
		stateTb.setValue("");
		zipCodeTb.setValue("");
		cityCodeTb.setValue("");
	}

	public void onClick$deleteAddressBtn(MouseEvent event) {
		for (Listitem listitem : (Set<Listitem>) addressLb.getSelectedItems()) {
			Address address = (Address) listitem.getValue();
			List<Address> addresses = (List<Address>) addressLb.getModel();
			addresses.remove(address);
			patient.setAddresses(addresses);
			persistPatient();
		}
	}

	public void onClick$updateBtn(MouseEvent event) {
		persistPatient();
	}

	public void onOK() {
		persistPatient();
	}
}

editPatientDemographics.zul:
<?page title="Edit Patient Demographics Information" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?component name="error" extends="label" class="com.loquatic.cerescan.view.ErrorLabel"?>
<zk>
	<zscript>
	<![CDATA[
	import com.cerescan.api.entities.Patient;
	import com.cerescan.api.persistence.managers.PatientManager;
	long patientId = (Long) Sessions.getCurrent().getAttribute("patientId");
	Patient patient = PatientManager.findById(patientId);
]]>
</zscript>
	<window id="editPatientWin" width="750px"
		title="Edit Patient Demographics Information" border="normal"
		apply="com.loquatic.cerescan.controller.patient.EditPatientDemographicsController">
		<error id="errLbl" style="color:#DD7870" multiline="true" />
		<label id="successLbl" style="color:green" multiline="true" />
		<groupbox mold="3d">
			<caption label="Patient Information" />
			<grid>
				<rows>
					<row>
						<cell>
							<label value="Last Name" />
							:*
						</cell>
						<cell>
							<textbox id="lastNameTb" focus="true"
								cols="10" value="@{patient.lastName}" />
						</cell>
						<cell>
							<label value="First Name" />
							:*
						</cell>
						<cell>
							<textbox id="firstNameTb" cols="10"
								value="@{patient.firstName}" />
						</cell>
						<cell>
							<label value="MI" />
							:
						</cell>
						<cell>
							<textbox id="miTb" cols="1" maxlength="1"
								value="@{patient.middleInitial}" />
						</cell>
					</row>
					<row>
						<cell>
							<label value="DOB" />
							:*
						</cell>
						<cell>
							<datebox id="dateOfBirthDb"
								value="@{patient.dateOfBirth}" />
						</cell>
						<cell>
							<label value="Gender" />
							:*
						</cell>
						<cell>
							<listbox id="genderLb" rows="1"
								mold="select" selectedItem="@{patient.gender}">
								<listitem label="Select One" value="" />
								<listitem label="Female" value="F" />
								<listitem label="Male" value="M" />
							</listbox>
						</cell>
						<cell>
							<label value="MR" />
							:* :
						</cell>
						<cell>
							<textbox id="mrTb" cols="10"
								value="@{patient.mrNumber}" />
						</cell>
					</row>
				</rows>
			</grid>
		</groupbox>
		<separator />
		<groupbox mold="3d">
			<caption label="Address Information" />
			<listbox id="addressLb" model="@{patient.addresses}"
				selectedItem="@{selectedAddress}">
				<listhead>
					<listheader label="Street1" />
					<listheader label="Street2" width="150px" />
					<listheader label="City" width="100px" />
					<listheader label="State" width="50px" />
					<listheader label="Zip" width="75px" />
					<listheader label="City Code" width="75px" />
				</listhead>
				<listitem id="addressLi" self="@{each='address'}"
					value="@{address}">
					<listcell label="@{address.street1}" />
					<listcell label="@{address.street2}" />
					<listcell label="@{address.city}" />
					<listcell label="@{address.state}" />
					<listcell label="@{address.zipCode}" />
					<listcell label="@{address.cityCode}" />
				</listitem>
			</listbox>
			<separator />
			<grid>
				<rows>
					<row>
						<cell width="100px">
							<label value="Address" />
							:
						</cell>
						<cell colspan="4">
							<textbox id="street1Tb" cols="50"
								maxlength="100" />
						</cell>
					</row>
					<row>
						<cell width="100px"></cell>
						<cell colspan="4">
							<textbox id="street2Tb" cols="50"
								maxlength="100" />
						</cell>
					</row>
					<row>
						<cell></cell>
						<cell>
							<label value="City" />
							:
							<textbox id="cityTb" cols="12"
								maxlength="20" />
						</cell>
						<cell>
							<label value="State" />
							:
							<textbox id="stateTb" maxlength="2"
								cols="2" />
						</cell>
						<cell>
							<label value="Zip" />
							:
							<textbox id="zipCodeTb" cols="7"
								maxlength="10" />
						</cell>
						<cell>
							<label value="City Code" />
							:
							<textbox id="cityCodeTb" cols="7"
								maxlength="10" />
						</cell>
					</row>
					<row>
						<cell colspan="5">
							<button id="addAddressBtn" label="Add" />
							<button id="deleteAddressBtn"
								label="Delete" />
						</cell>
					</row>
				</rows>
			</grid>
		</groupbox>
		<button id="updateBtn" label="Update" />
	</window>
</zk>
[

Thanks for you help in advance!

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2010-03-12 03:32:24 +0800

xnguyen gravatar image xnguyen
30 3

I think the issue is declaring this in my zul file

<zk>
	<zscript>
	<![CDATA[
	import com.cerescan.api.entities.Patient;
	import com.cerescan.api.persistence.managers.PatientManager;
	long patientId = (Long) Sessions.getCurrent().getAttribute("patientId");
	Patient patient = PatientManager.findById(patientId);
]]>
</zscript>

I removed it and it seemed to go away.

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-03-11 04:34:04 +0800

Seen: 764 times

Last updated: Mar 12 '10

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