• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem displaying desired output

 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

I am trying to do a test of an input Date type object and display it's value on the page based on it's value. If the Date object is NULL or empty I would like to display as '00000' otherwise it should display in the format of 'yyDDD' date format. for the code below I am getting the desired date value if Date object is not null. If there is no date value then I am not getting value displayed as '00000'.

Here's the part of the .xhtml file related to my problem-


Again if I change the code to something like this then I get the '00000' displayed for the NULL date values. But the other Date values would not get displayed as 'yyDDD' format. It would display it in it's original format and also preceded by '00000'

Here's that version of the code -


Any idea how can get this working for me?

Thanks
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Drop JSTL and make use of JSF's 'rendered' attribute.

JSTL and JSF doesn't run that seamlessly as you'd intuitively expect. I.e. JSTL and JSF aren't being evaluated in the logical order as you have coded in the JSP page. It's JSTL which will first be evaluated from top to bottom and then it's JSF's turn. This may lead to unexpected results.

From JSTL only the 'fn' (functions) taglib is useful and useable in JSF, the remaining JSTL taglibs should be avoided. JSF has its own components and/or attributes for that.
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke,

Thanks a lot for the tip. Any code hints that I can be using for my problem?

 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a thought would using something like <c:choose> ... <c:when> ... <ctherwise> will still still mess up the order of execution?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I repeat: use the 'rendered' attribute.

It accepts a boolean expression. Exactly as c:if and c:when does.
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try it out. Thanks!
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried using the <ui:fragment rendered ...> jsf component. Looks like this time it is completely ignoring the <ui:fragment> altogether. Here's my code -
[code]
html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:spss="http://www.spss.com/jsf/nimms"
xmlns:ft="http://sourceforge.net/projects/facestrace"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<ui:composition>
<ui:fragment rendered="${value == 'NullDate'}">
<ui:fragment rendered="${dataValue == null}">
<hutputText value="00000" style="white-space:nowrap" />
</ui:fragment>
<ui:fragment rendered="${value != 'NullDate'}">
<hutputText value="11111" style="white-space:nowrap" />

</ui:fragment>
</ui:fragment>
</ui:composition>
</body>
</html>
[code]
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry got trigger happy. Accidentally hit the submit button before finishing my post.
Here it is again -

I have tried using the <ui:fragment rendered ...> jsf component. Looks like this time it is completely ignoring the <ui:fragment> altogether. Here's my code -



Also getting the error -
SEVERE: Error Rendering View ... com.sun.facelets.tag.TagException: //C: formatData.xhtml @60,77 <f:convertDateTime> Parent not an instance of ValueHolder: com.sun.facelets.tag.ui.ComponentRef@ed0e35

when I have -

<f:convertDateTime pattern="yyDDD" timeZone="#{timeZone}" />

instead of what I have now -

<hutputText value="11111" style="white-space:nowrap" /> Any idea what I am doing wrong?


Thanks
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I repeat for the last time: remove all the JSTL.

Further on: use the rendered attribtue of the hutputText.
Finally, the f:convertDateTime should be nested in the hutputText.

According to this functional requirement:
I am trying to do a test of an input Date type object and display it's value on the page based on it's value. If the Date object is NULL or empty I would like to display as '00000' otherwise it should display in the format of 'yyDDD' date format. for the code below I am getting the desired date value if Date object is not null. If there is no date value then I am not getting value displayed as '00000'.

the correct coding would be

where bean.getDate() returns java.util.Date.

Does it make sense now?
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry, cut and pasted some of the old code I was using before. I indeed removed all the JSTL <c: .... So, my fault not being careful posting the code properly here. Anyway, even after taking out the last bit of the JSTL from the code it is still behaving the same way as it was when I posted my question first time with the JSTL.

I have decided to handle my problem by updating the view from the db table I am getting the date values from. I am guessing it would be much proficient instead of doing it in the code side. I always lean on letting the database handle any complex manipulation if it can handle. I have more trust on Oracle which I am using here to do a better job than my code can. Though it would have been great to get a generic way to handle date values in the way I initially wanted to. But for now this view update will do for me for the time being.
Thanking again for replying to my email.>
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic