redirect a URL - page blank

53 views
Skip to first unread message

andrea

unread,
Oct 29, 2010, 11:34:55 AM10/29/10
to Lift
Hi All!

I have the next problem

I have a dynamic menu, and for example when I need to change some
options I need to redirect the url to a other direction. For
example:

In my actual session I have the next menu option:

Home - URL (/index)
Menu Option 1 - URL (/option/opt1)
Menu Option 2 - URL (/option/opt2)
Menu Change Permissions - URL (/option/change permissions)
Menu Option 4 - URL (/option/opt4)

And I decide to change the permissions (in the application), So my
actual user now only have permission to the some options, For example:

Home - URL (/index)
Menu Option 1 - URL (/option/opt1)
Menu Option 2 - URL (/option/opt2)


My problem is that when I change my user permissions, this no longer
has permissions on the specified url and the page is blank, I wonder
if there is a way to redirect to a default page if you can not access
to a url. For example at one point I can access the url (/option/
change permissions), but then no longer, then Snippet directs me to
this path (RedirectTo ("/option/change permissions")), but since I
have no access, the page Shown in White. Any suggestions?

I only use the instruction redirectTo("/option/change permissions")
and is rigth when the user has permissions, but is blank when the user
not has permissions.

I probe options such as LiftRules.siteMapFailRedirectLocation =
List("index") in the Boot and

LiftRules.exceptionHandler.prepend {
case (_, _, exception) => {
Log.error(exception.getStackTrace.toString)
RedirectResponse("/")
}
}

but does not change the url

Please, suggestions?


Andrea Moruno

David Pollak

unread,
Oct 29, 2010, 11:36:56 AM10/29/10
to lif...@googlegroups.com
What does your SiteMap definition look like?


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

andrea

unread,
Oct 29, 2010, 11:56:10 AM10/29/10
to Lift
Hi! David

My siteMap is defined dynamically from a database, in the Boot I have
some conditions for to construct the sitemap


def sitemap() = {
if (Usuario.currentUserId.isDefined){
if
((Usuario.findByKey(Usuario.currentUserId.get.toLong).get.password.match_?
(DefaultPassword.getDefaultPassword) ) || (!
Aplicacion.currentApplicationId.isDefined ))
{ SiteMap(Usuario.sitemap :_*) }
else
{ val perfilId = UsuarioAplicacionPerfil.findAll(

By(UsuarioAplicacionPerfil.usuario_Id,Usuario.currentUserId.get.toLong),
By(UsuarioAplicacionPerfil.aplicacion_Id,
Aplicacion.currentApplicationId.get.toLong),
MaxRows(1)).headOption match {
case None => 0
case Some(uap) => uap.perfil_Id.toLong
}
// head.perfil_Id.toLong
Log.info("PERFIL ACTUAL " + perfilId)
perfilId match {
case 0 => SiteMap(Usuario.sitemap :_*) // caso perfil 0,
cuando se quita la aplicacion a un usuario con sesion abierta
case _ => SiteMap(Usuario.sitemap :::
menu.getMenuPerfil(perfilId,
Aplicacion.currentApplicationId.get.toLong) :_*) } }
}

else { SiteMap(Usuario.sitemap :_*) }
}

LiftRules.setSiteMapFunc(sitemap)




Usuario.sitemap only has 3 options ( Home Login OR Home,Reset
Password,Logout )

And

menu.getMenuPerfil(...) get the dynamic Menu of the database


This is the function:
------------
codPerfil -> is a Profile
idAplicacion -> Is an Id of Application
Opcion -> Option of menu
OpcionPerfil -> the menu option of a profile

esReescrito -> If the menu has rewrite rules
nombreUnico -> unique name
nombrePagina -> name of menu (show this text)

getSubMenuPerfil -> recursive function for submenus

---------
def getMenuPerfil(codPerfil:Long, idAplicacion:Long): List[Menu] = {

Opcion.findAll( In(Opcion.id,OpcionPerfil.opcion_Id,By(OpcionPerfil.perfil_Id,
codPerfil), By(OpcionPerfil.aplicacion_Id, idAplicacion)),
OrderBy(Opcion.orden, Ascending)).filter(a => a.padre_id == 0).map(
menu => { if (menu.esReescrito)
Menu(Loc( menu.nombreUnico,menu.nombrePagina.split("/").toList ->
true ,menu.nombre.toString ),
getSubMenuPerfil(codPerfil,idAplicacion, menu.id): _*)
else

Menu(Loc( menu.nombreUnico,menu.nombrePagina.split("/").toList ,menu.nombre.toString ),
getSubMenuPerfil(codPerfil, idAplicacion, menu.id): _*)
}
)
}

def getSubMenuPerfil(codPerfil:Long, idAplicacion:Long,
codPadre:Long): List[Menu] = {

Opcion.findAll( In(Opcion.id,OpcionPerfil.opcion_Id,By(OpcionPerfil.perfil_Id,
codPerfil), By(OpcionPerfil.aplicacion_Id, idAplicacion)),
OrderBy(Opcion.orden, Ascending)).filter(a => a.padre_id ==
codPadre).map(
menu => { if (menu.esReescrito)
Menu(Loc( menu.nombreUnico,menu.nombrePagina.split("/").toList ->
true ,menu.nombre.toString ),
getSubMenuPerfil(codPerfil,idAplicacion, menu.id) : _*)
else

Menu(Loc( menu.nombreUnico,menu.nombrePagina.split("/").toList ,menu.nombre.toString ),
getSubMenuPerfil(codPerfil,idAplicacion, menu.id) : _*)
}
)
}



At one point my user can have permissions to access a menu option, but
if I remove that option (through an option in the application of
permits), the url to which to redirect it is no longer displayed, then
I wish I could redirect you to the home


Thanks for your help!!

Andrea Moruno
> > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890

David Pollak

unread,
Oct 29, 2010, 12:22:11 PM10/29/10
to lif...@googlegroups.com
This is your first problem.  This will not work in production.  Lift supports dynamically changing SiteMap during development, but this only works in Development mode.

If you want to guard a page (the page is only available if the condition is satisfied), use If(conditionFunction, errorMessage)


On Fri, Oct 29, 2010 at 8:56 AM, andrea <tatiana...@gmail.com> wrote:
Hi! David

My siteMap is defined dynamically from a database,

This is a super extra ultra mega bad thing.  Do not do it!!!!
 
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890

andrea

unread,
Oct 29, 2010, 1:40:06 PM10/29/10
to Lift
Hi! David

Thanks for your answer, I have some questions

On 29 oct, 12:22, David Pollak <feeder.of.the.be...@gmail.com> wrote:
> This is your first problem.  This will not work in production.  Lift
> supports dynamically changing SiteMap during development, but this only
> works in Development mode.

How I can change the Production mode ??


>
> If you want to guard a page (the page is only available if the condition is
> satisfied), use If(conditionFunction, errorMessage)
>

OK, like a loggedIn ?? whit a If LocParam??


> On Fri, Oct 29, 2010 at 8:56 AM, andrea <tatiana.mor...@gmail.com> wrote:
> > Hi! David
>
> > My siteMap is defined dynamically from a database,
>
> This is a super extra ultra mega bad thing.  Do not do it!!!!

Can you explain me why??


Thanks for your patience

Andrea Moruno
> > <liftweb%2Bunsu...@googlegroups.com<liftweb%252Buns...@googlegroups.com>

David Pollak

unread,
Oct 29, 2010, 2:06:27 PM10/29/10
to lif...@googlegroups.com
On Fri, Oct 29, 2010 at 10:40 AM, andrea <tatiana...@gmail.com> wrote:
Hi! David

Thanks for your answer, I have some questions

