Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP expression inside JSF tag?

 
andree surya
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Samuel March
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic