You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rob Decker <ro...@objectsource.org> on 2005/04/13 20:15:53 UTC

predefined form values

Say I have a form to do a search and a backing bean called SearchBean:

<h:form>
<h:inputText value="#{searchBean.searchValue}"/>
<x:inputCalendar value="#{searchBean.lastModified}"/>
<h:commandButton type="submit" action="#{search.search}"/>
</h:form>

Now say I want to have simple links with predefined values for the search parameters, 
a quick search link:

<h:form
<h:commandLink action="#{search.search}">
<h:outputText value="Quick Search"/>
<h:inputHidden value="*"/>
<h:inputHidden value="04/05/2005"/>
</h:commandLink>
</h:form>

How do I associate the hidden input values with the search bean methods that holds 
their values? It seems like in this case I have to id all the components, get the
request, and populate the search bean myself or I have to create the search bean so
it binds components instead of values. Is there a simple way to do this that I'm 
missing?

--
Rob

@objectsource.org


Re: predefined form values

Posted by Rob Decker <ro...@objectsource.org>.
I was trying <f:param/>'s but I don't see how the name attribute gets the association 
with the searchBean.lastModified expression, in other words:

<f:param name="lastModified" value="04/05/2005"/>

Won't I have to get this out of the request? In that case I'll need the second 
solution anyway at least in terms of a special action to populate the bean.


While defining action methods in the bean to deal with it would work it would be nicer 
if new 'quick links' could simply be created in a jsp page instead of having to write 
a new java method.


--
Rob

@objectsource.org


---------- Original Message -----------
From: Heath Borders <he...@gmail.com>
To: MyFaces Discussion <my...@incubator.apache.org>
Sent: Wed, 13 Apr 2005 14:07:45 -0500
Subject: Re: predefined form values

> You can use <f:param />'s inside the quick links, or you could have the 
> quick links fire different action events, and those action events could 
> contains the defaults instead of having them in your JSP.
> 
> On 4/13/05, Rob Decker <ro...@objectsource.org> wrote: 
> > 
> > 
> > Say I have a form to do a search and a backing bean called SearchBean:
> > 
> > <h:form>
> > <h:inputText value="#{searchBean.searchValue}"/>
> > <x:inputCalendar value="#{searchBean.lastModified}"/>
> > <h:commandButton type="submit" action="#{search.search}"/>
> > </h:form>
> > 
> > Now say I want to have simple links with predefined values for the search 
> > parameters,
> > a quick search link:
> > 
> > <h:form
> > <h:commandLink action="#{search.search}">
> > <h:outputText value="Quick Search"/>
> > <h:inputHidden value="*"/>
> > <h:inputHidden value="04/05/2005"/>
> > </h:commandLink>
> > </h:form>
> > 
> > How do I associate the hidden input values with the search bean methods 
> > that holds
> > their values? It seems like in this case I have to id all the components, 
> > get the
> > request, and populate the search bean myself or I have to create the 
> > search bean so
> > it binds components instead of values. Is there a simple way to do this 
> > that I'm
> > missing?
> > 
> > --
> > Rob
> > 
> > @objectsource.org <http://objectsource.org>
> > 
> >
> 
> -- 
> -Heath Borders-Wing
> hborders@mail.win.org
------- End of Original Message -------


Re: predefined form values

Posted by Heath Borders <he...@gmail.com>.
You can use <f:param />'s inside the quick links, or you could have the 
quick links fire different action events, and those action events could 
contains the defaults instead of having them in your JSP.

