[izpack-devel] Dynamic controls&validation in UserInputPanel

Vladimir Ralev vralev at redhat.com
Tue Mar 13 17:16:35 CET 2007


Now that we have conditions and the different fields can be displayed 
conditionally with some rules assigned to them, I think it will be a 
good addition to make these a bit more dynamic. In other words - make 
the UIP GUI to be completely redrawn and revalidated on certain events 
(like clicking on a checkbox or radio, others are possible too).

For example let's say you have a Normal/Advanced radio selector in your 
UIP and you want additional controls to be displayed for advanced users, 
but not to be shown for users who selected the "Normal" option. Another 
example is server security (this is what need here at JBoss). The user 
has to choose:
1. Enable local administration only (no authentication)
2. Enable remote administration (password authentication)

When the users clicks on remote admin he gets user/pass input fields, 
otherwise nothig additional and all this in a single panel without 
clicking next and going back and forth.


The implementation:
---------------------

I added an attribute for radio and checkbox fields called "revalidate". 
If you set revalidave="yes" for a radio of checkbox the whole Panel is 
being recreated with updated variables.

   <!-- Standard/Advanced configuration panel -->
   <panel order="0">
      <field type="radio" variable="installConfig">
         <description align="left" txt="Select Standard installation or 
select Advanced to make changes"
            id="installConfig.text"/>
         <spec>
           <choice txt="Standard" revalidate="yes" 
id="installConfig.radio.standard" value="standard"  set="true"/>        
           <choice txt="Advance" revalidate="yes" 
id="installConfig.radio.advanced" value="advanced" />          
         </spec>
      </field>     
      <field type="divider" align="center"/>
      <field type="staticText" conditionid="advanced" align="left" 
id="installConfig.note"
         txt="This text is only displayed if advanced if checked" />
   </panel>

You can see that installConfig.note is rendered only when condition 
"advanced" is satisfied. Condition advanced is defined like this:

        <condition type="variable" id="advanced">
                <name>installConfig</name>
                <value>advanced</value>
        </condition>

This condition is checking whether installConfig (the radio) is in 
advanced mode. Note that installConfig.radio.standard and 
installConfig.radio.advanced cause revalidation, so the note is updated 
whenever the user clicks on one of them.

Performance:
--------------
There is no noticeable slowdown for up to about 10 conditionid-enabled 
controls on my machine. Have in mind that if you radios or checkboxes do 
not have revalidate="yes" there is no performance loss at all.

One more hack:
----------------
The UIPs are using a TwoColumnLayout with hardcoded topBuffer=25%. With 
the dynamic panel updates the height of you panel varies as components 
are removed or added on the fly, and thus moved up and down with each 
revalidation. That's why I added an attribute topBuffer to the panel tag 
in userInputSpec.xml. If you set topBuffer=0% the panel always appears 
at the topmost available place and stays there no matter the height. If 
you omit the topBuffer, the default value is 25 as before.
   <!-- Standard/Advanced configuration panel -->
   <panel order="0" topBuffer="0">
      <field type="title" align="right"
         txt="Standard - Advanced Option" bold="true" size="2"
         id="installConfigName"
         icon="/images/search.png"
         />
      <field type="radio" variable="installConfig">
         <description align="left" txt="Select Standard installation or 
select Advanced to make changes"
            id="installConfig.text"/>
         <spec>
           <choice txt="Standard" revalidate="yes" 
id="installConfig.radio.standard" value="standard"  set="true"/>        
           <choice txt="Advance" revalidate="yes" 
id="installConfig.radio.advanced" value="advanced" />          
         </spec>
      </field>     
      <field type="divider" align="center"/>
      <field type="staticText" conditionid="standard-advanced" 
align="left" id="installConfig.note"
         txt="Note: Selecting Advanced option allows you to chnage 
various configurations like DataSource, Security, Isolation and Call by 
Value Semantics etc" />
   </panel>

You can use spaces to make some static gap if you want to have similar 
effects.


If you approve this feature I will commit it to the trunk or the 3.10.1 
branch (it's just 20 lines of code)?



More information about the izpack-devel mailing list