users@javaserverfaces.java.net

Re: RE: I am stumped on how to move from Application.createValueBinding to ExpressionFactory.createValueExpression

From: Michael Youngstrom <youngm_at_gmail.com>
Date: Wed, 17 Jan 2007 20:20:26 -0700

Try looking at:

http://java.sun.com/javaee/javaserverfaces/1.2_MR1/docs/api/javax/faces/application/Application.html#getExpressionFactory()

http://java.sun.com/javaee/javaserverfaces/1.2_MR1/docs/api/javax/faces/application/Application.html#evaluateExpressionGet(javax.faces.context.FacesContext,%20java.lang.String,%20java.lang.Class)

and then look here for info on how the ELExpressionFactory works:

http://java.sun.com/javaee/5/docs/api/

Mike



On 1/17/07, Todd Patrick <Todd.Patrick_at_dtn.com> wrote:
> What I am trying to do is the following:
>
> In my login method, I create a visit object and set the visit's user
> property with a User object.
>
> Inside the try statement, what I had before was:
>
> facesContext.getApplication().createValueBinding("#{" +
> Constants.VISIT_KEY_SCOPE + Constants.VISIT_KEY +
> "}").setValue(facesContext, visit);
>
> This create an expression with the value of the visit object with it's
> User object property set.
>
> I think I am close with:
>
> facesContext.getApplication().getExpressionFactory().createValueExpressi
> on(elcontext, "#{" + Constants.VISIT_KEY_SCOPE + Constants.VISIT_KEY +
> "}", Visit.class);
>
> But, I still can't get the expression set to the visit object.
>
> Currently, I am reading about ELResolver...
>
> Thanks again,
>
> --Todd
>
>
>
> public String login() {
> FacesContext facesContext = getFacesContext();
> Authenticate auth = new Authenticate();
> auth.setPassword(this.password);
>
> if (auth.authenticateUser(this.username)) {
> User newUser = new User(this.username);
> Visit visit = new Visit();
> visit.setUser(newUser);
> visit.setAuthenticationBean(this);
> setVisit(visit);
>
> try {
> //facesContext.getApplication().createValueBinding("#{"
> + Constants.VISIT_KEY_SCOPE + Constants.VISIT_KEY +
> "}").setValue(facesContext, visit);
> ELContext elcontext = facesContext.getELContext();
>
> facesContext.getApplication().getExpressionFactory().createValueExpressi
> on(elcontext, "#{" + Constants.VISIT_KEY_SCOPE + Constants.VISIT_KEY +
> "}", Visit.class);
>
> HttpServletResponse resp = (HttpServletResponse)
> facesContext.getExternalContext().getResponse();
> HttpServletRequest req = (HttpServletRequest)
> facesContext.getExternalContext().getRequest();
>
> resp.sendRedirect(req.getContextPath() +
> Constants.BASE_URL);
> } catch (IOException e) {
> logger.warn("Authenticate: Unable to redirect user.",
> e);
> } catch (ELException e) {
> logger.warn("Unable to bind a value.", e);
> }
> } else {
> this.logout();
> }
>
> return SUCCESS_OUTCOME;
> }
>
>
>
>
> -----Original Message-----
> From: Jason Lee [mailto:lee_at_iecokc.com]
> Sent: Wednesday, January 17, 2007 2:47 PM
> To: users_at_javaserverfaces.dev.java.net
> Subject: RE: I am stumped on how to move from
> Application.createValueBinding to
> ExpressionFactory.createValueExpression
>
> Are you trying to register a variable that components can then
> reference, like the var attribute on a dataTable? If so, try this:
>
> ELContext ec = FacesContext.getCurrentInstance().getELContext();
> ELResolver er = ec.getELResolver();
> er.setValue(ec, null, "foo", valueOfFoo);
>
> -----
> Jason Lee, SCJP
> Programmer/Analyst
> http://www.iec-okc.com
>
>
> > -----Original Message-----
> > From: Todd Patrick [mailto:Todd.Patrick_at_dtn.com]
> > Sent: Wednesday, January 17, 2007 2:40 PM
> > To: users_at_javaserverfaces.dev.java.net
> > Subject: I am stumped on how to move from
> > Application.createValueBinding to
> > ExpressionFactory.createValueExpression
> >
> > I am looking at two APIs:
> >
> > http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.
> > html?javax
> > /faces/application/Application.html
> >
> > http://java.sun.com/javaee/5/docs/api/
> >
> >
> > Looking at the documentation I need to go from:
> >
> > Visit visit = new Visit();
> > facesContext.getApplication().createValueBinding("#{" +
> > Constants.VISIT_KEY_SCOPE + Constants.VISIT_KEY +
> > "}").setValue(facesContext, visit);
> >
> >
> > To the JSF 1.2 requirement:
> >
> > ELContext elcontext = facesContext.getELContext();
> > facesContext.getApplication().getExpressionFactory().createMet
> > hodExpress
> > ion(elcontext, "#{" + Constants.VISIT_KEY_SCOPE + Constants.VISIT_KEY
> > + "}", String.class, new Class<?>[0]);
> >
> >
> > The createMethodExpression method has be stumped at the moment.
> >
> > How do I get my visit object into the value of the expression (second
> > parameter in createMethodExpression)?
> >
> > Thanks,
> >
> > --Todd
> >
> >
> > -----------------------------------------
> > NOTICE: This email message is for the sole use of the intended
> > recipient(s) and may contain confidential and privileged information.
> > Any unauthorized use, disclosure or distribution is prohibited. If you
>
> > are not the intended recipient, please contact the sender by reply
> > email and destroy all copies of the original message.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
> > For additional commands, e-mail:
> > users-help_at_javaserverfaces.dev.java.net
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: users-help_at_javaserverfaces.dev.java.net
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: users-help_at_javaserverfaces.dev.java.net
>
>