On 4/13/05, Rob Decker <ro...@objectsource.org> wrote: 
> 
> 
> Say I have a form to do a search and a backing bean called SearchBean:
> 
> <h:form>
> <h:inputText value="#{searchBean.searchValue}"/>
> <x:inputCalendar value="#{searchBean.lastModified}"/>
> <h:commandButton type="submit" action="#{search.search}"/>
> </h:form>
> 
> Now say I want to have simple links with predefined values for the search 
> parameters,
> a quick search link:
> 
> <h:form
> <h:commandLink action="#{search.search}">
> <h:outputText value="Quick Search"/>
> <h:inputHidden value="*"/>
> <h:inputHidden value="04/05/2005"/>
> </h:commandLink>
> </h:form>
> 
> How do I associate the hidden input values with the search bean methods 
> that holds
> their values? It seems like in this case I have to id all the components, 
> get the
> request, and populate the search bean myself or I have to create the 
> search bean so
> it binds components instead of values. Is there a simple way to do this 
> that I'm
> missing?
> 
> --
> Rob
> 
> @objectsource.org <http://objectsource.org>
> 
> 


-- 
-Heath Borders-Wing
hborders@mail.win.org

Re: predefined form values

Posted by Heath Borders <he...@gmail.com>.
Oh... ok.
 You do it on the client with javascript. The inputHidden is going to 
re-post that value back to the request when the form is submitted, so if you 
want to make changes to it, you need to do so behind the scenes i the 
client. The easiest way would be with some kind of generic javascript 
function.

 On 4/13/05, Rob Decker <ro...@objectsource.org> wrote: 
> 
> Not that Heath's answer didn't work...just that I'd like to explore an 
> easier that the
> spec seems cover (I posted this to sun's jsf forums too).
> 
> Reading the JSF Specification section 5.1.4 Set Value Semantics I quote:
> 
> When the setValue() method on a ValueBinding is called, the syntax of the
> value binding restriction is restricted as described above. The 
> implementation must
> perform the following processing to evaluate an expression of the form 
> "#{expra.
> value-b}" or "#{expr-a[value-b]}":
> 
>  Evaluate expr-a into value-a.
> {cases with null, lists, maps snipped}
>  Otherwise (value-a is a JavaBean object):
>  Coerce value-b to String.
>  If value-b is a writeable property of value-a (as per the JavaBeans
> Specification), call the setter method (passing new-value); throwing
> ReferenceSyntaxException if an exception is thrown.
>  Otherwise, throw PropertyNotFoundException.
> 
> Hence,
> 
> <h:inputHidden value="#{searchBean.created}"/>
> 
> should evaluate to an instance of the managed-bean SearchBean.setCreated(String 
> s).
> The thing I'm missing is 'new-value'. Since value= is the value binding 
> attribute
> where do I put 'new-value'?
> 
> --
> Rob
> 
> @objectsource.org <http://objectsource.org>
> 
> 
> ---------- Original Message -----------
> From: Heath Borders <he...@gmail.com>
> To: MyFaces Discussion <my...@incubator.apache.org>
> Sent: Wed, 13 Apr 2005 15:30:57 -0500
> Subject: Re: predefined form values
> 
> > Ok, then you write a single quickSearch(ActionEvent) method and inside 
> it
> > you check for the quickSearch parameter(s). And use those to search.
> >
> > On 4/13/05, Rob Decker <ro...@objectsource.org> wrote:
> > >
> > >
> > > I don't want to write a java method for every quick search I want. I'd
> > > like to be able
> > > to just add a new quick search to a jsp. Say I have 3 quick searches:
> > >
> > > Look for things from: Today, Yesterday, Last Week
> > >
> > > Then next month the boss says 'I want a quick search for tomorrow!'. 
> It
> > > would be
> > > easier for someone to add it to the jsp page than to have to write a 
> new
> > > java method
> > > in the bean. It's a presentation detail.
> > >
> > > --
> > > Rob
> > >
> > > @objectsource.org <http://objectsource.org> <http://objectsource.org>
> > >
> > > ---------- Original Message -----------
> > > From: Enrique Medina <e....@gmail.com>
> > > To: MyFaces Discussion <my...@incubator.apache.org>
> > > Sent: Wed, 13 Apr 2005 21:05:03 +0200
> > > Subject: Re: predefined form values
> > >
> > > > Why not simply call another method from the commandLink (say
> > > > searchQuick) where those values are set in code, and then call the
> > > > search method?
> > > >
> > > > On 4/13/05, Rob Decker <ro...@objectsource.org> wrote:
> > > > >
> > > > > Say I have a form to do a search and a backing bean called 
> SearchBean:
> > > > >
> > > > > <h:form>
> > > > > <h:inputText value="#{searchBean.searchValue}"/>
> > > > > <x:inputCalendar value="#{searchBean.lastModified}"/>
> > > > > <h:commandButton type="submit" action="#{search.search}"/>
> > > > > </h:form>
> > > > >
> > > > > Now say I want to have simple links with predefined values for the
> > > search
> > > parameters,
> > > > > a quick search link:
> > > > >
> > > > > <h:form
> > > > > <h:commandLink action="#{search.search}">
> > > > > <h:outputText value="Quick Search"/>
> > > > > <h:inputHidden value="*"/>
> > > > > <h:inputHidden value="04/05/2005"/>
> > > > > </h:commandLink>
> > > > > </h:form>
> > > > >
> > > > > How do I associate the hidden input values with the search bean
> > > methods that holds
> > > > > their values? It seems like in this case I have to id all the
> > > components, get the
> > > > > request, and populate the search bean myself or I have to create 
> the
> > > search bean so
> > > > > it binds components instead of values. Is there a simple way to do
> > > this that I'm
> > > > > missing?
> > > > >
> > > > > --
> > > > > Rob
> > > > >
> > > > > @objectsource.org <http://objectsource.org> <
> http://objectsource.org>
> > > > >
> > > > >
> > > ------- End of Original Message -------
> > >
> > >
> >
> > --
> > -Heath Borders-Wing
> > hborders@mail.win.org
> ------- End of Original Message -------
> 
> 


