Possibly Stupid Question

43 views
Skip to first unread message

reuben doetsch

unread,
Jul 8, 2011, 3:34:26 PM7/8/11
to lif...@googlegroups.com
This could be a stupid question or I am going about this in the wrong way, but here is the scenario.

I have a ajax button which changes some state on the server side. For example the ajax button changes a user to an administrator and the side column changes. I then want to rerun a snippet on the page and change the existing html to the new html. Can snippets be run in this fashion/ is this possible/ should I be doing this another way? 

Thanks in advance,

Reuben 

David Pollak

unread,
Jul 8, 2011, 3:37:24 PM7/8/11
to lif...@googlegroups.com
On Fri, Jul 8, 2011 at 12:34 PM, reuben doetsch <reuben....@gmail.com> wrote:
This could be a stupid question or I am going about this in the wrong way, but here is the scenario.

I have a ajax button which changes some state on the server side. For example the ajax button changes a user to an administrator and the side column changes. I then want to rerun a snippet on the page and change the existing html to the new html. Can snippets be run in this fashion/ is this possible/ should I be doing this another way? 

Sure.

If you do something like SetHtml("sideThingId", <lift:MySnippet/>)  Then MySnippet will be run.

If you want to run a template:

SetHtml("sideThingId", S.runTemplate("foo" :: "bar" :: Nil)) // load the /foo/bar.html template

Hope this helps.
 

Thanks in advance,

Reuben 

--
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

Naftoli Gugenheim

unread,
Jul 8, 2011, 3:38:43 PM7/8/11
to lif...@googlegroups.com
--

reuben doetsch

unread,
Jul 8, 2011, 3:40:23 PM7/8/11
to lif...@googlegroups.com
Thank you so much for the quick replies!

reuben doetsch

unread,
Jul 8, 2011, 4:14:46 PM7/8/11
to lif...@googlegroups.com
One more question. So after taking your suggestion, I realized that I also wanted the meat of the snippet.

Here is the snip

A part of the snippet
-----------------------------------
   <lift:bind-at name="side-col">
            <lift:embed what="group-details-sidebar"></lift:embed>
         </lift:bind-at>

------ group-details-sidebar.html
 <div class="lift:GroupDetails.sidebar">

        <div class="lift:test_cond.loggedin">

        <!-- only show if admin -->
        <div id="update-group-button"></div>
        <div id="propose-game-button"></div>
</div>

------On Ajax Button

 JsCmds.SetHtml("side-col", <lift:embed what="group-details-sidebar"></lift:embed>)

---SideBar snippet

  def sidebar(html:NodeSeq):NodeSeq =
  {
    groupPart = group.getMembers.find(u => u.getUser.getUserID == Users.s_userID.get.get)

    println(groupID)
    println(group.getName)

    if(partOfGroup)
    {
      println(groupPart.get.getGroupParticipantType.toString)
    }
    else
    {
      println("Not member")
    }

     ("#update-group-button" #> updateButton &
      "#propose-game-button" #> updateRecurringButton &
      "#joinLink" #> conditionalSHtml(!partOfGroup, SHtml.a(buttonAjax,joinButton)) &
      "#invitePeople" #> conditionalSHtml(partOfGroup, SHtml.a(invitePeople,inviteButton)) &
      "#memberfaces *" #> group.getMembers.map(m =>
        ".picture [src]" #> Games.UserImageURL(m.getUser)
      )&
      "#update-group-button" #> updateButton)(html)
  }

The sidebar class sits in the same class as the snippet rendered by the page.


The issue is that the print lines in the sidebar are printing the same thing and not changing. I thought perhaps the class had a lifecycle which lasted both the request and the ajax so I even updated groupPart.

My question is, where does it cache and is there anything I can do about this problem? Am I totally off on something?

Thanks for your time,

Reuben

Naftoli Gugenheim

