0

Is there is any way I can write the Java code in JSF in the same manner as we do in JSP using script-lets?

I want to write following code in JSF:

<% 
EditProperties editProperties = new EditProperties();
Map<String,String> dataMap = new HashMap<String,String>();
dataMap = editProperties.getDocumentProperties();
if (dataMap.size() > 0) {
    Iterator<Map.Entry<String,String>> entries = dataMap.entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry<String, String> entry = entries.next();  
%>
6
  • 5
    JSF and other technologies were invented to avoid scriptlets in jsp. Believe me, you don't want to add scriptlets. What's your functional requirement? What specific problem you have moving this code on your managed bean? Commented Oct 2, 2012 at 4:48
  • Thanks Luiggi for replying, actually in my jsf page i have to use the basic input component <input type="text" id="<%=entry.getKey()%>" value="<%=entry.getValue()%>"/> So in order to iterate over this component i need that jav acode inside my jsf page Commented Oct 2, 2012 at 4:57
  • Any valuable info to help people get involved in your problem must be in your question, not in comments. Edit your question and add everything you consider good so people could understand the situation and help you. Commented Oct 2, 2012 at 4:59
  • 1
    Based in your comment, you must learn the basics of JSF. Read the info on our JSF wiki, your actual approach is very outdated. Commented Oct 2, 2012 at 5:01
  • 1
    Related: stackoverflow.com/questions/3177733/… Commented Oct 2, 2012 at 11:29

1 Answer 1

2

There is a lot of work involved in not allowing you to do this.

As Luiggi mentioned - take some time learning JSF basics and see what it can give you. Another good source of knowledge is Core JavaServer Faces book by D. Geary and C. Horstmann.

If you still can't achieve what you want using JSF core libraries (or some additional, widely available ones), then any Java code related with front-end should be in your controller classes like JSF managed beans. It will make your code easier to maintain and will allow you to test it.

There is nothing worse than putting scriptlets in your JSP/JSF/whatever view technology.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.