-- 
-Heath Borders-Wing
hborders@mail.win.org

Re: predefined form values

Posted by Rob Decker <ro...@objectsource.org>.
Not that Heath's answer didn't work...just that I'd like to explore an easier that the 
spec seems cover (I posted this to sun's jsf forums too).

Reading the JSF Specification section 5.1.4 Set Value Semantics I quote:

When the setValue() method on a ValueBinding is called, the syntax of the
value binding restriction is restricted as described above. The implementation must
perform the following processing to evaluate an expression of the form “#{expra.
value-b}” or “#{expr-a[value-b]}”:

 Evaluate expr-a into value-a.
{cases with null, lists, maps snipped}
 Otherwise (value-a is a JavaBean object):
 Coerce value-b to String.
 If value-b is a writeable property of value-a (as per the JavaBeans
Specification), call the setter method (passing new-value); throwing
ReferenceSyntaxException if an exception is thrown.
 Otherwise, throw PropertyNotFoundException.

Hence,

<h:inputHidden value="#{searchBean.created}"/> 

should evaluate to an instance of the managed-bean SearchBean.setCreated(String s). 
The thing I'm missing is 'new-value'. Since value= is the value binding attribute 
where do I put 'new-value'?



--
Rob

@objectsource.org


---------- Original Message -----------
From: Heath Borders <he...@gmail.com>
To: MyFaces Discussion <my...@incubator.apache.org>
Sent: Wed, 13 Apr 2005 15:30:57 -0500
Subject: Re: predefined form values

