aspose file tools*
The moose likes JSF and the fly likes JSP expression inside JSF tag? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSP expression inside JSF tag?" Watch "JSP expression inside JSF tag?" New topic
Author

JSP expression inside JSF tag?

andree surya
Greenhorn

Joined: Jun 13, 2009
Posts: 29
I have a set of categories and I want to display that as hyperlinks in my JSF page.
If the user clicks in one of them, the category ID is submitted and the action BookController.filterByCategory is called.

This is my code:

And when I browse the page, apparently it doesn't work:

Can anyone tell me the correct way to do this?

Thanks,
Ang
Samuel March
Ranch Hand

Joined: Oct 28, 2009
Posts: 39
Just to be quick since i can't do much at this time.

<h:inputHidden binding="#{BookCategories.bookBean.categoryId}" value="<%= categories.get(i).getId() %>" />

The setValue in bookBean should have at least one property to store a value for each of the array elements you are iterating over.

If your list does not require to change for al the categories you can set each property value into
and Array[] or java.util.List and assign in faces-config.xml managed properties for the managed bean.

for now or till someone else sees this thread and shows you: See the J2EE tutorial "Managed Beans" (Backing Beans)
at the http://www.java.sun.com site.
============================
Just got back, i had some time to think.

Firstly, your using a scriptlet to attempt to "evaluate" a scriptlet call.

Secondly , you don't need to use the value attribute "with a tag that has a binding= to a producer method of the java type its producing.

The errors refer to :
type int getId
and
type String getName

You should have set the value in the component producer method programmatically.

http://java.sun.com/javaee/javaserverfaces/1.1/docs/api/javax/faces/component/html/HtmlInputHidden.html

http://java.sun.com/javaee/javaserverfaces/1.1/docs/api/


...did you have the fish?!............................ No.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

As Samuel noted, you really shouldn't use both "binding=" and "value=" in the same element. They're intended as mutually exclusive options.

However, your expressions are done the hard way, in addition to not being valid EL expressions at all.

Instead of


Try


And, of course, the same format for the name.


Customer surveys are for companies who didn't pay proper attention to begin with.
Samuel March
Ranch Hand

Joined: Oct 28, 2009
Posts: 39

Using scriptlet "(JSP)" is not valid inside JSF.


JSP and JSTL use a writing evaluater to the output stream when evaluating the JSP page called A JspWriter.

JSF uses between JSP and JSF in synchronicity (for evaluating the page) a (JSF Writer) ResponseWriter.
E.G. (methods) void encodeBegin , void encodeEnd and decode for retrieval with a Renderkit


Here's the tricky bit.
When a JSP/JSTL tag or scriptlet is seen in the markup, the JspWriter evaluates them, but if a JSF tag is seen , the JSP evaluator is switched to wait().
But if you write a JSF custom tag, it is picked up by the JSP writer and can/will evaluate scriptlet in its attributes becuase the
tag registration in the page markup is JSP and it hasn't started to be operated on until the page information is inside the tags class binaries.

Inside the tag class code to make a JSF custom tag, a call to the JSF instance and JSF writer(the ResponseWriter object) is made to operate and encode()
methods are used to produce the output component before writing it to out.

If anything (i haven't specifically checked its as simple as this) you could import the FacesContext at the top of your page and because the managed bean declaration
name is the same as using the jsp:useBean id= reference you could do ... example-ish but that requires climbing into the map of the application bean introspection indexer classes:
="<%= categoryBeanName.get(i).getName() %>"

THIS next URL (in this article and ELResolver is used to create an expression or obtain its value on the current on the current instance):
http://www.oracle.com/technology/products/jdev/tips/fnimphius/advancedeltechniques/advancedeltechniques.html?msgid=7962520
andree surya
Greenhorn

Joined: Jun 13, 2009
Posts: 29
Thanks guys for the help. But honestly, I'm a bit overwhelmed since I'm not yet that much into Java

However, I understand that JSF doesn't go well with JSP, so I decide to remove those JSP scriptlets, and use something like this instead:



Nevertheless, thanks for your time and effort .. I appreciate that
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSP expression inside JSF tag?