File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes JSF Rendered attribute question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Rendered attribute question" Watch "JSF Rendered attribute question" New topic
Author

JSF Rendered attribute question

J Ruing
Greenhorn

Joined: Feb 27, 2009
Posts: 7
Hi,

I am migrating a dhtml/ajax/spring web app to jsf on the front-end and am running into the following problem.

We have fields that are optionally rendered depending on a conditional flag that comes off the backend.



The bean is implmented as follows:




But the problem I have is within this method determining what form element has currently executed the method. Am I using the wrong approach here should I be using a phase listener not sure as new to JSF but any help much appreciated.

Amy Saari
Greenhorn

Joined: Sep 13, 2007
Posts: 29
Hi JR

I used the tag:

<a4j:actionparam name="desc#{rowIndex}ID" value="#{rowIndex}" assignTo="#{DescriptionHandler.rowUpdated}" />

to tell the backing bean what component in a list was clicked (ie the setter for rowUpdated is called).
I think you can get core functionality (if you're not using a4j) from the tags:

f:attribute

or

f:param

Amy
J Ruing
Greenhorn

Joined: Feb 27, 2009
Posts: 7
I am using core tag libs for now and have played around with f:param and f:attribute as far as I can see:

f:param is used on a link or button to append additional info to the request

f:attribute (name/value) to be use to place addtional information into a individual UIComponent

both of these tags will not help - as within the method I don't know what component is exactly executing the call.

Thanks for the prompt reply - I am using a phase listener as I think this will allow me to do what I need.
Amy Saari
Greenhorn

Joined: Sep 13, 2007
Posts: 29
But that was the point

pass the id of the component to the backing bean inside the inputText tag.

<f:param name="currentId" value="officeEmail" binding="#{myClass.currentId}" />


String currentId;

public void setCurrentId(String s) {
currentId = s;
}

UIComponent field = fc.getViewRoot().findComponent(currentId);
J Ruing
Greenhorn

Joined: Feb 27, 2009
Posts: 7
I have done as you suggested:



but on the bean the currentId is not a string it is an instance of

"getCurrentId()"= "javax.faces.component.UIParameter@1a06d8b" ???
J Ruing
Greenhorn

Joined: Feb 27, 2009
Posts: 7
What you have said is not correct when you have a list of fields the param value is always the last one so your suggestion is useless.
Amy Saari
Greenhorn

Joined: Sep 13, 2007
Posts: 29
JR

I used ajax4jsf - so our examples aren't exactly the same. I think you have to tell JSF about this property inside this bean in the faces-config.xml inside the managed-bean tag. See:

webpage

See if this helps - I'd be interested to know if that's the problem...

Amy
J Ruing
Greenhorn

Joined: Feb 27, 2009
Posts: 7
Not sure if the link posted previously is of any value as it relates to updating a jsf component based on user interaction this is not what I am trying to do. I will attempt to outline the problem domain:

Problem:
I have a jsf page that before it loads in the browser I would like to exclude certain fields from being rendered in the response. Sounds fine if I had a traditional backing bean but this is not the case. The application is dhtml and js using ajax requests to get data back from the server - I don't want to change this for now but want the advanages of using the jsf component libs.

We have a client that does not want 3 fields on a particular form so I decided to convert this form to a jsf document so that I could use the jsf panel and the response would render fine no need for me to code the client to ensure that there was no gaps in the form. I have attempted to use the rendered attribute but this has not worked. I have coded a PhaseListener that gets me most of the way it excludes the 3 fields from the form but only after the inital request has been served, i.e. only on second request. I have played around with all the different phase types but none seem to be able to take the 3 fields out of the inital client response. If anyone was any ideas on how to manipulate the component tree for the initial request and render the response please let me know.

Thanks,

JR.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF Rendered attribute question
 
Similar Threads
Exit methods with return
ValueChangeListener for double values
UiViewRoot - findComponent dont work
component doesnt remeber value
Custom Validator persistently returning NULL