> Ok, then you write a single quickSearch(ActionEvent) method and inside it 
> you check for the quickSearch parameter(s). And use those to search.
> 
> On 4/13/05, Rob Decker <ro...@objectsource.org> wrote: 
> > 
> > 
> > I don't want to write a java method for every quick search I want. I'd 
> > like to be able
> > to just add a new quick search to a jsp. Say I have 3 quick searches:
> > 
> > Look for things from: Today, Yesterday, Last Week
> > 
> > Then next month the boss says 'I want a quick search for tomorrow!'. It 
> > would be
> > easier for someone to add it to the jsp page than to have to write a new 
> > java method
> > in the bean. It's a presentation detail.
> > 
> > --
> > Rob
> > 
> > @objectsource.org <http://objectsource.org>
> > 
> > ---------- Original Message -----------
> > From: Enrique Medina <e....@gmail.com>
> > To: MyFaces Discussion <my...@incubator.apache.org>
> > Sent: Wed, 13 Apr 2005 21:05:03 +0200
> > Subject: Re: predefined form values
> > 
> > > Why not simply call another method from the commandLink (say
> > > searchQuick) where those values are set in code, and then call the
> > > search method?
> > >
> > > On 4/13/05, Rob Decker <ro...@objectsource.org> wrote:
> > > >
> > > > Say I have a form to do a search and a backing bean called SearchBean:
> > > >
> > > > <h:form>
> > > > <h:inputText value="#{searchBean.searchValue}"/>
> > > > <x:inputCalendar value="#{searchBean.lastModified}"/>
> > > > <h:commandButton type="submit" action="#{search.search}"/>
> > > > </h:form>
> > > >
> > > > Now say I want to have simple links with predefined values for the 
> > search
> > parameters,
> > > > a quick search link:
> > > >
> > > > <h:form
> > > > <h:commandLink action="#{search.search}">
> > > > <h:outputText value="Quick Search"/>
> > > > <h:inputHidden value="*"/>
> > > > <h:inputHidden value="04/05/2005"/>
> > > > </h:commandLink>
> > > > </h:form>
> > > >
> > > > How do I associate the hidden input values with the search bean 
> > methods that holds
> > > > their values? It seems like in this case I have to id all the 
> > components, get the
> > > > request, and populate the search bean myself or I have to create the 
> > search bean so
> > > > it binds components instead of values. Is there a simple way to do 
> > this that I'm
> > > > missing?
> > > >
> > > > --
> > > > Rob
> > > >
> > > > @objectsource.org <http://objectsource.org>
> > > >
> > > >
> > ------- End of Original Message -------
> > 
> >
> 
> -- 
> -Heath Borders-Wing
> hborders@mail.win.org
------- End of Original Message -------


Re: predefined form values

Posted by Heath Borders <he...@gmail.com>.
Actually, its even simpler than that.
 The commandLink puts the param on the postback, so you should be able to 
reference it by calling:
FacesContext.getCurrentInstance
().getExternalContext().getRequestParameterMap().get("paramName");

 On 4/13/05, Rob Decker <ro...@objectsource.org> wrote: 
