Yesod - Include a base widget only once - haskell

I have a Widget a_i that relies on a base Widget b. b contains Javascript that a requires to work.
Currently, the widgets are included on a page like so:
getHomeR = defaultLayout $ do
b
a_1
a_2
I want to automatically include b if a_i is used but only do this once for any particular handler run.
Widget appears to use IO underneath - can I use this to set some kind of flag which allow b only to be included once? Is there already functionality to set some kind of flag that is exclusive to a single handler thread?

I think that's the purpose of widget, to allow to insert javascript only once. Your use case seemt to correspond to the described there. You should use addScript in a and it should be only added once.

Related

Xpages - Custom control getting a custom property from another custom control

I've searched google and stack but can't seem to find a definitive answer. What I would like to do, is something like this:
Say I have custom control A, within which, is a radio button, when I click it, I want it to grab a custom property that is set on custom control B, lets say compositeData.Name as an example. Can I do this?
If I give custom control B an ID, lets say ccB, can the radio button in custom control A do something like, getComponent("ccB").getValue().compositeData.Name so I can get the value of the property I passed into custom control B using the custom property 'Name'?
If its a straight no, at least I know to stop playing around with the idea! Thanks
Reaching from one control into the inside of another control would break component isolation. You might want to take a different approach:
Option a - client side:
Your control emits a JavaScript event that bubbles up until it reaches a parent element that contains the control you want to change (presumably the parent Dom element). There you set the property of that element.
Option b - server side:
As Urs suggested: bind both to a bean and handle the updates inside the bean

get the outer element (LIST) to render anything other than a div

Is it possible to get List (or any other component from RV) to render itself like an UL>LI list or specifically like React Bootstraps ListGroup.
Currently I can not see an option to get the outer element (LIST) to render anything other than a DIV.
So my use case is really that each row should be a ListGroupItem (e.g. li with BS classes applied) and the container should be a ListGroup component.
Short answer: No. This is not supported.
Longer answer: List (like Table) uses a Grid internally. In order for windowing to work, Grid needs 2 wrapper elements around its cells. (Check out the source here. I also made a presentation slide about how it works, if you're interested, here.) Lists (ol, ul) only have 1 wrapper element.

Gtk2Hs : Widget interaction

I'm trying to create a program with Gtk2Hs and Haskell and I wonder whether it is possible to make different widgets communicate with one another.
I have a text entry, which is used to write commands, a drawing area, which draws something when the text entry is validated. These two widgets works together fine.
However, I would like to add an "optional" treeview in a different window, which would be updated when all commands in the text entry have been executed (this can take a long time).
As the treeview is "optional" and created only afterwards, I can't define callbacks to its update in the text entry definition (like the drawing area).
I would to create a signal (event?) to be emitted when all the operations are done and caught by the treeview to update its data.
My questions are :
Is there a way to do that with Gtk2Hs and Glib?
Is there a module that could be used to make it (portable to Linux/Windows, if possible)?
Is there a correct way to make a widget interract/communicate with others?
I'm using GHC 7.4.1 and Gtk2Hs 0.12.3
I find a solution to my problem :
In the main program I create an IORef of a list of actions to perform :
actionsIO <- newIORef [action_to_do_1,action_to_do_2]
I create my custom combined widget for text entry
ent <- textEntry window canvas state modele parser info actionsIO
Inside, I execute the list of actions that way :
actions <- readIORef actionsIO
sequence_ actions
I create my treeview
arwin <- arrayWin modele window canvas state info actionsIO
Inside, I modify/delete/add actions to the list like this :
let newactions = [new_action_to_do_1,new_action_to_do_2]
writeIORef actionsIO newactions
These new actions are performed every time a command is validated with the special entry widget.
There is probably a "cleaner" method to do that, but this one work well and solved my problem completely.

Reusable edit form in Apache Wicket

I have a simple ContactEditPanel which contains a form and a number of textfields. Up until now I included an AjaxSubmitLink in this panel which, if the form content is valid, saves/updates the Contact instance contained in the Panel model. So far so simple. However now I'd like to remove the link in order that I may, depending on the context in which I use the ContactEditPanel, place the submit link at different levels of my overall component hierarchy. For instance in one context I'd like to use to flip between ContactEditPanel and ContactViewPanel with a bar of actions above the current view (edit | save , cancel). Another context would be to use ContactEditPanel in a standalone way (maybe part of a multi-step process) with just a save link below.
I was contemplating refactoring my ContactEditPanel to extends FormComponentPanel rather than Panel as described here but I'm not sure whether this is the right approach and I'm having trouble wrapping my head around this.
Any help would be most appreciated!
Many Thanks,
A
Your using the panel like a FormComponent so extend FormComponentPanel, it will allow you to keep all the validation you write contained to the component and also allow you to reuse it as you wish.
Just think of it as you've created a new FormComponent, like a TextField or DropDownChoice.

Blackberry - UI like BBM

I want to make a layout like Blackberry Messenger.
Is it possible to add ListField to a TreeField in Blackberry?
Alternatively, if I use ListstyleButtonField, how can I get the expand and collapse state so I can add the ListField on the expand event.
No it's not possible to add a ListField to a TreeField, since TreeField acts like a ListField using a callback.
I'd use a VerticalFieldManager in combination with CheckboxFields, adding the different ListFields corresponding to the states of the Checkboxes.
If u want to use ListstyleButtonField you need to extend it by some kind of boolean state, changing its value on clickButton before the fieldchangenotify.

Resources