unread,
Jul 8, 2011, 4:24:36 PM7/8/11
to lif...@googlegroups.com
I don't think anything is being cached. What are groupPart and partOfGroup and where are they changed?

reuben doetsch

unread,
Jul 8, 2011, 4:32:04 PM7/8/11
to lif...@googlegroups.com
  def isGroupMember = !groupPart.isEmpty && groupPart.get.getGroupParticipantType == GroupParticipantType.MEMBER

  def isGroupAdmin = !groupPart.isEmpty && groupPart.get.getGroupParticipantType == GroupParticipantType.ADMIN

  def partOfGroup = isGroupMember || isGroupAdmin

Naftoli Gugenheim

unread,
Jul 8, 2011, 4:35:20 PM7/8/11
to lif...@googlegroups.com
What is groupPart? And how do you update it?

Naftoli Gugenheim

unread,
Jul 8, 2011, 4:36:00 PM7/8/11
to lif...@googlegroups.com
And where is it defined?

reuben doetsch

unread,
Jul 8, 2011, 4:38:49 PM7/8/11
to lif...@googlegroups.com
class GroupDetails {

  val groupID = paramToLong(S.param("groupID"),"No group number")

  val group = tryIDAndRedirect[Group](groupID, "No group with that ID")

  var groupPart = group.getMembers.find(u => u.getUser.getUserID == Users.s_userID.get.get)

reuben doetsch

unread,
Jul 8, 2011, 4:39:02 PM7/8/11
to lif...@googlegroups.com
the class where the snippet and the render method is.

Naftoli Gugenheim

unread,
Jul 8, 2011, 4:41:35 PM7/8/11
to lif...@googlegroups.com
And do you actually update it?

reuben doetsch

unread,
Jul 8, 2011, 4:44:46 PM7/8/11
to lif...@googlegroups.com
Yeah look at the snippet


  def sidebar(html:NodeSeq):NodeSeq =
  {
    groupPart = group.getMembers.find(u => u.getUser.getUserID == Users.s_userID.get.get)



Naftoli Gugenheim

unread,
Jul 8, 2011, 4:47:50 PM7/8/11
to lif...@googlegroups.com
And are the contents of group.getMembers, or the value of Users.s_userID, being updated?

reuben doetsch

unread,
Jul 8, 2011, 4:50:49 PM7/8/11
to lif...@googlegroups.com
Ahh okay great thank you I think that was the issue.

Reuben

Diego Medina

unread,
Jul 10, 2011, 10:42:07 PM7/10/11
to lif...@googlegroups.com
On Fri, Jul 8, 2011 at 3:37 PM, David Pollak
<feeder.of...@gmail.com> wrote:
>
>
> On Fri, Jul 8, 2011 at 12:34 PM, reuben doetsch <reuben....@gmail.com>
> wrote:
>>
>> This could be a stupid question or I am going about this in the wrong way,
>> but here is the scenario.

Not stupid at all, I'm not sure how many people on this mailing list
would have thought of including a whole template using setHtml

>> I have a ajax button which changes some state on the server side. For

[cut]

> Sure.
>
> If you do something like SetHtml("sideThingId", <lift:MySnippet/>)  Then
> MySnippet will be run.
>
> If you want to run a template:
>
> SetHtml("sideThingId", S.runTemplate("foo" :: "bar" :: Nil)) // load the
> /foo/bar.html template

This is pretty cool, I didn't know you could do this, but when I tried
it I had to modify it a bit:


S.runTemplate("liftactorform" :: Nil) map { x => partialUpdate
(SetHtml("state", ( x ))) }

otherwise I got a compiler error:

[error] found : net.liftweb.common.Box[scala.xml.NodeSeq]
[error] required: scala.xml.NodeSeq

Thanks!

Diego

--
Diego Medina
Web Developer
(305) 788-4954
di...@fmpwizard.com
http://www.fmpwizard.com

Reply all
Reply to author
Forward
0 new messages