Validators and itemrenderers

Hi,
I have a problem using ItemRenderer.
I have a table implemented as DataGrid in which some cells are shown by a self written itemRenderer. Depending on the type of the cells data the cell will be also used by a validator. Executing the program everything looks fine, as long as the programs window is not too small. If you scroll in the table then really ugly things happen. The wrong cells get validated by wrong validators and I have even seen that a single cell is validated by several validators.
I know that the ItemRenderer are recycled and I am pretty sure that this has dealing with the problem. But the validators should be activated and deactivated by databinding which should occure on every databinding. So I should work well? But why it doesn't?
If I use a List, and set useVirtualLayout="false"then the problem occues no more (but it looks verry different).
Thank you
Andreas Ruloffs
The main Application with the datagrid:
?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="application1_initializeHandler(event)">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
private var data:ArrayCollection = new ArrayCollection();
protected function application1_initializeHandler(event:FlexEvent):void
data.addItem(new MonoAttributeData("Text1", "Halloo", "String", true, true, 5 ));
data.addItem(new MonoAttributeData("Dbl1", "1", "Double", false, true));
data.addItem(new MonoAttributeData("Int1", "2", "Integer", false, true));
data.addItem(new MonoAttributeData("Text2", "Welt", "String", true, true, 5 ));
data.addItem(new MonoAttributeData("Dbl2", "", "Double", false, true));
data.addItem(new MonoAttributeData("Int2", "54", "Integer", true, true));
data.addItem(new MonoAttributeData("Text3", "Fix", "String", true, true, 5 ));
data.addItem(new MonoAttributeData("Dbl3", "", "Double", false, true));
data.addItem(new MonoAttributeData("Int3", "54", "Integer", true, true));
dataGrid.dataProvider = data;
]]>
</fx:Script>
<mx:AdvancedDataGrid id="dataGrid"
verticalScrollPolicy="on"
horizontalScrollPolicy="off"
alternatingItemColors="[#969696,#787878]"
headerColors="[#969696,#787878]"
width="100%"
height="100%"
sortableColumns="false"
sortItemRenderer="{null}">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="fieldname" headerText="Name" />
<mx:AdvancedDataGridColumn dataField="value"    headerText="Value"/>
</mx:columns>
<mx:rendererProviders>
<mx:AdvancedDataGridRendererProvider
dataField="value"
renderer="MonoLangValueItemRenderer"
columnIndex="1"/>
</mx:rendererProviders>
</mx:AdvancedDataGrid>
</s:Application>
The data model for the ItemRenderer:
package
import mx.collections.ArrayCollection;
import mx.collections.ArrayList;
public class MonoAttributeData
private var _value:String;
private var _changeable:Boolean;
private var _changed:Boolean;
private var _valid: Boolean = true;
private var _validationMessage: String;
private var _fieldType:String;                    //Double, Integer oder String
private var _fieldLength:int;
private var _fieldAllowNull:Boolean
private var _fieldname:String;
public function MonoAttributeData(fieldname:String, value:String, fieldType:String, fieldAllowNull:Boolean, changeable:Boolean, fieldLength:int = 0)
_value = value;
_changeable = changeable;
_changed = false;
_valid = true;
_validationMessage = "";
_fieldType = fieldType;
_fieldLength = fieldLength;
_fieldAllowNull = fieldAllowNull;
_fieldname = fieldname;
public function get fieldname():String
return _fieldname;
public function set fieldname(value:String):void
_fieldname = value;
public function get validationMessage():String
return _validationMessage;
public function set validationMessage(value:String):void
_validationMessage = value;
public function get valid():Boolean
return _valid;
public function set valid(value:Boolean):void
_valid = value;
[Bindable]
public function get changeable():Boolean
return _changeable;
public function set changeable(value:Boolean):void
_changeable = value;
[Bindable]
public function get changed():Boolean
return _changed;
public function set changed(value:Boolean):void
_changed = value;
[Bindable]
public function get value():String
return _value;
public function set value(value:String):void
_value = value;
[Bindable]
public function get fieldType():String
return _fieldType;
public function set fieldType(value:String):void
_fieldType = value;
[Bindable]
public function get fieldLength():int
return _fieldLength;
public function set fieldLength(value:int):void
_fieldLength = value;
[Bindable]
public function get fieldAllowNull():Boolean
return _fieldAllowNull;
public function set fieldAllowNull(value:Boolean):void
_fieldAllowNull = value;
and the ItemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="100%" height="100%" >
<fx:Declarations>
<!-- value Commit keine Auswirkung
dataChange von Anfang an
Platzieren Sie nichtvisuelle Elemente (z.*B. Dienste, Wertobjekte) hier -->
<mx:NumberValidator id="validatorDouble"  source="{textInput}"
property="text"
valid="validatorDouble_validHandler(event)"
invalid="validatorDouble_invalidHandler(event)"
required="{!MonoAttributeData(data).fieldAllowNull}"
domain="real"
enabled="{ MonoAttributeData(data).fieldType == 'Double'}"/>
<mx:NumberValidator id="validatorInt" source="{textInput}"
property="text"
required="{!MonoAttributeData(data).fieldAllowNull}"
valid="numbervalidatorInt_validHandler(event)"
invalid="numbervalidatorInt_invalidHandler(event)"
domain="int"
enabled="{ ( MonoAttributeData(data).fieldType == 'Integer')}"/>
<mx:StringValidator id="validatorStr" source="{textInput}"
property="text"
valid="validatorStr_validHandler(event)"
invalid="validatorStr_invalidHandler(event)"
required="{!MonoAttributeData(data).fieldAllowNull}"
minLength="NaN"
maxLength="{MonoAttributeData(data).fieldLength}"
enabled="{MonoAttributeData(data).fieldType == 'String'}"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayList;
import mx.core.UIComponent;
import mx.events.ValidationResultEvent;
private function dataChanged():void
if(data.value != textInput.text)
var newValue:String = textInput.text;
MonoAttributeData(data).changed = true;
MonoAttributeData(data).value = newValue;
protected function validatorDouble_validHandler(event:ValidationResultEvent):void
data.valid = true;
MonoAttributeData(data).validationMessage = "";
protected function validatorDouble_invalidHandler(event:ValidationResultEvent):void
data.valid = false;
MonoAttributeData(data).validationMessage =  MonoAttributeData(data).fieldname + ": " + event.message + "\n";
protected function numbervalidatorInt_validHandler(event:ValidationResultEvent):void
data.valid = true;
MonoAttributeData(data).validationMessage = "";
protected function numbervalidatorInt_invalidHandler(event:ValidationResultEvent):void
data.valid = false;
MonoAttributeData(data).validationMessage =  MonoAttributeData(data).fieldname + ": " + event.message + "\n";
protected function validatorStr_validHandler(event:ValidationResultEvent):void
data.valid = true;
MonoAttributeData(data).validationMessage = "";
protected function validatorStr_invalidHandler(event:ValidationResultEvent):void
data.valid = false;
MonoAttributeData(data).validationMessage =  MonoAttributeData(data).fieldname + ": " + event.message + "\n";
]]>
</fx:Script>
<s:Group width="100%" height="100%">
<s:TextInput  id="textInput"
change="dataChanged()"
color="{data.changed?0x666666:0x000000}"
enabled="{data.changeable}"
text="{data.value}"
textAlign="center"
width="100%" height="100%"/>
</s:Group>
</s:MXAdvancedDataGridItemRenderer>

