You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Aleksandr Mazur <ma...@reksoft.ru> on 2007/03/13 08:15:38 UTC

Re: ---SPAM--- Re: setting default value for input field?

Hi David,

Life could be easy with facelets. For example:

Tag file: myinputText.xhtml 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:c="http://java.sun.com/jstl/core"
        >
<ui:composition>
<c:if test="#{empty value}">
        <c:set var="value" value="#{default}"/>
</c:if>
        <t:inputText id="#{name}" value="#{value}" required="#{required}">
                <c:if test="#{!empty size}">
                        <f:attribute name="size" value="#{size}"/>
                </c:if>
            <ui:insert/>
        </t:inputText>
</ui:composition>
</html>

So, on your page:

<my:inputText value="#{myBean.fieldValue}" default="Search..." size="50" 
required="false"/>
 
Best regards,
Aleksandr Mazur,




David Delbecq <de...@oma.be> 
12.03.2007 22:29
Please respond to
"MyFaces Discussion" <us...@myfaces.apache.org>


To
MyFaces Discussion <us...@myfaces.apache.org>
cc

Subject
---SPAM--- Re: setting default value for input field?






Thanks but it does not fit the needs
1) the default value should be configurable per page. It's not the only
hidden field. Some have a searchScope that depend on which page the form
sit in. It can't be initialized by 'managed property'

Cmon, there should be something as simple as defaut="..." that exist in
JSF. I can't believe a form couldn't have default values in the JSP...

Steve Torrefranca a écrit :
> I am also a JSF newbie but I think for default values you can try
> managed property
>
> In you faces-config.xml you do something like
>
>  <managed-bean>
>    <managed-bean-name>theBackingBean</managed-bean-name>
>    <managed-bean-class>
>    com.whatever.com.TheBackingBean</managed-bean-class>
>    <managed-bean-scope>
>    session</managed-bean-scope>
>      <managed-property>
>          <property-name>theProperty</property-name>
>          <value>theDefaultvalue</value>
>      </managed-property>
>  </managed-bean>
>
>
>
>
> David Delbecq wrote:
>> Hello,
>>
>> I need to design a form in JSF where there are various default value 
for
>> various fields.
>> However, the default value is separated from the backing bean (it's
>> something to display in initial form). I am not sure how to do this, i
>> don't see in h:inputHidden anything that relate to a default value.
>>
>> I need to convert this struts form:
>>
>>
>>         <html:hidden property="scope" value="${param.searchScope}"/>
>>         <html:hidden property="requestedNodeResults" value="15"/>
>>         <html:text property="query" styleClass="search"/>
>> to a JSF form, but i don't know where to put the '15' and
>> 'param.searchScope' in JSf
>>
>> setting <h:inputHidden value="#{theForm.requestedNodeResults}"/> does
>> not set the default value to 15.
>>
>> Any suggestion to set default value? Do i have to do
>> <h:inputHidden
>> value="#{theForm.requestedNodeResults}">15</h:inputHidden> or something
>> like that? Can't find documentation on setting default form values...
>>
>> Help appreciated.
>>
>>
>> 
>



Re: ---SPAM--- Re: setting default value for input field?

Posted by David Delbecq <de...@oma.be>.
Thank you Aleksandr, it does fit my need, i didn't know about the
f:attribute, i'll check if it works for the value (your example use the
size :p )

To people saying it's one backing bean per form, i agree up to some
point. In my case i have only 2 forms and could separate in 2 backing
beans. But main problems are
1) i don't have access to backing bean initialization step thru JSf,
it's manager by struts faces
2) on the same form, default value of some fields depend on current user
profile, on some GET parameters and so on, this make it difficult to
manage somewhere else than in form.

Thanks for help anyway.

En l'instant précis du 13/03/07 08:15, Aleksandr Mazur s'exprimait en
ces termes:
> Hi David,
>
> Life could be easy with facelets. For example:
>
> Tag file: myinputText.xhtml 
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE html
>         PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml"
>       xmlns:ui="http://java.sun.com/jsf/facelets"
>       xmlns:t="http://myfaces.apache.org/tomahawk"
>       xmlns:c="http://java.sun.com/jstl/core"
>         >
> <ui:composition>
> <c:if test="#{empty value}">
>         <c:set var="value" value="#{default}"/>
> </c:if>
>         <t:inputText id="#{name}" value="#{value}" required="#{required}">
>                 <c:if test="#{!empty size}">
>                         <f:attribute name="size" value="#{size}"/>
>                 </c:if>
>             <ui:insert/>
>         </t:inputText>
> </ui:composition>
> </html>
>
> So, on your page:
>
> <my:inputText value="#{myBean.fieldValue}" default="Search..." size="50" 
> required="false"/>
>  
> Best regards,
> Aleksandr Mazur,
>
>
>
>
> David Delbecq <de...@oma.be> 
> 12.03.2007 22:29
> Please respond to
> "MyFaces Discussion" <us...@myfaces.apache.org>
>
>
> To
> MyFaces Discussion <us...@myfaces.apache.org>
> cc
>
> Subject
> ---SPAM--- Re: setting default value for input field?
>
>
>
>
>
>
> Thanks but it does not fit the needs
> 1) the default value should be configurable per page. It's not the only
> hidden field. Some have a searchScope that depend on which page the form
> sit in. It can't be initialized by 'managed property'
>
> Cmon, there should be something as simple as defaut="..." that exist in
> JSF. I can't believe a form couldn't have default values in the JSP...
>
> Steve Torrefranca a écrit :
>   
>> I am also a JSF newbie but I think for default values you can try
>> managed property
>>
>> In you faces-config.xml you do something like
>>
>>  <managed-bean>
>>    <managed-bean-name>theBackingBean</managed-bean-name>
>>    <managed-bean-class>
>>    com.whatever.com.TheBackingBean</managed-bean-class>
>>    <managed-bean-scope>
>>    session</managed-bean-scope>
>>      <managed-property>
>>          <property-name>theProperty</property-name>
>>          <value>theDefaultvalue</value>
>>      </managed-property>
>>  </managed-bean>
>>
>>
>>
>>
>> David Delbecq wrote:
>>     
>>> Hello,
>>>
>>> I need to design a form in JSF where there are various default value 
>>>       
> for
>   
>>> various fields.
>>> However, the default value is separated from the backing bean (it's
>>> something to display in initial form). I am not sure how to do this, i
>>> don't see in h:inputHidden anything that relate to a default value.
>>>
>>> I need to convert this struts form:
>>>
>>>
>>>         <html:hidden property="scope" value="${param.searchScope}"/>
>>>         <html:hidden property="requestedNodeResults" value="15"/>
>>>         <html:text property="query" styleClass="search"/>
>>> to a JSF form, but i don't know where to put the '15' and
>>> 'param.searchScope' in JSf
>>>
>>> setting <h:inputHidden value="#{theForm.requestedNodeResults}"/> does
>>> not set the default value to 15.
>>>
>>> Any suggestion to set default value? Do i have to do
>>> <h:inputHidden
>>> value="#{theForm.requestedNodeResults}">15</h:inputHidden> or something
>>> like that? Can't find documentation on setting default form values...
>>>
>>> Help appreciated.
>>>
>>>
>>>
>>>       
>
>
>
>   



