1

Change include source content

asked 2014-01-03 08:17:01 +0800

MDHK gravatar image MDHK
11 1

My program separated into 2 areas, the left is menu, the right is content, then i use the template to do that. <zk> <include id="mainInclude" self="@define(content)" src="/home.zul"/> </zk>

now, i need add an authorization checking for each page, if not allow to access, then i will set the include source on the right area.

if(page.getFellowIfAny("mainInclude")!=null){
Include mainInclude = (Include)page.getFellow("mainInclude"); if(mainInclude!=null){ String p = mainInclude.getSrc(); if(p.equals("prcreate.zul")){
mainInclude.setSrc("/access
denied.zul"); } }

The result of program is the accessdenied.zul content and home.zul would be include at the same time, i would like to just show the accessdenied.zul content, anyone know what's the program? Thank you very much.

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-01-16 06:59:13 +0800

rmuetzner gravatar image rmuetzner
22 3

Please try following:

mainInclude.setSrc(null);
mainInclude.setSrc("/accessdenied.zul");

It works for me.

link publish delete flag offensive edit
0

answered 2014-01-16 16:31:16 +0800

ziccardi gravatar image ziccardi
321 7

In my opinion the getFellowXXX methods should be avoided as much as possible. I think a better approach would be to attach a viewmodel to your view and then use something like:

<include src="@bind(myViewModel.page)"/>

However this still ties your server code too much with your zul file.

A much better approach could be:

<include src="myprotectedpage.zul" if="@load(myViewModel.canAccess)"/>
<include src="/accessdenied.zul" unless="@load(myViewModel.canAccess)"/>

This way you can freely change your zul file without affecting the Java code

link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2014-01-03 08:17:01 +0800

Seen: 36 times

Last updated: Jan 16 '14

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