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 how to eliminate code repeating in jsf page? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "how to eliminate code repeating in jsf page?" Watch "how to eliminate code repeating in jsf page?" New topic
Author

how to eliminate code repeating in jsf page?

Pavels Hlopoks
Ranch Hand

Joined: Feb 05, 2007
Posts: 31
Hello!

I have code



If and else part is little bit different, parameter SELECTED value is different.

how better to eliminate code repeating in jsf page in this situation?

Thanks!
Josh Juneau
Ranch Hand

Joined: Jun 16, 2004
Posts: 86
I'm not sure exactly what you are attempting to perform, but you should be able to tie the selected attribute to a backing bean value. In coding this way, your backing bean will determine if the value is true or false. You can get rid of the JSTL altogether and just do something like this:

<tr:commandNavigationItem immediate="true"
text="Contracts"
action="guide.page"
selected="#{bean.selectedValue}"/>

I do not use JSTL anywhere in JSF code at this time unless absolutely necessary. You should try to perform all comparisons and business logic within the backing beans if possible.

I hope this will work for your situation. Otherwise, your JSTL solution may be the best alternative.


Database Administrator/Application Developer
Pavels Hlopoks
Ranch Hand

Joined: Feb 05, 2007
Posts: 31
Thanks Josh,

I have another solution



Josh Juneau
Ranch Hand

Joined: Jun 16, 2004
Posts: 86
Nice one...that will definitely do the trick!
 
 
subject: how to eliminate code repeating in jsf page?
 
Threads others viewed
Getting Checkbox value - DisplayTag library
Mixing JSP and Scriptlets throws compilation errors
Best way to find out of user is logged in
Can multiple conditions be checked using JSTL?
EL Question, print variable between two strings
IntelliJ Java IDE