On 29 oct, 12:22, David Pollak <feeder.of.the.be...@gmail.com> wrote:
> This is your first problem.  This will not work in production.  Lift
> supports dynamically changing SiteMap during development, but this only
> works in Development mode.

How I can change the Production mode ??

when you start the container that runs the Lift instance, you have to set the JVM property run.mode=production
 


>
> If you want to guard a page (the page is only available if the condition is
> satisfied), use If(conditionFunction, errorMessage)
>

OK, like a loggedIn ??  whit a If LocParam??

Yes.
 


> On Fri, Oct 29, 2010 at 8:56 AM, andrea <tatiana.mor...@gmail.com> wrote:
> > Hi! David
>
> > My siteMap is defined dynamically from a database,
>
> This is a super extra ultra mega bad thing.  Do not do it!!!!

Can you explain me why??

SiteMap is fixed at Boot time (we made an exception for development mode so the developer can change the SiteMap during development without rebooting [this is useful if you're using JRebel]).  That way Lift can do proper caching of items as well as reasoning about a data structure that's immutable.

 
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890

Lukasz Kuczera

unread,
Oct 29, 2010, 2:18:37 PM10/29/10
to Lift
There should be some ultra fat message in ScalaDoc, I did the same
thing. Fortunately my code runs in Development mode on production :)

On Oct 29, 6:22 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> This is your first problem.  This will not work in production.  Lift
> supports dynamically changing SiteMap during development, but this only
> works in Development mode.
>
> If you want to guard a page (the page is only available if the condition is
> satisfied), use If(conditionFunction, errorMessage)
>
> > <liftweb%2Bunsu...@googlegroups.com<liftweb%252Bunsubscribe@googlegroup s.com>

David Pollak

unread,
Oct 29, 2010, 2:25:20 PM10/29/10
to lif...@googlegroups.com
On Fri, Oct 29, 2010 at 11:18 AM, Lukasz Kuczera <kuk...@gmail.com> wrote:
There should be some ultra fat message in ScalaDoc, I did the same
thing. Fortunately my code runs in Development mode on production :)

  /**
  * Set the sitemap to a function that will be run to generate the sitemap.
  *
  * This allows for changing the SiteMap when in development mode and having
  * the function re-run for each request.<br/>
  *
  * This is **NOT** a mechanism for dynamic SiteMap.  This is a mechanism
  * **ONLY** for allowing you to change the SiteMap during development.
  * There will be significant performance penalties (serializing the
  * service of requests... only one at a time) for changing the SiteMap.
  */
 
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890

andrea

unread,
Oct 29, 2010, 4:19:41 PM10/29/10
to Lift
OK, thank you very much!

:)

Andrea Moruno
> > <liftweb%2Bunsu...@googlegroups.com<liftweb%252Buns...@googlegroups.com>>
> > > > <liftweb%2Bunsu...@googlegroups.com<liftweb%252Buns...@googlegroups.com>
> > <liftweb%252Bunsubscribe@googlegroup s.com>
>
> > > > > > .
> > > > > > For more options, visit this group at
> > > > > >http://groups.google.com/group/liftweb?hl=en.
>
> > > > > --
> > > > > Lift, the simply functional web frameworkhttp://liftweb.net
> > > > > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > > > > Follow me:http://twitter.com/dpp
> > > > > Blog:http://goodstuff.im
> > > > > Surf the harmonics
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Lift" group.
> > > > To post to this group, send email to lif...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com>
> > <liftweb%2Bunsu...@googlegroups.com<liftweb%252Buns...@googlegroups.com>>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/liftweb?hl=en.
>
> > > --
> > > Lift, the simply functional web frameworkhttp://liftweb.net
> > > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > > Follow me:http://twitter.com/dpp
> > > Blog:http://goodstuff.im
> > > Surf the harmonics
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Lift" group.
> > To post to this group, send email to lif...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
>
> ...
>
> leer más »
Reply all
Reply to author
Forward
0 new messages