Hello,
I have solved the problem myself.
The problem was not the validators. As I proposed were they activated and deactivated correctly by databinding on each recycling.
But the textfield in the itemrenderer got a property called ‘errorText’ which was not reseted on recycling. This caused my problem. This little enhancement finally solved my problem:
private function resetValidation():void
     textInput.errorString = "";
     textInput.toolTip = "";
     validatorDouble.validate();
     validatorInt.validate();
     validatorStr.validate();
override public function set data(value:Object):void
     super.data = value;
     resetValidation();
Best regards,
Andreas Ruloffs

Similar Messages

  • Problem with "Using Validators and Converters" example

    Hi,
    I am doing the Validatoris an Converters tutorial and I can't get it correctly executed.
    In step 9, I double click on textField1 and the systems goes to textField1_processValueChange function instead of textField1_valueChangeListener.
    I added the code of step 10 as a separate method and after executing it there is no error message. Please help. Thanks,
    I wish these examples where a little more of dummies: step 2 toke some time because you don't say "In the properties window". Please look the tutorials with people that does not know anything about the Creator.
    Also I wish you had a step by step tutorial with "About Components", "About Message Components", and "About Converters". Just reading , I did not grasp anything, so I prefer to create a project with these tutorials.
    Do I need to learn JSF in order to understand and use Creator? It seems as I read the tutoriasl you assume to much. I found that Cay Horstmann's Core JavaServer Faces book is downloadable at http://horstmann.com/corejsf/
    Thanks for your input,
    Lorenzo Jimenez

    Hi,
    You may find our book, Java Studio Creator Field Guide, helpful for a more gentle introduction to Creator and JSF components. We don't assume that you know JSF or even Java. We also have step-by-step instructions for building projects.
    Here's the link to our website:
    www.asgteach.com
    (You can download Chapter 2, which is the basic introduction to Creator.)
    Hope that helps.
    Gail and Paul Anderson

  • Validators and Tabbed Panels

    Hi there, hope you can help.
    I have a page with a tabbed panel with links to other pages
    on it which worked fine until I added links to Spry Validator files
    on my HEAD.
    Ever since then, if I do a javascript.history(-1) from one of
    the target pages the tabbed panel will reset the displayed tab back
    to 0.
    Is there any way to make the tabbed panel work properly while
    the validators js are loaded? Or should I completely separate them?
    I am using spry pre-release 1.6.1
    Thanks

    quote:
    Originally posted by:
    Abstremik
    Link
    The site is in Portuguese so let me explain a bit
    When you open the page, the site displays a tabbed panel,
    select the second tab "Fichas mais recentes" and then click on any
    of the buttons "Detalhes...". This will open the details view for
    that record.
    Then going back to the original page through the browser
    navigation bar will load the initial tab "Fichas mais visitadas".
    Edit: looks like I was wrong, there is something else
    causing the error. I'll look into it some more
    http://labs.adobe.com/technologies/spry/samples/utils/URLUtilsSample.html
    check out the bottom example
    and read this:
    http://foundationphp.com/tutorials/spry_url_utils.php

  • Dynamic validators and itemrenderer

    Hi,
    I have a bunch of dynamic validators that i create in my application.
    I have a s:DataGroup which contains an itemRenderer. In this itemRenderer, I have a combobox which I want to validate.
    I perform the validation like this:
    protected function performValidation(event:FocusEvent):void
          var condition:Condition = data as Condition;
          condition.validator.listener = valuesComboBox;
          condition.validator.validate(valuesComboBox.textInput.text);
    Of course, when I do this, the itemrenderer is recycling, and the validator appears in comboboxes in which i do not want it to.
    Anybody have any idea how i can work around this problem?
    Thanks,
    Jamie

    Hi,
    I have a bunch of dynamic validators that i create in my application.
    I have a s:DataGroup which contains an itemRenderer. In this itemRenderer, I have a combobox which I want to validate.
    I perform the validation like this:
    protected function performValidation(event:FocusEvent):void
          var condition:Condition = data as Condition;
          condition.validator.listener = valuesComboBox;
          condition.validator.validate(valuesComboBox.textInput.text);
    Of course, when I do this, the itemrenderer is recycling, and the validator appears in comboboxes in which i do not want it to.
    Anybody have any idea how i can work around this problem?
    Thanks,
    Jamie

  • XML Data Sets and IE8

    I have an issue with Spry XML Data sets that is driving me nuts.
    The setup is quite straightforward. I have a PHP script which submits a SOAP request, the result of which is pure XML. I echo this XML out as the result of the script.
    I have another page on which is one or more Spry XML Data Sets. These data sets use the previous script as the source. I know this works OK because when i 'Get Schema' in the XML dataset dialog in Dreamweaver, the schema is properly displayed. This page also has a Spry Table on it, which uses the dataset as the source. There is nothing else on the page at all.
    Now, when I preview this page in Firefox, Chrome, Opera or Safari, it displays fine. However, when I preview it in IE, the table briefly flashes up then disappears. A quick look at the source of the page shows the HTML all laid out very licely, but the Spry fields still show with their placeholders (e.g. {Balance}) instead of the actual value. Im left with a totally blank page in IE.
    I have tried running in compatibility mode with no effect. I found a posting on Experts Exchange (yuk!) where someone else was having the problem but this turned out to bedue to badly formed XML. I have run my XML though XMLSpy and several online validators and it checks out every time.
    Any ideas? I am slowly losing the will to live....
    Si

    Hi,
    I'm trying to debug the same problem...I think.The pages work in firefox on PC & MAC but stop with the {data_name} in IE on both PC & MAC.
    I'm using Dreamweaver CS3 with ADDT. I've read the posts about adding the content-type to my file that ADDT created for me just before the XMLExport, so I've added that to the get_menu_1_info.php file (see lines 42-46). I've peeked into the XMLExport.class.php file to see that the Execute function is supposedly already sending the header info (see line 223). But I'm not getting the data into IE.
    Any help would be appreciated!
    here's where you can see the page:
    https://hbblearning.org/Takv3uMYsX7cVK5eRo/newcomer_info.html
    here's where I generate the xml file to be consumed:
    https://www.hbblearning.org/get/get_menu_1_info.php
    I've attached the files for you to see.

  • HtmlInputText and Programatic Style Changes

    I think I might be going blind here looking at this code. I have something that seems so inexplicably easy, but I still can't get it.
    I have a form of HtmlInputText's, which when the user submits the form and I find problems with the data from the server-side, I want to highlight the input field with a red background. Since I do not specify a background color for my input's styles, I thought the easiest approach would be to simply add '; background-color: RED' at the end of the inline style. This works, but the strange thing happens when I try to change more than one at a time. I have a method, resetFieldStyles(), which I'm including at the bottom of this message. It was originally called as part of my apply logic in the Invoke Application phase. Now I retain the initial highlight state and call this method explicitly in beforeProcessValidations().
    All it does is check each input's style and if it ends in '; background-color: RED' then I remove it and set the resulting style back to the component. The problem is that it will only work for one component at a time, so what I'm saying is that if I had 6 fields that needed to be cleared of styles, I would have to loop through this code 6 times to get each component style reset. It sounds crazy I know, but I've tried to work around it a few dozen ways and it keeps happening. I've even tried to move the execution of this code around to different phases in my app.
    Does anyone know of a fix for me, or does someone have an even better method that they use / know of that will do the same thing without the looping of the setStyle() or getAttributes().put("style", "") methods? Does setStyle() actually work? Could Style Classes help? Is there a more direct way to guarantee this data changes?
    Thanks.
    private static final String errorHighlightTag = "; background-color: RED";
    /** resetFieldStyles() - Reset All Form Field Style Classes */
    private void resetFieldStyles()
         // Create an Array of Form Fields
         HtmlInputText[] inputs = { this.getOwner(), this.getName(), this.getAdd1(), this.getAdd2(), this.getAdd3(),
              this.getCity(), this.getState(), this.getZip(), this.getCountry(), this.getPhone(), this.getFax(),
              this.getEmail() };
         // Remove Background Tags From Style Values
         for (int i = 0; i < inputs.length; i++)
              // If Style Ends With Appended Highlight Tag
              if ((inputs.getStyle()).endsWith(errorHighlightTag) == true)
                   // Strip Length of Highlight Tag From End of Style Value
                   inputs[i].setStyle(inputs[i].getStyle().substring(0, (inputs[i].getStyle().length() -
                        errorHighlightTag.length())));
         // Compile Field Styles
         String style = "";
         for (int a = 0; a < inputs.length; a++)
              style += inputs[a].getStyle() + ",";
         System.out.println("Field Styles: '" + style + "'");
         // Evaluate Field Styles
         if (style.indexOf("RED") < 0)
              System.out.println("All RED Style Tags Have Been Removed...");
         else
              System.out.println("WARNING: Not All RED Style Tags Have Been Removed!!!");
         return;

    what your are looking for is something like this
    jsp page
    =======
      <head>
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
          <title>JSF Page</title>
          <style type="text/css">
            input{
              background-color: #EEE;
            .invalid-field{
              background-color:#800000;
              color:#FFF;
              font-weight:bolder;
          </style>
      </head>
      <body>
       <faces:view>
         <html:form>
         <faces:verbatim>
           <table>
             <tr>
               <td>
                 Amount
               </td>
               <td>
         </faces:verbatim>
           <html:inputText id="amount" value="#{myBean.amount}" size="10" maxlength="10"
               validator="#{myBean.validateCurrency}"/>
          <faces:verbatim>    
               </td>
             <tr>
             <tr>
               <td>
                 Age
               </td>
               <td>
            </faces:verbatim>
                 <html:inputText id="age" value = "#{myBean.age}" size="5" maxlength="3" validator="#{myBean.validateAge}"/>          
             <faces:verbatim>
               </td>
             </tr>
             <tr>
               <td>
                 Email
               </td>
               <td>
              </faces:verbatim>
                 <html:inputText id="email" size="10" maxlength="100" validator="#{myBean.validateEmail}" />
              <faces:verbatim>
               </td>
             </tr>
             <tr>
               <td colspan="2">
             </faces:verbatim>
                 <html:commandButton value="Submit" action="#{myBean.save}"/>
             <faces:verbatim>
               </td>
             </tr>
           </table>
            </faces:verbatim>
         </html:form>
       </faces:view>
      </body>the bean
    =======
        public void validateEmail(FacesContext oContext,UIComponent oComponent, Object oValue) {
          String sMessage = "";
          System.out.println("Validating Email..."+ oValue);
          String sEmail = (String) oValue;
          UIInput oInput = (UIInput)oComponent;
          String sCurrentStyleClass = ((HtmlInputText)oComponent).getStyleClass();
          if (sCurrentStyleClass==null)
            sCurrentStyleClass= "";
          boolean bValid = true;
          if (sEmail.indexOf('@') == -1) {
            oInput.setValid(false);
            sMessage = "Invalid Email Address";
            oContext.addMessage(oComponent.getClientId(oContext),new FacesMessage(sMessage));
            sCurrentStyleClass += " invalid-field ";
            bValid=false;
          else{
            //remove any existing invalid-field classes.
            sCurrentStyleClass = sCurrentStyleClass.replaceAll("invalid-field","");
          ((HtmlInputText)oComponent).setStyleClass(sCurrentStyleClass);
          System.out.println("Validating Email isValid=["+bValid + "] class=["+ sCurrentStyleClass + "] message=["+sMessage+"]");
        public void validateCurrency(FacesContext oContext,UIComponent oComponent, Object oValue) {
          String sMessage = "";
          System.out.println("Validating Currency..."+ oValue);
          UIInput oInput = (UIInput)oComponent;
          String sCurrentStyleClass = ((HtmlInputText)oComponent).getStyleClass();
          if (sCurrentStyleClass==null)
            sCurrentStyleClass= "";
          boolean bValid = true;
          try{
             double iAmount = Double.parseDouble(oValue+"");
          catch(ClassCastException oException){
            bValid = false;
            oException.printStackTrace();
          catch(NumberFormatException oException){
            bValid=false;
            oException.printStackTrace();
          if (!bValid) {
            oInput.setValid(false);
            sMessage = "Invalid Currency";
            oContext.addMessage(oComponent.getClientId(oContext),new FacesMessage(sMessage));
            sCurrentStyleClass += " invalid-field ";
          else{
            //remove any existing invalid-field classes.
            sCurrentStyleClass = sCurrentStyleClass.replaceAll("invalid-field","");
          ((HtmlInputText)oComponent).setStyleClass(sCurrentStyleClass);
          System.out.println("Validating Currency isValid=["+bValid + "] class=["+ sCurrentStyleClass + "] message=["+sMessage+"]");
       public void validateAge(FacesContext oContext,UIComponent oComponent, Object oValue) {
          String sMessage = "";
          System.out.println("Validating Age..."+ oValue);
          UIInput oInput = (UIInput)oComponent;
          String sCurrentStyleClass = ((HtmlInputText)oComponent).getStyleClass();
          if (sCurrentStyleClass==null)
            sCurrentStyleClass= "";
          boolean bValid = true;
          try{
             int iAge = Integer.parseInt(oValue+"");
             if (iAge<18){
               bValid = false;
               sMessage = "Sorry you are too young.";
             if (iAge>99){
               bValid=false;
               sMessage = "Sorry you are too old.";
          catch(ClassCastException oException){
            bValid = false;
            oException.printStackTrace();
          catch(NumberFormatException oException){
            bValid=false;
            oException.printStackTrace();
          if (!bValid) {
            oInput.setValid(false);
            sMessage = "Invalid Age: " + sMessage;
            oContext.addMessage(oComponent.getClientId(oContext),new FacesMessage(sMessage));
            sCurrentStyleClass += " invalid-field ";
          else{
            //remove any existing invalid-field classes.
            sCurrentStyleClass = sCurrentStyleClass.replaceAll("invalid-field","");
          ((HtmlInputText)oComponent).setStyleClass(sCurrentStyleClass);
          System.out.println("Validating Age isValid=["+bValid + "] class=["+ sCurrentStyleClass + "] message=["+sMessage+"]");
       public void save(){
           System.out.println("Good Data  ....");
       }this is jsu a basic you can modify the validators and have one validator for each data type. the idea is when there is an error you need to add the appropriate style class. if you dont want to work with styleClass then instead of
    component.setStyleClass() use component.setStyle()and use the appropriate style.
    hope that would help.

  • Repeaters and DataGroups

    Hi All,
    It seems that in Flex 4, the new Repeater is now the DataGroup. I think this is generally a good thing as Repeaters tend to have some strange functionality, especially when using recycleChildren.
    However, I seem to have a bit of a problem with DataGroup. I would like my particular ItemRenderer to know what index it is in the dataProvider, such that if a user interacts with it then it can call a method based on the index. Eg. itemClicked(itemRendererIndex), but there doesn't seem to be any way in which the item index can be passed to the ItemRenderer. I don't want to put the index in the dataProvider if possible as this array is remotely managed and can change at any time, which makes adding extra index data relatively complex.
    When using a repeater this was easy as I could just assign repeater.currentIndex to some property of the repeated component.
    Perhaps I am approaching the problem in the wrong way, so let me explain what I am trying to do...
    I want to arrange some buttons horizontally in a line, each of which represents the day of a month. I want the text of the buttons to be populated by an ArrayCollection. I want to do this with a dataProvider because the array length and contents may change and I want this to be reflected in the number of buttons and the button text. The array does not contain the day number, this is implicit in the item's position in the array. If the user clicks one of the buttons I then wish to call a function to say that day 'n' has been clicked, so each button has to know which day/index it is.
    I originally did this with a Repeater, which worked, but I'm not convinced this is the best way, plus I am trying to use pure Flex 4. I then tried with DataGroup, but I can't pass the index to the buttons!
    Perhaps there is a better way to do this?
    Any help is much appreciated,
    Thanks,
    Chris.

    I avoid repeaters whenever I can.  Based on your description I would use something like the following.  Obviously change the click handler to your function call (itemClicked(event.target.owner.itemIndex)).
    Basically DataGroups use itemRenderers to render each item in the data provider, and itemRenderers publish the itemIndex and data attributes.  So you just need to hit the owner of the button to get the required info.
        <s:DataGroup dataProvider="{new ArrayList(['Monday', 'Tuesday', 'Wednesday', 'Otherday'])}" click="trace(event.target.owner.itemIndex, event.target.owner.data);">
            <s:layout>
                <s:HorizontalLayout />
            </s:layout>
            <s:itemRenderer>
                <fx:Component>
                    <s:ItemRenderer>
                        <s:Button label="{data}" />
                    </s:ItemRenderer>
                </fx:Component>
            </s:itemRenderer>
        </s:DataGroup>

  • "Suggestive" validators (suggestors?)

    Is there any way to do this? For example, I have a "signup"
    type form (name, email, address, hobbies, etc.)... Certain fields
    would be required and have their respective validators (name,
    email, phone)... But other fields (hobbies, homepage, etc.), I
    would like to recommend that the user fill them in before
    submitting the info, but it's OK if they don't... Is there any type
    of "suggestion validator" that can accomplish this, or do you just
    have to handle all the logic yourself...??? Or can you actually
    just do it with validators and I'm missing something obvious...???
    Just wondering...

    Istrasci,
    There is nothing like a "sugestion validator" in Flex
    framework. But as you said, you can validate those fields with your
    own logic. I would sugest you create your own "sugestion validator"
    class to use it in your project, sou it would be easier to handle.
    Depending on what you plan to do, you cold extend TextInput and
    create a flag, required or optional and create your own validator,
    which would handle each Field acording to its flag.
    (I personaly hate flex validators, i always create my own
    lib).
    I hope that my post was useful.
    Regards,
    Peter

  • Get the values from datatable?

    hi,
    my form having some textinputs with validators.
    and datatable.
    my datatable i am displaying data with boolean check box.
    when select check boxes , and click on remove button
    I am getting values in managed bean if no form validations for text inputs.
    now how to skip validations while click on remove button.
    thanks
    siva

    thanks solve problem.
    siva

  • How to use a Spry Menu as a Library item?

    Okay, this is my second post; but, with a different title.
    I made a Spry menu for my Home Page. I saved it and a logo
    together as a library item and placed the library item on a second
    page. The links in the menu work when there is no style sheet
    attached for the Spry meny and the menu appears just as text; but,
    as soon as the .css style sheet for the menu is attached to the
    second page, the menu appears correct except the drop down menus do
    not work. I tried adding a link to the Spry Java Script file as it
    is on the home page; still no luck.
    I tried the same with a test file, which I have since
    removed, stored at the same folder as the home page; same problem.
    How are we suposed to make a workable library item with a
    Spry Menu? Surely this is possible, no?
    Here are the two pages I am referring to:
    Good Page:
    http://iculver.com/
    Bad Page:
    http://iculver.com/pages/AboutUs/Personal_info.html

    Apologies - my mistake. You are correct, and my instructions
    were
    incomplete. That other bit is required too.
    > Now, I thought (probably in error) that items after !--
    were comments, but
    > it
    > seems to be required, too. I tried eliminating taht part
    and the menus did
    > not
    > work. I need all of this last part.
    The comments 'hide' the scripting from validators and older
    browsers, but
    it's still recognized as javascript, since the comments occur
    INSIDE a
    <script> tag.
    > these Spry Menus in Libraries easier to use...)
    It's not so hard once you get all the pieces together.
    1. Create the library item as described.
    2. Make sure that each page that is to carry this library
    item has the
    required links in the head (to the CSS and the js files), AND
    in the body.
    Why not use a template instead? That way, all of these links
    are managed
    for you.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "JustBob" <[email protected]> wrote in
    message
    news:[email protected]...
    > Hummm...
    >
    > Now, don't yell at me, okay? I'm a goLive switcher and
    really a graphic
    > designer, not a coder...
    >
    > So, It seems from the above message that I am to
    establish the links to
    > the
    > script and the css file before inserting the library
    item. But, either
    > way,
    > that didn;t do the trick for me. I did find a bit of
    code in one of the
    > pages
    > that seems to be required.
    >
    > It seems I also need to insert this just before the
    close of the body tag:
    >
    > <script type="text/javascript">
    > <!--
    > var MenuBar1 = new Spry.Widget.MenuBar("MenuBar",
    > {imgDown:"SpryAssets/SpryMenuBarDownHover.gif",
    > imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
    > //-->
    > </script>
    >
    > Now, I thought (probably in error) that items after !--
    were comments, but
    > it
    > seems to be required, too. I tried eliminating taht part
    and the menus did
    > not
    > work. I need all of this last part.
    >
    > I'm sorry I'm such a dope. I probably did something
    funny when I was
    > styling
    > the menu. (I do hope Adobe can accommodate dopes lime
    me, though, and make
    > these Spry Menus in Libraries easier to use...)
    >
    > Thanks for all of your help! Really!
    >

  • Detailed comments

    I've gone through the EAD spec. and I've come up with a detailed list of comments that I'd like to post here and also will post over at TheServerSide.com and send directly to the JSR group. This area will give the community a chance to discuss this more. There are a few things that I did not finish commenting on, but over-all this document is fairly complete with my comments thus far. But then again, I've only read the spec twice and spent a day considering it.
    I'll continue to add to this thread as I think of more.
    Brian Pontarelli
    Included document
    JSF 2.1
    Assuming that most applications will be setup like:
    HTML->HTTP->FacesServlet->reconstitute phase->validation phase->model phase
    This leads to an enormous amount of duplication as well as overhead. The information for each form component will be stored in the HttpServletRequest, expanded into the UIComponent Tree and stored in the FacesContext and finally migrated to the Application�s Model. Although this seems to be a small amount of work when considering smaller forms with two or three fields, it could become larger with 20-30 field forms. This continues to grow when considering an intensive web application with many users (i.e. 20+ requests per minute). In addition, the cost of the UIComponent and Application�s Model classes themselves might further increase the amount of memory consumed by this triple duplication as they may contain other member variables that increase each instances foot-print. In addition, without some comparison mechanism, the HttpSerlvetRequest parameters will be copied to the UIComponents local values, which will be copied to the Application�s Model each request. If, for example, the request goes all the way to the Invoke Application phase and then encounters an error, which will redirect the user back to the form so that they can fix some values, after they have fixed the values and resubmitted, the triple transfer happens, in its entirety, again (unless the application program is exceptionally savvy and is willing to build in an update recognition component that could skip application model updates when they are not needed).
    The simpler and more concise design seems to be a single duplication of data. This would be from the HttpServletRequest to the Application�s Model. This would remove the UIComponent�s local values entirely. The UIComponent tree could still be constructed and optimized however the JSF spec allows. Likewise, the UIComponent�s themselves could be �backed� by the Application�s Model classes as is the case in the MVC design of Java�s Swing APIs.
    The decoding process would work the same but would store the decoded information in the Application�s Model. Likewise, the encoding would retrieve it from the Application�s Model. This mimics other frameworks such as Jakarta Struts with their ActionForm classes that are essentially the Application�s Model (or at least positioned in such a way that they could be).
    JSF 2.3
    This has been tried many times and shown to be lacking. Server-side event models do not scale well because of the overhead of marshalling and unmarshalling the entire HttpServletRequest including all the form parameters, so that a single checkbox can change the values in a single selectbox (for example). The only solution to this problem seems to be the use of contained transmission systems, which transmit only the needed components state to the server. The server can respond with updates to any component, or whatever it needs. In order to attempt to accomplish this in a web browser, some very extensive JavaScript needs to be written which can cause enormous amounts of support issues. I think that you�ll find very little need for RequestEventHandlers and find that nearly 98%+ of the work will be done in the ApplicationEventHandlers.
    JSF 2.6
    This needs to be rewritten. This contains information about the Lifecycle management process before the reader knows what that is.
    JSF 2.7
    I don�t really like the concept of 1 Tree to 1 page yet, but I don�t know why. Need to think about this and draw some concrete conclusions about how this is lacking and what impacts it will have.
    How will applications be able to forward to HTML pages? It doesn�t seem possible in the current setup without creating Tree objects for pages that don�t contain JSF code. Likewise, it seems that the requirement of having response Trees dictate the outbound page require that every JSP page in the entire application use JSF code (in order to seem conceptually correct). This seems like a large requirement for businesses with existing info-structure. Not to mention the need to be redirected out of the J2EE application server to an ASP server. Of course no one wants that, but it is a reality. This seems very restricting. The flow should be flexible enough to support forwards and redirects to any resource inside and outside the container.
    JSF 2.8
    The requirement on forcing the Tree to be saved to the response or the session seems very restricting. This section is very ambiguous about what writing the Tree to the response means. Does this mean doing nothing because the JSF tags will do everything for you? Or does it mean adding additional information to the HTML about the state of the JSF system? In the latter case, this is simply duplication of the information that the JSF tags write out, is it not? And there might be implementations with large Trees and many users that do not want to bug down the session with this information and would rather spend the computing cycles to reconstruct it each time from the request. Additionally, would there be cases where a developer would want to send the information from a normal HTML page to the JSF system and have it construct a UIComponent Tree? This seems likely and not possible (?) with the requirement from this section.
    If you decide to leave in the local values and model values that I disagreed with above, you�ll need to be specific about where the values for the response come from when encode is called. It they come from the local values of the UIComponent, then the application logic will need to be responsible for migrating the values from the Application�s Model to the UIComponent�s local values. If they come from the Application�s Model, then every component will need to supply model references (I think). Or a better solution to this problem would be to add another phase to the lifecycle called �Update Local Values� which is designed to update the UIComponent�s local values from the Application�s Model if necessary. Or you could simply do away with the UIComponent�s local values altogether in favor of a more MVC oriented system where the view is directly backed by the Application�s Model (similar to Swing).
    JSF 3.1.2
    You probably want to add a way to determine a components individual and absolute id (bar and /foo/bar). This will be useful in tools as well as debugging.
    JSF 3.1.5-3.1.6
    See above about my issues with model references and local values. What if I write a JavaScript Tree component? This would mean that UIComponent�s local value would be of type com.foo.util.Btree (or something) and my Application�s Model might be the same. There is a lot of overhead doing things this way. What if my tree stores the groups and all the employees for a company with 50,000 people and 500 groups (not the best way to do things, but possible)? What if the Tree is roughly 1K in size (Java object size) and 2000 users are banging away at the system all day? Let�s see that�s 1K for the UIComponent�s local value, 1K for the Application�s Model, 2000 users, and roughly 4 Megs consistent memory usage for a single component.
    JSF 3.5.x
    This was a major concern to me when I wrote both of my frameworks. A reusable Validator is excellent because it reduces the amount of code duplication. However, it is very difficult to tailor messages for specific UIComponents using a reusable Vaildator. For example, on one page I just a text box for age and on another I use if for income. I don�t want my error messages to be generic stating that, �This value must be greater than 0 and less than X�. I want the user to know what must be within the range.
    One solution is to use the name of the input in the error message. This forces the user to name inputs in human readable form, which might not be possible. For example, I have an input for monthly overhead and I name it monthlyOverhead so that it is a legal variable name. You can�t have a message that reads, �monthlyOverhead must be greater than 0�. This just won�t fly in a production environment. It needs to be nice and human readable and say, �Your monthly overhead must be greater than zero.� However, you can�t name your UIComponent �Your monthly overhead� especially I you intend to do JavaScript on the page. Besides, it�s just bad style.
    Another solution is requiring specific sub-classes for each message required, or some parameter from the page to denote the specific message to use. The former clutters up the packages with tons of Validators and also requires way too much coding. The latter completely negates the ability to use parameterized messages without further bogging down the page with all the (un-localized) parameters to the error message or forces the placing of all the parameters inside the resource bundle for the error messages with a standard naming scheme (i.e. for the first parameter to the message �longRange.montlyOverhead.0=Your monthly overhead�). Since 1/3 of any application is really the view and interaction of which a large chunk is error messages, this is a major issue that must be considered. Because it always happens that the CEO plays around with the application one day and says, �I really wish this error message read this �� and then you�re in for some major headaches, unless this problem is solved up front.
    JSF 3.5.2.x and 4.x and 7.6.x
    These sections seem to break up the flow of reading. The previous sections were charging forward with information about the interfaces, the JSF classes and specifics about what is required for each Phase. Then we need to down shift quite a bit to talk about default/standard implementations that ship with JSF or are required to be implemented by implementers. I think that these should be contained in a later section after 5, 6, 7 and 8.
    JSF 5.1.2
    What are the implications of this decision on Internationalization? When different UIComponents encode using different Locales and the HttpServletResponse�s content type has already been set, there could be rendering problems on the client side in the browser.
    JSF 5.1.5
    Messages added to the message queue during validation or processing contain Unicode String Objects and could be written in any language. The Message Object does not contain information about the Locale that the message needs to be converted to and this is needed for internationalization. If I have a multi-lingual portal and output error messages in multiple languages, the spec needs to really consider what and where the charset for the HTTP header is going to be set. What if JSF realizes it needs to use UTF-8 but another tag library an application is using assumes fr_FR, who is correct and what will happen? How will JSF determine what encoding to use when it has Messages in ten different languages? What if the container starts writing the output to the stream before the header is set? Etc. etc.
    JSF 8.1
    This is possibly the most confusing and poorly written section in the entire document. This uses terms that don�t relate to anything, old class names and un-described tables. This needs to be re-written in a more concise way. I did not understand what a custom action was until I reached section 8.2.6 and realized that an action was really a tag implementation. Action is a poor choice of words because not all tags equate to actions. What is the action of an input tag? I understand action when talking about for-loop tags, but not input tags.
    JSF 8.3
    This seems quite contradictory to section JSF 2.8 because it leads the reader to believe that they have no control over the implementation of the use_faces tag and the method of saving the JSF state. That is UNTIL they read section 8.5. These two sections need to be combined to clarify the document.
    Comments:
    I think that JSF is a very good idea in general and that it is a very complicated thing to define (due mostly to the use of HTTP, which is a stateless protocol). There are so many frameworks out there and each has its own benefits and downfalls. However, it is imperative that this specification attempt to solve as many problems as possible and not introduce any more. The spec must be flexible enough to support implementations that drive for speed and those that drive for flexibility. It must also support enormous amounts of flexibility internally because as vendors attempt to comply with it, they want to make as few changes to their own code base as possible.
    Right now, JSF has not accomplished these goals. I think that it needs to consider a lot more than it has and really needs to address the more complex issues.

    Brian,
    I've gone through the EAD spec. and I've come up with
    a detailed list of comments that I'd like to post here
    and also will post over at TheServerSide.com and send
    directly to the JSR group. Thanks for the feedback, it's really appreciated. I've included some comments below. Even though I'm a member of the spec group, these are just my personal comments and do not represent any official position of the group. It's very important that you send feedback you want the spec group to consider to the mail address listed in the spec draft. Some of us read this forum, and try to answer questions and clarify things as best we can, but the only way to make sure the feedback is considered is to send it to the JSR-127 mail address.
    Included document
    JSF 2.1
    Assuming that most applications will be setup like:
    HTML->HTTP->FacesServlet->reconstitute
    phase->validation phase->model phase
    This leads to an enormous amount of duplication as
    well as overhead. The information for each form
    component will be stored in the HttpServletRequest,
    expanded into the UIComponent Tree and stored in the
    FacesContext and finally migrated to the Application�s
    Model. [...]This is not so bad as it may seem, since typically it's not copies of the information that get stored in multiple places, just references to the same object that represents the information.
    Consider a simple text field component that is associated with a model object. The text value arrives with the request to the server which creates a String object to hold it. The UI component that represents the text saves a reference to the same String object and eventually updates the model's reference to point to the same String object. The application back-end eventually gets a reference to the value from the model and, say, saves it in a database. Not until you hit the database do you need to make a copy of the bytes (in the database, not in the JVM).
    JSF 2.3
    This has been tried many times and shown to be
    lacking. Server-side event models do not scale well
    because of the overhead of marshalling and
    unmarshalling the entire HttpServletRequest including
    all the form parameters, so that a single checkbox can
    change the values in a single selectbox (for example).
    The only solution to this problem seems to be the use
    of contained transmission systems, which transmit only
    the needed components state to the server. The server
    can respond with updates to any component, or whatever
    it needs. In order to attempt to accomplish this in a
    web browser, some very extensive JavaScript needs to
    be written which can cause enormous amounts of support
    issues. I think that you�ll find very little need for
    RequestEventHandlers and find that nearly 98%+ of the
    work will be done in the ApplicationEventHandlers.I agree with you that a web app can never be as responsive as a thick-client app unless client-side code (JavaScript) is used. Web apps must be designed with this in mind, which can be a challenge in itself.
    But there are still advantages with an event-based model, namely that it provides a higher abstraction layer than coding directly to the HTTP request data. And even in a web app, having stateful components that generate events simplifies the UI development. As an example, say you have a large set of rows from a database query you want to display a few rows at a time. A stateful component bound to this query result can take care of all the details involved, rendering Next/Previous buttons as needed. Clicking on one of the buttons fires an event that the component itself can handle to adjust the display to the selected row subset.
    Coding the logic for this over and over in each application that needs it (as you need to do without access to powerful components like this) is error prone and boring ;-)
    Finally, JSF components can be smart and generate client-side code as well to provide a more responsive user interface.
    JSF 2.6
    This needs to be rewritten. This contains information
    about the Lifecycle management process before the
    reader knows what that is.Many parts of the draft needs to be rewritten; it's still a work in progress.
    JSF 2.7
    I don�t really like the concept of 1 Tree to 1 page
    yet, but I don�t know why. Need to think about this
    and draw some concrete conclusions about how this is
    lacking and what impacts it will have.I have the same concerns, and think we need to take a close look at how a response can be composed from multiple JSF Trees, or a combination of regular JSP pages and JSF Trees, etc. I know others in the spec group agree that this is a vague area that needs more attention.
    How will applications be able to forward to HTML
    pages? It doesn�t seem possible in the current setup
    without creating Tree objects for pages that don�t
    contain JSF code. Likewise, it seems that the
    requirement of having response Trees dictate the
    outbound page require that every JSP page in the
    entire application use JSF code (in order to seem
    conceptually correct). [...]I don't think this is a problem. The application can decide to redirect (or forward) to any resource it wants when it processes an application event; it doesn't have to generate a new JSF response. But yes, navigation is also an area that needs attention in general.
    JSF 2.8
    The requirement on forcing the Tree to be saved to the
    response or the session seems very restricting. This
    section is very ambiguous about what writing the Tree
    to the response means. [...]It is, isn't it ;-) Again, this is an area that still needs work, and I believe we must be able to provide a lot of flexibility here. Depending on the type of components in the Tree, the size of the Tree, the number of concurrent users and size of the application, etc. different approaches will be needed. How much data must be saved is also dependent on the type of component.
    Additionally, would there be cases where a developer
    would want to send the information from a normal HTML
    page to the JSF system and have it construct a
    UIComponent Tree? This seems likely and not possible
    (?) with the requirement from this section.In that case the request initiated from the HTML page would be directed directly to application code (a servlet, maybe) which would create an appropriate JSF component Tree and generate a response from it.
    If you decide to leave in the local values and model
    values that I disagreed with above, you�ll need to be
    specific about where the values for the response come
    from when encode is called. It they come from the
    local values of the UIComponent, then the application
    logic will need to be responsible for migrating the
    values from the Application�s Model to the
    UIComponent�s local values. If they come from the
    Application�s Model, then every component will need to
    supply model references (I think). [...]I think this is pretty clear in the current EA draft. First, a model is optional for the basic component types (while more complex things, like a DataGrid, may require it). The draft says (in 3.16): "For components that are associated with an object in the model data of an application (that is, components with a non-null model reference expression in the modelReference property), the currentValue() method is used to retrieve the local value if there is one, or to retrieve the underlying model object if there is no local value. If there is no model reference expression, currentValue() returns the local value if any; otherwise it returns null."
    Other parts of the spec (can't find it now) deals with how the local value is set and reset. The effect for the normal case is that if there's a non-null model reference, its value is used, otherwise the local value is used. In special cases, a local value can be set to explicitly ignore the model value.
    JSF 3.5.x
    This was a major concern to me when I wrote both of my
    frameworks. A reusable Validator is excellent because
    it reduces the amount of code duplication. However, it
    is very difficult to tailor messages for specific
    UIComponents using a reusable Vaildator. For example,
    on one page I just a text box for age and on another I
    use if for income. I don�t want my error messages to
    be generic stating that, �This value must be greater
    than 0 and less than X�. I want the user to know what
    must be within the range. [...]I agree that this is a concern. In addition to the solutions you have suggested, I think a way to solve it is by letting validators fire "invalid value" events of different types. These events would contain a default message but also getter method for the interesting parts (e.g. the invalid value, the start and the stop value for an "invalid range" event). An event handler can use the getter methods for the individual values and build a message that's appropriate for the application,
    JSF 5.1.2
    What are the implications of this decision on
    Internationalization? [...]
    JSF 5.1.5
    Messages added to the message queue during validation
    or processing contain Unicode String Objects and could
    be written in any language. The Message Object does
    not contain information about the Locale that the
    message needs to be converted to and this is needed
    for internationalization. [...]I need to read up on the latest i18n proposals, but in general I think you're right that there's more work to do in this area.
    JSF 8.1
    This is possibly the most confusing and poorly written
    section in the entire document. This uses terms that
    don�t relate to anything, old class names and
    un-described tables. [...]The whole JSP layer is still immature, but IMHO, we need to get the API right before we address the JSP issues.
    I did not understand what a custom
    action was until I reached section 8.2.6 and realized
    that an action was really a tag implementation. Action
    is a poor choice of words because not all tags equate
    to actions. What is the action of an input tag? I
    understand action when talking about for-loop tags,
    but not input tags. [...]Actually, "action" is the proper name defined by the JSP specification for what's described in this section. A "JSP action" is represented by an "XML element" in a page, which in turn consists of a "start tag", a "body" and an "end tag", or just an "empty tag".
    Comments:
    I think that JSF is a very good idea in general and
    that it is a very complicated thing to define (due
    mostly to the use of HTTP, which is a stateless
    protocol). There are so many frameworks out there and
    each has its own benefits and downfalls. However, it
    is imperative that this specification attempt to solve
    as many problems as possible and not introduce any
    more. The spec must be flexible enough to support
    implementations that drive for speed and those that
    drive for flexibility. It must also support enormous
    amounts of flexibility internally because as vendors
    attempt to comply with it, they want to make as few
    changes to their own code base as possible.
    Right now, JSF has not accomplished these goals. I
    think that it needs to consider a lot more than it has
    and really needs to address the more complex issues.I agree, and thank you for the feedback. There are many holes yet to be filled and many details to nail down. All of this takes time, since you must build support for the spec among a large number of vendors and other market groups, as well as among developers; this is one of the most important goals for any specification.

  • JDeveloper 11.1.2.4: Is it possible to only display custom validator IDs defined in faces-config.xml

    I have many custom validators and do not need to see the default values as listed in the below screen shot:
    http://i.imgur.com/xOQgxeZ.png
    Is it possible to only show the custom validators I define within faces-config.xml?
    Thanks,
    Wes

    Deepak,
    don't understand this sentence:
    "Do not specify the binding attribute value in the f:validator tag for the bindings not to display."
    Wes,
    The answer to the question seems to be "no" you cannot suppress the other validator entries as they too are configured in a faces config file - though not the one in the application
    Frank

  • What is the best time to validate this?

    I'm creating a standard form which asks the user for personal data (name, age, address, and so on...).
    At the end of this form the user must enter a User Name for his/her account.
    Since validating the user name requires the server to connect to the database and check wheter that name already exists or not, I'd like to do this verification only when all the other fields in the form are valid. This will reduce accesses to the DB.
    Think about connecting to the DB even when the user fails entering a valid age or other data. It seems pretty inefficient.
    What is the best way to achieve this check?
    I was thinking to create a backing bean which includes all the fields in the form, and which validates the user name field only if every single other field is valid... but I guess that's not how it should be done.
    Any idea? Please help.
    Thank you!

    That's what I do...
    The problem is: I want the other fields to be validated by their validators (and that what happens). But I want the user name to be validated only if all the other fields are valid (i.e. previously validated and accepted), otherwise no validation occours on the user name fields (except for the "needed" one)
    Is that possible?
    I'm doing it with a big Backing Bean which embodies the whole form and checks whether the other fileds are valid or not before validating the User Name.

  • What went wrong here?

    Like I said in the picture, I changed my font size and font family for one of my <p> in one of my divs. Why did this change carry over to all my divs and <p>'s? What did I do wrong and what can I do to fix it?
    I am using Dreamweaver CS6
    Thanks in advance for your help!
    Dalton

    Run your page through these validators and repair any errors...
    HTML: http://validator.w3.org/
    CSS: http://jigsaw.w3.org/css-validator/
    If that doesn't fix the issue, we'll definitely need to see your code to find the problem.

  • Set fields of derived class in base class constructor via reflection?

    Does the Java Language Specification explicitly allow setting of fields of a derived class from within the base class' constructor via reflection? The following test case runs green, but I would really like to know if this Java code is compatible among different VM implementations.
    Many thanks for your feedback!
    Norman
    public class DerivedClassReflectionWorksInBaseClassConstructorTest extends TestCase {
    abstract static class A {
        A() {
            try {
                getClass().getDeclaredField("x").setInt(this, 42);
            } catch (Exception e) {
                throw new RuntimeException(e);
    static class B extends A {
        int x;
        B() {
        B(int x) {
            this.x = x;
    public void testThatItWorks() {
        assertEquals(42, new B().x);
        assertEquals(99, new B(99).x);
    }

    why not just put a method in the superclass that the subclasses can call to initialize the subclass member variable?In derived classes (which are plug-ins), clients can use a field annotation which provides some parameter metadata such as validators and the default value. The framework must set the default value of fields, before the class' initializer or constructors are called. If the framework would do this after derived class' initializer or constructors are called, they would be overwritten:
    Framework:
    public abstract class Operator {
        public abstract void initialize();
    }Plug-In:
    public class SomeOperator extends Operator {
        @Parameter(defaultValue="42", interval="[0,100)")
        double threshold;
        @Parameter(defaultValue="C", valueSet="A,B,C")
        String mode;
        public void setThreshold(double threshold) {this.threshold = threshold;}
        public void setMode(String mode) {this.mode = mode;}
        // called by the framework after default values have been set
        public void initialize() {
    }On the other hand, the default values and other metadata are also used to create GUIs and XML I/O for the derived operator class, without having it instantiated. So we cannot use the initial instance field values for that, because we don't have an instance.

Maybe you are looking for

  • Can i install Oracle ADF Essentials 11.1.2.3 on weblogic 10.6 ?

    can i install Oracle ADF Essentials 11.1.2.3 on weblogic 10.6 ? what the difference between ADF Essentials 11.1.2.3 and Application Development Run time 11.1.1.6 ? can i use ADF Essentials 11.1.2.3 instead of Application Development Run time 11.1.1.6

  • Purchase Order Output Failing

    When a user creates a purchase order, the output (usually set to print and fax) is failing. On the Message window, the output method has a status of "incorrectly processed" and upon attempting to display a print preview of the document an error messa

  • To Select Max Value in the table

    Hello All, I want to select a record from a Z table which has the following fields. POSID STLNR DATUM UZEIT UNAME TCODE I have to select LAstest record depending upon the datum & uzeit field I am using like this.     SELECT SINGLE UNAME              

  • WLC 4404 and LAG

    We are trying to setup the four ports on our 4404 wireless lan controller to use LAG connected to a 3560G switch. If we connect distribution port 1 to a switch trunked port the unit works as expected. However, if we create an etherchannel containing

  • Unable to upgrade my 3 year-old MacBook Pro (w/ Intel chip) 10.5.8 to Snow Leopard using installation disk. Why is this so difficult?

    I have a macbook pro OSX 10.5.8 and cannot seem to upgrade to Snow Leopard using my Snow Leopard disk. My MacBook Pro has an Intel chip. Why is this so complicated and how am I supposed to install Snow Leopard if I can't do it via disk??