Re: ---SPAM--- Re: setting default value for input field?

Posted by David Delbecq <de...@oma.be>.
Thank you Aleksandr, it does fit my need, i didn't know about the
f:attribute, i'll check if it works for the value (your example use the
size :p )

To people saying it's one backing bean per form, i agree up to some
point. In my case i have only 2 forms and could separate in 2 backing
beans. But main problems are
1) i don't have access to backing bean initialization step thru JSf,
it's manager by struts faces
2) on the same form, default value of some fields depend on current user
profile, on some GET parameters and so on, this make it difficult to
manage somewhere else than in form.

Thanks for help anyway.

En l'instant précis du 13/03/07 08:15, Aleksandr Mazur s'exprimait en
ces termes:
> Hi David,
>
> Life could be easy with facelets. For example:
>
> Tag file: myinputText.xhtml 
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE html
>         PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml"
>       xmlns:ui="http://java.sun.com/jsf/facelets"
>       xmlns:t="http://myfaces.apache.org/tomahawk"
>       xmlns:c="http://java.sun.com/jstl/core"
>         >
> <ui:composition>
> <c:if test="#{empty value}">
>         <c:set var="value" value="#{default}"/>
> </c:if>
>         <t:inputText id="#{name}" value="#{value}" required="#{required}">
>                 <c:if test="#{!empty size}">
>                         <f:attribute name="size" value="#{size}"/>
>                 </c:if>
>             <ui:insert/>
>         </t:inputText>
> </ui:composition>
> </html>
>
> So, on your page:
>
> <my:inputText value="#{myBean.fieldValue}" default="Search..." size="50" 
> required="false"/>
>  
> Best regards,
> Aleksandr Mazur,
>
>
>
>
> David Delbecq <de...@oma.be> 
> 12.03.2007 22:29
> Please respond to
> "MyFaces Discussion" <us...@myfaces.apache.org>
>
>
> To
> MyFaces Discussion <us...@myfaces.apache.org>
> cc
>
> Subject
> ---SPAM--- Re: setting default value for input field?
>
>
>
>
>
>
> Thanks but it does not fit the needs
> 1) the default value should be configurable per page. It's not the only
> hidden field. Some have a searchScope that depend on which page the form
> sit in. It can't be initialized by 'managed property'
>
> Cmon, there should be something as simple as defaut="..." that exist in
> JSF. I can't believe a form couldn't have default values in the JSP...
>
> Steve Torrefranca a écrit :
>   
>> I am also a JSF newbie but I think for default values you can try
>> managed property
>>
>> In you faces-config.xml you do something like
>>
>>  <managed-bean>
>>    <managed-bean-name>theBackingBean</managed-bean-name>
>>    <managed-bean-class>
>>    com.whatever.com.TheBackingBean</managed-bean-class>
>>    <managed-bean-scope>
>>    session</managed-bean-scope>
>>      <managed-property>
>>          <property-name>theProperty</property-name>
>>          <value>theDefaultvalue</value>
>>      </managed-property>
>>  </managed-bean>
>>
>>
>>
>>
>> David Delbecq wrote:
>>     
>>> Hello,
>>>
>>> I need to design a form in JSF where there are various default value 
>>>       
> for
>   
>>> various fields.
>>> However, the default value is separated from the backing bean (it's
>>> something to display in initial form). I am not sure how to do this, i
>>> don't see in h:inputHidden anything that relate to a default value.
>>>
>>> I need to convert this struts form:
>>>
>>>
>>>         <html:hidden property="scope" value="${param.searchScope}"/>
>>>         <html:hidden property="requestedNodeResults" value="15"/>
>>>         <html:text property="query" styleClass="search"/>
>>> to a JSF form, but i don't know where to put the '15' and
>>> 'param.searchScope' in JSf
>>>
>>> setting <h:inputHidden value="#{theForm.requestedNodeResults}"/> does
>>> not set the default value to 15.
>>>
>>> Any suggestion to set default value? Do i have to do
>>> <h:inputHidden
>>> value="#{theForm.requestedNodeResults}">15</h:inputHidden> or something
>>> like that? Can't find documentation on setting default form values...
>>>
>>> Help appreciated.
>>>
>>>
>>>
>>>       
>
>
>
>