myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From M Rather <mrat...@definedlogic.com>
Subject Re: default value of input field not of string type - how to set in JSF?
Date Wed, 26 Dec 2007 21:01:21 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Andrew:<br>
<br>
As for first suggestion:<br>
<pre wrap="">1) Have the converter use a default value when there is no value</pre>
It is more like suggested default value for this form, it could be a
different default in a different form. It is such in my case, where a
content created from one link defaults to MENU_ITEM, and if content is
created from another link it defaults to another value. So converter
may not be a good place to set it, as the same converter will get used
at both places.<br>
<br>
as for the second suggestion:<br>
<pre wrap="">2) Have the backing bean value never be null (always require that it is
set)</pre>
I could set the defaults in the managed bean as 'usually' different
forms will have separate 'managed beans' and defaults could be set
there.. But, for this option there is a 'what if' question, what if I
am using the same form+managed bean from different links which should
result in defaults of different types? As I am writing this, just
thinking out loud, it is possible that the different links send params
to the managed bean with default values, and the managed bean sets it
in 'add' action method before the form is drawn. But the 'what if'
question still remains, what if I want a default value to be supplied
from jsf for each form (if different forms are using the same managed
bean, or Is that not a good idea?)? Is it not possible? <br>
<br>
Thanks<br>
MRather<br>
<br>
Andrew Robinson wrote:
<blockquote
 cite="mid:bc36a6210712261234w5a9e166dh511fb7ec97667840@mail.gmail.com"
 type="cite">
  <pre wrap="">1) Have the converter use a default value when there is no value
or
2) Have the backing bean value never be null (always require that it is set)

On Dec 26, 2007 10:48 AM, M Rather <a class="moz-txt-link-rfc2396E" href="mailto:mrather@definedlogic.com">&lt;mrather@definedlogic.com&gt;</a>
wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hello,

I want a hidden input field with a default value put in JSF page. The
value that the input field is tied to is of type 'ContentType' (object),
so I use a converter to convert the string to the object as:

&lt;h:inputHidden value="#{contentForm.content.type}" id="type" &gt;
    &lt;f:converter converterId="converters.ContentTypeConverter"  /&gt;
 &lt;/h:inputHidden&gt;

Since the inputHidden is bound to "contentForm.content.type" by virtue
of me assigning it to the value attribute, and since the content.type by
default is null, so the input is rendered as:

&lt;input id="contentForm:type" type="hidden" value="" name="contentForm:type"/&gt;

note: value="" I would like to have it defaulted to value="MENU_ITEM" as:

&lt;input id="contentForm:type" type="hidden" value="MENU_ITEM" name="contentForm:type"/&gt;

but, if I change the h:inputHidden to value="MENU_ITEM",  I do get the
desired input tag, but the value is not then assigned to content object
upon submission.

So, if I use value="contentForm.content.type", I do get proper linking
with backing bean properties, but NO default value. and I if provide a
text value like value="MENU_ITEM",  I do get the proper default value,
but I do NOT get the linking with backing bean. How can this be resolved?

Thanks
MRather

    </pre>
  </blockquote>
  <pre wrap=""><!---->
  </pre>
</blockquote>
<br>
</body>
</html>

Mime
View raw message