0
votes

I want to create a generic action bar custom control with Save, Edit, Delete, ... buttons.

How can I pass var variable from xpage to a custom control?

Update

I successfully transferred document object to custom control and I can Save the changes made in document, but I can't delete it with same object. Update:

<xp:this.action>
    <xp:executeScript
        script="#{javascript:compositeData.datasrc.save()}">
    </xp:executeScript>
</xp:this.action>

Delete is not working:

<xp:deleteDocument
    message="Do you want to delete?"
    var="#{javascript:compositeData.datasrc}">
    <xp:this.name><![CDATA[#{javascript:var page = sessionScope.get("prevview");
    return (page=='')?'home.xsp':page}]]>    </xp:this.name>
</xp:deleteDocument>

I tried also with:

var="#{javascript:compositeData.datasrc.getDocument()}">

but also didn't work.

4
The deleteDocument action requires the name of the datasource, not the datasource itself.Sven Hasselbach

4 Answers

3
votes

When you define a custom control, you can specify control properties. These properties then show up in the property editor when you insert the custom control into an XPage or another control. You can specify the data type and allow them to repeat. This is saver than to rely on scoped variables. Check Chris' introduction and the XPages 101 session or and many more for inspiration

0
votes

You can do it for example with a Scoped Variable. If the variable value is specific to that XPage (and user) viewScope is probably the best.

0
votes

The above options are the best way to do that, but keep in mind that if you define a variable in a scriptblock or somewhere else in the Xpage, you will be able to access this variable from your code in the CustomControl, too. I think that's because the XPage und the custom Controls are kind of merged when compiled. Keep that in mind, this can lead to very nasty problems, especially with recycling issues.

0
votes

What is the purpose of this variable ? If its a variable to control which buttons are being shown it would be best to create properties for each button / section. These properties can be computed to either return true or false.

If you want to pass the code that a button should execute I would advice you to generate button bars for the most common locations ( aka actions ) and add custom buttons on the button bar by using a facet (Editable area its called in the designer) .On this facet you'll drag a panel on which the buttons are being placed.