Archive for September, 2007|Monthly archive page

Try to parse XML (similar to Integer.TryParse).

I’ve facing following problem during my current project. We have a lot of automation here. We have plug-ins architecture inside. Plug-ins are simple classes which inherits our special interface off-course. But main issue for plug-in is to persist his status. It’s possible with properties. So plug-ins are classes with properties which are processed automatically. Under processing I’m talking about setting/getting values and storing in our system. But plug-in can contains not just properties with simple types but complex types as well. Here complex type is some class which can easily be serialized/deserialized to/from XML. So we should be able to store complex types in properties. BTW: all values are storing as strings in our system. If can’t then I’m trying to convert value to a type of property. During conversation I’m checking if the passed value can be deserialized to complex type if yes – then it’s deserialized and value successfully set. If not I’m looking for a converter if no converter found I’m trying to set value directly.

    So my actual problem is that I can’t check that string can be parsed by XML processor. For example if we have in the string special symbols it can’t be processed. So I need to do try … catch to handle errors during deserialization. So I’m wondering why haven’t Microsoft add TryParse method to XML processor.

Advertisements

ExtJS – changing title for form fields dynamically – failed :( or “How can I prepare build from official ExtJS sorces

Couple of days ago I’ve tried to change title for form field for the form dynamically. And have faced problems. It looks like label element doesn’t contain ID-property. I’ve found standard template for all form-fields in ExtJS forms. So standart template is looking like:


<div class=”x-form-item {5}”>  <label for=”{0}” style=”{2}“>{1}{4}</label>
  <div class=”x-form-element” id=”x-form-el-{0}”
       style=”{3}“>
  </div>
</div>
<div class=”x-form-clear-left”>
</div>

But it’s easy to fix this issue. For example – you can travel via DOM to the label element and change innerHTML property of the element. But for was more interesting to understand how can I do build from the sources of ExtJS. And I’ve found that there is very interesting standard for build systems for such projects which is used (I guess so) by the ExtJS developers. So the name of the build – system is JSBuilder and it can be found here –http://code.google.com/p/js-builder/ It’s built using .net. It’s easy to use this system – you should open description file for the project (*.jsb). You can find build file for the ExtJS by the path: %ExtDirectory%/source/ext.jsb. After file was opened you should select modules you want to build and specify output directories.

Let’s back to our issue with label. For me I’ve changed standard template in %ExtDirectory%/source/widgets/form/Layout.js in function OnRender
in Ext.form.Layout class. So new template for me now looks like :


<div class=”x-form-item {5}”>
  <label id=”x-form-label-{0}” for=”{0}” style=”{2}“>
   {1}{4}</label>
  <div class=”x-form-element” id=”x-form-el-{0}” style=”{3}“>
  </div>
</div>
<div class=”x-form-clear-left”>
</div>

Here you can notice that I’ve add id property for the label. So now I can change innerHTML property of the label when it’s needed. Parameter #0 from the stack is ID for the rendered object. So after updates in source code I can easily update fieldLabel text:

Ext.get(‘x-form-label-‘ + currentField.id).innerHTML = “new title”;

Good luck 😉