Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8372

Re: How to access properties of UI Elements in View Controller?

$
0
0
Hello Rahul,
It is not really possible to do checks on the content of an InputField while you are typing.
The onChange() is not really for this. It is invoked if the focus is changing, not the content.
What is slightly better for your approach is the onEnter(). But there you always have to press Enter key once you typed something, and then this event gets triggered so then you can do your code.
If you wanted to have a continuous check on the contents of the InputField then you should have some kind of repetitive task that is doing this. One option would be TimedTrigger (unless it was not re-rendering the entire page -- and so it would not wipe out the data from your inputfield, etc).
Perhaps using some javascript inside the page the key events could be captured (I assume once can do this with WebWidget UI element, I will check this soon -- no idea how to capture key events in any other way).
To implement the solution (with the downside of always pressing Enter to get validation on the content of the inputfield) do this example:
1. have 3 context attributes
   - text1 (string -- for the value property of inputfield1)
   - text2 (string -- for the value property of inputfield2)
   - enabdisab (boolean -- for the enabled property of inputfield2)
2. bind these context attributes to the UI elements' property value as I wrote above in the brackets in point 1.
3. put into wdDoInit() so the inputfield2 gets disabled when you start up the application
public void wdDoInit()  {
//@@begin wdDoInit()   wdContext.currentContextElement().setEnabdisab(false);
//@@end  }
4. now create an event for the onEnter() event of inputfield1, and add this code (I called the event "ChangeIt"):
  public void onActionChangeIt(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )  {    //@@begin onActionChangeIt(ServerEvent)   if (wdContext.currentContextElement().getText1() == null) {    wdComponentAPI.getMessageManager().reportWarning("not yet filled");    wdContext.currentContextElement().setEnabdisab(false);   }   else {        wdComponentAPI.getMessageManager().reportSuccess("has content");     wdContext.currentContextElement().setEnabdisab(true);   }    //@@end  }
This will work this way in runtime:
1- after invocation you see this:
p1.PNG
2- if you press key Enter now once focusing inputfield1:
p2.PNG
3- if you add some text and press Enter again then inputField2 gets enabled:
p3.png
4- If you delete the text, press enter again, the inputfield2 gets disabled
Problem is that once the first field is empty but no enter pressed yet, then still the second inputfield is enabled.
Still I hope this helps.
Regards,
Ervin

Viewing all articles
Browse latest Browse all 8372

Trending Articles