cancel
Showing results for 
Search instead for 
Did you mean: 

Convert javascript var into a java String

Former Member
0 Kudos

Hi all,

I have an iview that receives an event. I tried to work with JSP this time. After I received the event I have a java-script var. I would like to put the content of the var into a htmlb-component:

<script>

EPCM.subscribeEvent( 'urn:com.test.EPCFExample', 'Event', getEvent);

function getEvent( evt ) {

var nameEvent = EPCM.loadClientData('urn:com.test.EPCFExample','textInput');

}

</script>

I have completly no clue what to do with the variable. Can this be transferred into a java-String? If I use it as value-parameter for an InputField it will be interpreted as a String ;-(

<hbj:inputField

id="eventField"

value=nameEvent

width="90"

visible="TRUE"

disabled="TRUE"

/>

Thanks for any help!

Martina

Accepted Solutions (1)

Accepted Solutions (1)

detlev_beutner
Active Contributor
0 Kudos

Hi Martina,

to access HTMLB elements as JS HTMLB objects, the following function you should always wear in your pocket:

function getHtmlbElement(pElementId) {
  var loDocForms = document.forms;
  for (var j = 0; j < loDocForms.length; j++) {
    try {
      var funcName = loDocForms[j].id + "_getHtmlbElementId";
      func = window[funcName]; 
      var element = eval(func(pElementId));
      if (element != null) {
        return element;
      }
    } catch(ex) {
  }
}

Setting "nameEvent" into the HTMLB tag cannot work because this is calculated at server side (it's JSP - Java).

With the method given above, you retrieve the HTMLB JS object, here the HTMLB JS object InputField, when you write (and have set JSObjectNeeded to true):

var myInpField = getHtmlbElement('eventField')

On this object, you can set a value by

myInpField.setValue(EPCM.loadClientData('urn:com.test.EPCFExample','textInput'))

I didn't test it (the last combination), but it should work.

A general question is if it is really needed to pass the data via ClientDataBag. Why not passing as a value of the event?

Hope it helps

Detlev

PS: https://forums.sdn.sap.com/thread.jspa?threadID=26357 wasn't helpful? No reply, no points, nothing?

Answers (0)