Thanks Martin,
> This means you also need to make sure you handle the case where a
> value-expression/binding is set.
probably asking a stupid question... Won't that also be covered by the given
approach?
// storing old bean values, altering bean values...
super.encodeAll(context, arc, component, bean);
//restoring old bean values
Cheers,
Carsten
Martin Marinschek wrote:
>
> Hi Carsten,
>
> it is ok, if you correctly restore the old values ;) This means you also
> need to make sure you handle the case where a value-expression/binding is
> set.
>
> regards,
>
> Martin
>
> On 8/14/07, Carsten Pieper <[EMAIL PROTECTED]> wrote:
>>
>>
>> Thanks a lot for the valued advice, Simon and Martin,
>>
>> so I'll have a go at Simon's recommendation. Just a question concerning
>> your
>> remarks
>> to my approach with pushing things into the bean: Would that approach be
>> OK,
>> if I'd tidied everything up? Something like the following (in my
>> overwritten
>> encodeAll(...)):
>>
>> // storing old bean values, altering bean values...
>>
>> super.encodeAll(context, arc, component, bean);
>>
>> // restoring old bean values
>>
>> Well, this (incl. tidying up) is how I've been showed to do this but
>> probably I've been a little
>> careless as I've never made use of these onkeyxxx properties ...
>>
>> Best regards,
>> Carsten
>>
>>
>>
>> Martin Marinschek wrote:
>> >
>> > Just as added information: what Simon says holds true also for
>> > standard JSF (non-Trinidad components)...
>> >
>> > regards,
>> >
>> > Martin
>> >
>> > On 8/13/07, Simon Lessard <[EMAIL PROTECTED]> wrote:
>> >> Hello again,
>> >>
>> >> I forgot to mention another issue with pushing values in the FacesBean
>> >> inside renderer code. Assume that your styleClass attribute is set to
>> an
>> >> EL.
>> >> If the EL returns "readOnly" during a rendering, you're going to alter
>> >> the
>> >> component attributes permanently and the JavaScript events will
>> continue
>> >> to
>> >> return false even if the styleClass is no longer "readOnly" for
>> further
>> >> requests.
>> >>
>> >>
>> >> Regards,
>> >>
>> >> ~ Simon
>> >>
>> >>
>> >> On 8/13/07, Simon Lessard <[EMAIL PROTECTED]> wrote:
>> >> > Hello Carsten,
>> >> >
>> >> > You shouldn't alter the bean value in the renderer. It's not right
>> to
>> >> do
>> >> so. Instead, you should override the various getXyz(FacesBean) method
>> of
>> >> the
>> >> renderer. This will ensure that you safely overhaul all properties
>> >> without
>> >> pushing value strange values in the saved state.
>> >> >
>> >> > Also, since the renderer is the most complex part of component
>> >> creation,
>> >> why don't you create a new custom one like outputSkinnedText or
>> >> something?
>> >> The component can extends CoreOutputText simply using a different
>> >> renderer
>> >> type. The renderer can extends CoreOutputTextRenderer and simply use
>> the
>> >> following code:
>> >> >
>> >> > public OutputSkinnedRenderer extends OutputTextRenderer
>> >> > {
>> >> > public OutputSkinnedRenderer()
>> >> > {
>> >> > super(CoreOutputSkinned.TYPE);
>> >> > }
>> >> >
>> >> > public void encodeAll(FacesContext context,
>> >> > RenderingContext rc,
>> >> > UIComponent component,
>> >> > FacesBean bean) throws IOException
>> >> > {
>> >> > ResponseWriter writer = context.getResponseWriter();
>> >> >
>> >> > // Create a wrapping span
>> >> > writer.startElement("span", component);
>> >> >
>> >> > // Write our new skin selector
>> >> > renderStyleClass(context, rc, "af|outputSkinnedText");
>> >> >
>> >> > // Render the text normally
>> >> > super.encodeAll(context, rc, component, bean);
>> >> >
>> >> > // Close the wrapping span element
>> >> > writer.endElement("span");
>> >> > }
>> >> > }
>> >> >
>> >> >
>> >> >
>> >> > Regards,
>> >> >
>> >> > ~ Simon
>> >> >
>> >> > On 8/13/07, Carsten Pieper <[EMAIL PROTECTED]> wrote:
>> >> >
>> >> > >
>> >> > > 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.
>> >> > >
>> >> > >
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>> > --
>> >
>> > 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#a12139094
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>
>
> --
>
> 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#a12159484
Sent from the MyFaces - Users mailing list archive at Nabble.com.