> 
> event.getComponent()
> comp.getChildren()
> while children.hasnext
> if child instanceof UIParameter
> set[child.getName]=child.value;
> 
> I wonder if instead of returning void from the bean setter if I return the 
> value I can
> 
> <h:inputHidden value="#{searchBean.lastModified['04/05/2005']}"
> converter="javax.faces.DateTime"/>
> 
> --
> Rob
> 
> @objectsource.org <http://objectsource.org>
> 
> ---------- Original Message -----------
> From: Heath Borders <he...@gmail.com>
> To: MyFaces Discussion <my...@incubator.apache.org>
> Sent: Wed, 13 Apr 2005 15:30:57 -0500
> Subject: Re: predefined form values
> 
> > Ok, then you write a single quickSearch(ActionEvent) method and inside 
> it
> > you check for the quickSearch parameter(s). And use those to search.
> >
> > On 4/13/05, Rob Decker <ro...@objectsource.org> wrote:
> > >
> > >
> > > I don't want to write a java method for every quick search I want. I'd
> > > like to be able
> > > to just add a new quick search to a jsp. Say I have 3 quick searches:
> > >
> > > Look for things from: Today, Yesterday, Last Week
> > >
> > > Then next month the boss says 'I want a quick search for tomorrow!'. 
> It
> > > would be
> > > easier for someone to add it to the jsp page than to have to write a 
> new
> > > java method
> > > in the bean. It's a presentation detail.
> > >
> > > --
> > > Rob
> > >
> > > @objectsource.org <http://objectsource.org> <http://objectsource.org>
> > >
> > > ---------- Original Message -----------
> > > From: Enrique Medina <e....@gmail.com>
> > > To: MyFaces Discussion <my...@incubator.apache.org>
> > > Sent: Wed, 13 Apr 2005 21:05:03 +0200
> > > Subject: Re: predefined form values
> > >
> > > > Why not simply call another method from the commandLink (say
> > > > searchQuick) where those values are set in code, and then call the
> > > > search method?
> > > >
> > > > On 4/13/05, Rob Decker <ro...@objectsource.org> wrote:
> > > > >
> > > > > Say I have a form to do a search and a backing bean called 
> SearchBean:
> > > > >
> > > > > <h:form>
> > > > > <h:inputText value="#{searchBean.searchValue}"/>
> > > > > <x:inputCalendar value="#{searchBean.lastModified}"/>
> > > > > <h:commandButton type="submit" action="#{search.search}"/>
> > > > > </h:form>
> > > > >
> > > > > Now say I want to have simple links with predefined values for the
> > > search
> > > parameters,
> > > > > a quick search link:
> > > > >
> > > > > <h:form
> > > > > <h:commandLink action="#{search.search}">
> > > > > <h:outputText value="Quick Search"/>
> > > > > <h:inputHidden value="*"/>
> > > > > <h:inputHidden value="04/05/2005"/>
> > > > > </h:commandLink>
> > > > > </h:form>
> > > > >
> > > > > How do I associate the hidden input values with the search bean
> > > methods that holds
> > > > > their values? It seems like in this case I have to id all the
> > > components, get the
> > > > > request, and populate the search bean myself or I have to create 
> the
> > > search bean so
> > > > > it binds components instead of values. Is there a simple way to do
> > > this that I'm
> > > > > missing?
> > > > >
> > > > > --
> > > > > Rob
> > > > >
> > > > > @objectsource.org <http://objectsource.org> <
> http://objectsource.org>
> > > > >
> > > > >
> > > ------- End of Original Message -------
> > >
> > >
> >
> > --
> > -Heath Borders-Wing
> > hborders@mail.win.org
> ------- End of Original Message -------
> 
> 


-- 
-Heath Borders-Wing
hborders@mail.win.org

Re: predefined form values

Posted by Heath Borders <he...@gmail.com>.
Ok, then you write a single quickSearch(ActionEvent) method and inside it 
you check for the quickSearch parameter(s). And use those to search.

On 4/13/05, Rob Decker <ro...@objectsource.org> wrote: 
> 
> 
> I don't want to write a java method for every quick search I want. I'd 
> like to be able
> to just add a new quick search to a jsp. Say I have 3 quick searches:
> 
> Look for things from: Today, Yesterday, Last Week
> 
> Then next month the boss says 'I want a quick search for tomorrow!'. It 
> would be
> easier for someone to add it to the jsp page than to have to write a new 
> java method
> in the bean. It's a presentation detail.
> 
> --
> Rob
> 
> @objectsource.org <http://objectsource.org>
> 
> ---------- Original Message -----------
> From: Enrique Medina <e....@gmail.com>
> To: MyFaces Discussion <my...@incubator.apache.org>
> Sent: Wed, 13 Apr 2005 21:05:03 +0200
> Subject: Re: predefined form values
> 
> > Why not simply call another method from the commandLink (say
> > searchQuick) where those values are set in code, and then call the
> > search method?
> >
> > On 4/13/05, Rob Decker <ro...@objectsource.org> wrote:
> > >
> > > Say I have a form to do a search and a backing bean called SearchBean:
> > >
> > > <h:form>
> > > <h:inputText value="#{searchBean.searchValue}"/>
> > > <x:inputCalendar value="#{searchBean.lastModified}"/>
> > > <h:commandButton type="submit" action="#{search.search}"/>
> > > </h:form>
> > >
> > > Now say I want to have simple links with predefined values for the 
> search
> parameters,
> > > a quick search link:
> > >
> > > <h:form
> > > <h:commandLink action="#{search.search}">
> > > <h:outputText value="Quick Search"/>
> > > <h:inputHidden value="*"/>
> > > <h:inputHidden value="04/05/2005"/>
> > > </h:commandLink>
> > > </h:form>
> > >
> > > How do I associate the hidden input values with the search bean 
> methods that holds
> > > their values? It seems like in this case I have to id all the 
> components, get the
> > > request, and populate the search bean myself or I have to create the 
> search bean so
> > > it binds components instead of values. Is there a simple way to do 
> this that I'm
> > > missing?
> > >
> > > --
> > > Rob
> > >
> > > @objectsource.org <http://objectsource.org>
> > >
> > >
> ------- End of Original Message -------
> 
> 


