Hi,

as most of you might have noticed the topic of this thread somehow drifted
from 
tr:outputText to tr:inputText...

Anyhow, I implemented my option 2) (new styleClass "readOnly"), which is
running fine except of
one issue (inherent to this approach with onxxx --> return false;). If the
text is getting to long
for my inputText it's now accessible via the mouse but not (since the
onkeyxxx stuff...) via
the keyboard. 

If anybody is interested in this non-keyboard-only solution, here it is:

In CSS (just note the "nested selector"; the stuff between the brackets
isn't important/belongs to you...):
-----------------------------------------------------------------------------------------------------
.readOnly af|inputText::content{
    -tr-rule-ref: selector(".AFTextBackground:alias");
    -tr-rule-ref: selector(".MyDisplayTextBorder:alias");
}

Extending InputTextRenderer:
----------------------------
package bla;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import org.apache.myfaces.trinidad.bean.FacesBean;
import org.apache.myfaces.trinidad.bean.PropertyKey;
import org.apache.myfaces.trinidad.context.RenderingContext;
import
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.InputTextRenderer;

public class InputTextExtRenderer extends InputTextRenderer
{

  public InputTextExtRenderer()
  {
    super();
  } 

  @Override
  protected void findTypeConstants(FacesBean.Type type)
  {
    super.findTypeConstants(type);
    _styleClassKey = type.findKey("styleClass");
    _onkeyupKey = type.findKey("onkeyup");
    _onkeydownKey = type.findKey("onkeydown");
    _onkeypressKey = type.findKey("onkeypress");
  }
  
  @Override
  protected void encodeAll(FacesContext        context,
      RenderingContext arc,
      UIComponent         component,
      FacesBean           bean) throws IOException
  {
    String styleClass = (String)bean.getProperty(_styleClassKey);
    if (READONLY_INPUT_TEXT_SELECTOR.equalsIgnoreCase(styleClass))
    {
      bean.setProperty(_onkeyupKey, RETURN_FALSE);
      bean.setProperty(_onkeydownKey, RETURN_FALSE);
      bean.setProperty(_onkeypressKey, RETURN_FALSE);
    }
    
    super.encodeAll(context, arc, component, bean);
  }

  private static String READONLY_INPUT_TEXT_SELECTOR = "readOnly";
  private static String RETURN_FALSE = "return false;";

  private PropertyKey _styleClassKey;
  private PropertyKey _onkeyupKey;
  private PropertyKey _onkeydownKey;
  private PropertyKey _onkeypressKey;
}

Configuring the faces-config.xml:
-------------------------------
                <renderer>
                        <component-family>
                                org.apache.myfaces.trinidad.Input
                        </component-family>
                        <renderer-type>
                                org.apache.myfaces.trinidad.Text
                        </renderer-type>
                        <renderer-class>
                                
de.continentale.vu.jsf.base.component.trinidad.InputTextExtRenderer
                        </renderer-class>
                </renderer>

Using it in the JSF page:
-----------------------
<tr:inputText label="My short inputText (styleClass: readOnly;)"
        value="Hello inputText" contentStyle="width: 50px;"
        styleClass="readOnly"></tr:inputText>

Cheers, Carsten

-

Carsten Pieper wrote:
> 
> Hi Martin,
> 
> yes, that works, thank you!
> 
> Some thoughts, though:  Without touching the renderer this would mean that
> (as in your example) the inputText's attribute readOnly must not be set or
> else the effect of these onxxx methods returning false would be bypassed.
> 
> When chosing to extend the InputTextRenderer there are two options (at
> least ;-) ):
> 
> 1) If attribute readOnly (or attribute disabled; should be treated equally
> in our application, but
> this, of course, isn't the default...) is set to true, do this in the new
> renderer:
> - get rid of default readOnly-behaviour (which might be tricky to "extract
> and eliminate")
> - set those onxxx to "return false;"
> 
> 2) Alternatively, leave attribute readOnly and according behaviour
> untouched. Instead,
> - invent a new style class (e.g. "readOnly")
> - in the CSS, for this style class use the same settings as for
> "af|inputText:disabled::content"
> - in the renderer, if styleClass = "readOnly" set those onxxx to "return
> false;"
> 
> In principle, option 1) would be my favourite solution, but due to the
> intricate situation
> (InputTextRenderer has quite a line of ancestors...) and me being new to
> the fine art of
> extending Trinidad renderers, which both makes it hard to isolate what
> happens where and
> how to replace it, I think option 2) is the way for us to go (just
> injecting the new behaviour
> for styleClass "readOnly" and delegating everything else to
> InputTextRenderer seems to be
> a lot easier...).
> 
> Best regards,
> Carsten
> 
> 
> 
> Martin Marinschek wrote:
>> 
>> Hi Carsten,
>> 
>> (for reference, I'm also posting this message in the original thread)
>> 
>> I've played around with the options a bit more, and this is what could
>> work - with this you'd have an input field (and therefore automatic
>> text-control by the browser), and then you could also effectively
>> disable the keyboard:
>> 
>>   <label for="text">Textfield:</label><input id="text" name="text"
>> type="text" value="irgendwas" onkeyup="return false;"
>> onkeydown="return false;" onkeypress="return false;" />
>> 
>> regards,
>> 
>> Martin
>> 
>> ...
>> 
>> -- 
>> 
>> http://www.irian.at
>> 
>> Your JSF powerhouse -
>> JSF Consulting, Development and
>> Courses in English and German
>> 
>> Professional Support for Apache MyFaces
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/-Trinidad--Skinning---no-CSS-selector-for-tr%3AoutputText--tf4247489.html#a12127815
Sent from the MyFaces - Users mailing list archive at Nabble.com.

Reply via email to