0

Pass object argument to a new window browser page

asked 2010-04-06 09:45:31 +0800

max152 gravatar image max152
15 1 1

Hi all!

I have to develop a web application in order to complete my graduate and as you've guessed i'm using zk.

I've been searching a lot about this but couldn't find what I need or maybe I haven't been able to apply the solution that i found... :s

Here's my problem : When I select an object in listbox I want to open a new browser page and pass the item selected in the listbox to that new page...

Don't know how to do that...

For now I'm using the sendRedirect method with an argument in the url :
execution.sendRedirect("/user/addreport.zul?eventid="+selected.getId(),"newwindow");

And in AddReportController , i get the id passed and send a request to my db.


I found that it is possible to set an object argument to an Include object with setDynamicProperty() method, but how to open my zul page with that argument in another web page?

Hope you understand (I'm quite confused when I explain something... particularly in english :) )

Thanks for your response

delete flag offensive retag edit

9 Replies

Sort by ยป oldest newest

answered 2010-04-07 08:53:38 +0800

xmedeko gravatar image xmedeko
1031 1 16
http://xmedeko.blogspot.c...

You can pass an object as argument if you stay on the same desktop - the same browser window. I.e. you have a page with an include tag and you change dynamically src of this tag.

If you want to open another browser window, then your method is the only possible method. Ugly workaround may be to store the object in the session and pass a key of the session object to the new window instead of database id.

Anyway, I think it is a good practise to read the object from DB prior editing. You get the DB row by ID, which is very fast. You got a fresh data (in case somebody else has change them). And you may read from DB additional info which is not shown in the listbox (e.g. lazy Hibernate relationships).

link publish delete flag offensive edit

answered 2010-04-07 10:47:01 +0800

max152 gravatar image max152
15 1 1

Ok thanks. Great to know it's not possible, anyway I'm tired of searching...

I tried with the sessionscope but the problem was if I wanted to open more than one new page, the second page was the same as the first one as I can't pass arguments between my two browser pages... The new window always gets the same object in the sessionscope...

Well you gave some good reasons to keep my method, but the greatest problem is that someone can change the id in the URL and get the information about an event that he wasn't supposed to see... :s

link publish delete flag offensive edit

answered 2010-04-07 13:30:02 +0800

xmedeko gravatar image xmedeko
1031 1 16
http://xmedeko.blogspot.c...

updated 2010-04-07 13:31:42 +0800

If you want to open the same page twice with different objects, then:
1. if you open it consecutively, then it should not be a problem. The first page grabs the parameter from the session, then put the second parameter, open the second page and it will have the second parameter.
2. if you want to open them at one time, make two random keys, put into the sessionScope two objects and pass each page a different key. In this case, I would implement my own "ObjectCache", which I would store in the session scope. This "ObjectCache" would generate random keys (e.g. UUID) for the stored objects and would delete the objects after a timeout. Also, every "get" would delete the object from the "ObjectCache" as well. Maybe you find an implementation of such cache on the web.


If your method is not secure enough for you, then
1. implement a security on the dao layer
2. make an UUID instead of integer id (i.e. randomise ids)
3. make a secret algorithm, which would map id to a string or another id, e.g. id2 = 31 * id + 7; id = (id2 - 7)/31.

The good point about "your method" is that the user may bookmark the URL and go directly to this URL next time.

link publish delete flag offensive edit

answered 2010-04-09 03:49:48 +0800

max152 gravatar image max152
15 1 1

Great now it works with both method, I did not have to use an "ObjectCache" cause it's not possible to open 2 events at the same time.

By the way I could use some help for another question if you don't mind :)

Actually I want to show the information about an event and give the possibility to the user to edit those information, to do that I use the same .zul file that I made to create a new event (that's the new page I opened with the event as argument)
The problem is that the comboboxes I used load the different values on "onOpen" event, so it doesn't show the field of the event until I open the combobox...

Is there a way to show the value of my event? Or do I have to force all the onOpen events when the page is loading?

link publish delete flag offensive edit

answered 2010-04-09 07:23:15 +0800

xmedeko gravatar image xmedeko
1031 1 16
http://xmedeko.blogspot.c...

Hmm, I do not understand your problem with comboboxes.

link publish delete flag offensive edit

answered 2010-04-09 08:21:18 +0800

max152 gravatar image max152
15 1 1

Well, here's how I create my comboboxes :

<combobox id="combohaps" autodrop="true" model="@{reportWindowCtrl.hapsname}" selectedItem="@{reportWindowCtrl.newEvent.happeningtypeID, save-when=none}"/>

The model is load when the onOpen event is triggered. Then the user chooses one item and this item is saved in a variable of an Event object. Then I can save the Event object in my db. That's how an event is created.


And I use the same .zul file and Controller to display the information about an Event. In the controller I get the event in the sessionScope and set it to "newEvent" so my zul page can access it. The problem is that the values don't appear since the model isn't loaded, I have to open a combobox and then the value is directly set to the good value.
I want the value to be displayed directly without having to open the combobox, I guess I must load all the items of all comboboxes before in order to do that...

I think I just gave the sollution to my problem...
But if you have another idea without loading all items...

Thanks

link publish delete flag offensive edit

answered 2010-04-12 02:24:13 +0800

xmedeko gravatar image xmedeko
1031 1 16
http://xmedeko.blogspot.c...

What about <combobox value="whatEverYouWant" />

link publish delete flag offensive edit

answered 2010-04-12 04:02:00 +0800

max152 gravatar image max152
15 1 1

No already tried that...
The problem is the combobox, it cant display a single value like a textbox...

link publish delete flag offensive edit

answered 2010-04-27 07:24:46 +0800

Cogito gravatar image Cogito
66 1
ZK Team

Hi max152,
Setting a value for a combobox does give it a default value without having to select its items as xmedeko illustrated.

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-04-06 09:45:31 +0800

Seen: 2,685 times

Last updated: Apr 27 '10

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