0

I have a custom Control which I'll call ccViewTemplate with this code in it:

<xp:repeat id="repeatData" rows="30"
    value="#{viewEntry}" var="veData"
    first="#{javascript:return (sessionScope.ssFirst != null)?sessionScope.ssFirst:0;}">
<xp:panel id="panelSelect">
<xp:callback facetName="viewBodyFacet" id="callback1"></xp:callback>
</xp:panel><!-- panelSelect -->
</xp:repeat>

the database view (viewEntry) is also defined in ccViewTemplate and defined based on several custom properties. ccViewTemplate is then added to another custom Control called ccFinalView. Where the custom properties are entered, and the content of the display is entered into viewBodyFacet. I have access to veData and a everything works great to this point. In the viewBodyFacet I have a link that does a redirect to open the document which also works fine. However, in the link I want to get the repeatData Property First and store it so that it returns to the correct page of the repeat. I use this code:

sessionScope.put('ssFirst',getComponent("repeatData").first);

However, the code can not find the getComponent("repeatData") because it is inside ccViewTemplate and not accessible. Is there a way to get the component repeatData from the ccViewTemplate while in ccFinalView which contains ccViewTemplate.

I have done getComponent("ccViewTemplate") and I have the handle to the custom Control, but getComponent("ccViewTemplate").getComponent("RepeatData").first fails. So is there a way to pull a value from a component 'inside' a custom control from 'outside' the custome control? looked a little further and found this:

var rtn = getComponent("ccViewTemplate").getPropertyMap().getProperty("repeatData");

It does not generate an error but returns nothing, if I add

var rtn = getComponent("ccViewTemplate").getPropertyMap().getProperty("repeatData").first;

I get an error getComponent() is null

Hope this makes sense.

Bill F
  • 2,057
  • 3
  • 18
  • 39
  • couldnt you access the sessionScope.ssFirst variable directly, or use a java bean which manages the ssFirst variable and have the neccessary checks there? Perhaps also putting the value and first variables into the URL as parameters and allow default values in case they are not found? – Greg Oct 15 '14 at 10:40
  • Greg - the issue is setting the value for first from a button. The button is in a custom control that is contained within another custom control that contains the repeat, so the button has no access to the repeat to find out what it's first is set to. – Bill F Oct 20 '14 at 15:29

1 Answers1

0

From what I understand, this is a perfect job for a java bean. The bean can even keep a default value.

public class Controller{

public String value;

public Controller(){
value = "default_value";
}

public String getValue(){return value;}
public void setValue(String value){this.value=value}

}

In this fashion, the value will be available as soon as the object is created. pressing the button then sets the value with javascript,

ControllerBean.setValue("thisValue");

and you can read the value

ControllerBean.getValue();

This question shows how to configure the bean: How to set up a managed bean to work with Notes document

By setting this to, say the viewScope, you can then access the value anywhere you need regardless of whether or not it is in a custom control or main page. I highly recommend this approach. It just means possibly rethinking your custom control structure.

EDIT
Extra ideas include having an enum that maintains the views,

public enum Views{
VIEW_1("viewAlias", "urlParam")

private String vwAlias;
private String urlParam;
private Views(String alias, String param){
vwAlias = alias;
urlParam = param;
} 

// public getters
}

And then in your controller you can get the view string:

1. By seeing if a view param is included in the URL
2. If a cookie value is set
3. Take the hard coded default

Clicking the change view action then sets the cookie value and changes the view parameter and redirects.

This is all extra ideas, but it is how I build my view controllers. I will be doing a tutorial on that soon.

Community
  • 1
  • 1
Greg
  • 714
  • 4
  • 16