0

I have 2 edit Boxes, 1 is editable, the other just prints the name of the sessionScope, both fields are in a in 2 cells next to each other , see code below, inputText1 is a editable text field, inputText2 is non editable text, printing #{sessionScope.Tmp1_ABC}

<xp:td> 
<xp:inputText id="inputText1" 
loaded="true"> 
<xp:this.value><![CDATA[${javascript:var fieldName = "Tmp_" +      @ReplaceSubstring(varcollection," ",""); 
return '#{sessionScope.' + @ReplaceSubstring(fieldName,@List(" ",")","("),"") + '}';}]]></xp:this.value> 

<xp:eventHandler 
event="onchange" submit="true" refreshMode="partial" 
refreshId="panel_1" /> 
</xp:inputText> 
</xp:td> 
<xp:td> 
<xp:inputText id="inputText2" 
loaded="true"> 
<xp:this.value><![CDATA[#{javascript:var fieldName = "Tmp1_" +   @ReplaceSubstring(varcollection," ",""); 
return '#{sessionScope.' + @ReplaceSubstring(fieldName,@List(" ",")","("),"") + '}';}]]></xp:this.value> 

<xp:eventHandler 
event="onchange" submit="true" refreshMode="partial" 
refreshId="panel_1" /> 

</xp:inputText> 
</xp:td>
Web_Developer
  • 9
  • 1
  • 2
  • 8

2 Answers2

2

AFAIK you can't assemble your data binding that way. Data binding is an EL expression, not SSJS. You could try to trick using ${} to compute #{}

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • yes, thanks, I think Eclipse must've changed that without me noticing from #{} to ${} – Web_Developer Jul 09 '13 at 07:15
  • there is a UI element for it: (x) Compute on page load ( ) compute dynamically. Does it work for you now? – stwissel Jul 09 '13 at 09:26
  • it looks to be working 50% of the time !, really, sometimes it doesn't work when I've made some changes elsewhere on the custom control. then when I revert back to old code it's working again, that's with the code for the field being 100% the same and see below, even when it's working I cannot change and of the code for the binding in SSJS – Web_Developer Jul 12 '13 at 20:54
1

As per Stefan, using SSJS (javascript:) to define a value for an input control results in it only being read-only. For values to be editable they must be bound using Expression Language (EL). For something as complex as the example (looping over a list of field/variable) you will most likely have to learn a little Java to allow you to connect your input controls to the bean via EL. If the purpose of the code is to have one field editable and the other read-only you should (as Per suggested) change the control from being an inputText to just (computed) text or a label and remove the event handler. Somebody reading the code could easily be confused in thinking you intended both to be editable.

Peter Presnell
  • 380
  • 2
  • 15
  • Thanks, that's probably why it's so "unstable", it does work using SSJS but sometimes when I just even change the variable name and save it, the field becomes readonly straight away. – Web_Developer Jul 12 '13 at 20:52
  • I second Peter's suggestion. You probably would be happier with a Java class. DataContext seems to be a good place to start – stwissel Jul 13 '13 at 07:39