-- 
-Heath Borders-Wing
hborders@mail.win.org

Re: predefined form values

Posted by Rob Decker <ro...@objectsource.org>.
I don't want to write a java method for every quick search I want. I'd like to be able 
to just add a new quick search to a jsp. Say I have 3 quick searches:

Look for things from: Today, Yesterday, Last Week

Then next month the boss says 'I want a quick search for tomorrow!'. It would be 
easier for someone to add it to the jsp page than to have to write a new java method 
in the bean. It's a presentation detail.

--
Rob

@objectsource.org


---------- Original Message -----------
From: Enrique Medina <e....@gmail.com>
To: MyFaces Discussion <my...@incubator.apache.org>
Sent: Wed, 13 Apr 2005 21:05:03 +0200
Subject: Re: predefined form values

> Why not simply call another method from the commandLink (say
> searchQuick) where those values are set in code, and then call the
> search method?
> 
> On 4/13/05, Rob Decker <ro...@objectsource.org> wrote:
> > 
> > Say I have a form to do a search and a backing bean called SearchBean:
> > 
> > <h:form>
> > <h:inputText value="#{searchBean.searchValue}"/>
> > <x:inputCalendar value="#{searchBean.lastModified}"/>
> > <h:commandButton type="submit" action="#{search.search}"/>
> > </h:form>
> > 
> > Now say I want to have simple links with predefined values for the search 
parameters,
> > a quick search link:
> > 
> > <h:form
> > <h:commandLink action="#{search.search}">
> > <h:outputText value="Quick Search"/>
> > <h:inputHidden value="*"/>
> > <h:inputHidden value="04/05/2005"/>
> > </h:commandLink>
> > </h:form>
> > 
> > How do I associate the hidden input values with the search bean methods that holds
> > their values? It seems like in this case I have to id all the components, get the
> > request, and populate the search bean myself or I have to create the search bean so
> > it binds components instead of values. Is there a simple way to do this that I'm
> > missing?
> > 
> > --
> > Rob
> > 
> > @objectsource.org
> > 
> >
------- End of Original Message -------


Re: predefined form values

Posted by Enrique Medina <e....@gmail.com>.
Why not simply call another method from the commandLink (say
searchQuick) where those values are set in code, and then call the
search method?

On 4/13/05, Rob Decker <ro...@objectsource.org> wrote:
> 
> Say I have a form to do a search and a backing bean called SearchBean:
> 
> <h:form>
> <h:inputText value="#{searchBean.searchValue}"/>
> <x:inputCalendar value="#{searchBean.lastModified}"/>
> <h:commandButton type="submit" action="#{search.search}"/>
> </h:form>
> 
> Now say I want to have simple links with predefined values for the search parameters,
> a quick search link:
> 
> <h:form
> <h:commandLink action="#{search.search}">
> <h:outputText value="Quick Search"/>
> <h:inputHidden value="*"/>
> <h:inputHidden value="04/05/2005"/>
> </h:commandLink>
> </h:form>
> 
> How do I associate the hidden input values with the search bean methods that holds
> their values? It seems like in this case I have to id all the components, get the
> request, and populate the search bean myself or I have to create the search bean so
> it binds components instead of values. Is there a simple way to do this that I'm
> missing?
> 
> --
> Rob
> 
> @objectsource.org
> 
>