• Post Reply Bookmark Topic Watch Topic
  • New Topic

t:inputText id="test", how to get its value?

 
peter tong
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in a selection criteria screen, there is a <t:inputText id="test"/> component, how to get its value?
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter getting the value of the specified component is easy. Make use of the value attribute. Are you comfortable with the concept of backing bean ? If yes then it will come to you in a minute.

I will try to give a small example for you here.

In the page the code will be



In backing Bean make a property and write its getter and setters as well.


Hope this will solve your problem.
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't "get" a JSF value. A JSF page is a View, and it references a Model. Your tag misses a critical attribute:

<t:inputText id="test" value="#{bean.property}"/>

This will cause the JSF Controller to inject the value of the inputText field into the property named "property" of the bean which has been named "bean" in your jsf faces-config.xml file.
 
peter tong
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, theat means all h:inputText must have a backing bean,otherwise we have no method to get the value?
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF is a framework and backing bean is a part of it. You cannot test the functionality of most of the componenet without using backing bean. Please go through some good examples to understand it in a better way.
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by peter tong:
Oh, theat means all h:inputText must have a backing bean,otherwise we have no method to get the value?


Before you get into details, you really need to get an understanding of what JSF is all about. I think, actually, that you're looking at it as though the JSF pages are where the program logic is based, and that isn't so. In fact, one of the bits of advice I provide more than almost any other in this forum is that JSF pages should have as little logic on them as possible. None at all, if you can.

JSF is about as complete an implementation of the classic Model/View/Controller paradigm as you can manage when HTTP is your underlying transport mechanism. It's also very much based on the concept of Inversion of Control (IoC), where you don't "get" things, they're injected into your code.

I had to learn to think of web application structure a lot differently when I started working with JSF. So will you.
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just been looking at JSF quickly and have a quick question to ask. I've put it here because this thread seems to be along the same lines...

I found this quick sample 2 page app called JSFKickStart.

Basically has 2 JSPs and a Bean, with the following smippets



Now my question is, how does JSP1 or JSP2 know to use the Getter or Setter?

Usually you'd expect to see something like



But as if by magic JSF seems to know which to use, what's the 'background' logic going on here?

PS: Early opinion is that JSF look very much the thing for me, but it will be very hard to drag me away from 5 years or so of classic JSP/Servlet/Bean coding!

---

Just like to add another observation to this question...

Pu a couple of simple Sys.outs in the Bean to see when, what is called and noticed this:



It 'gets' the method getPersonName twice!
It gets the method getPersonName, then gets the method setPersonName, then gets the method getPersonName again!

That seems an extra 'call', why is this?
[ November 20, 2008: Message edited by: Keith Seller ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!