0

inside a iteration with primefaces dataList I want render an image conditionally like this:

<ui:param name="curTriggerState" value="#{jobListController.getTriggerState(curJobTriggerInfo)}" />
<p:column rendered="#{showCurJobTrigger}">
    <h:outputText value="#{curTriggerState}" />
    <h:graphicImage value="/resources/images/triggerstate_none_48.png" 
        rendered="#{curTriggerState eq 'NONE'}" />
    <h:graphicImage value="/resources/images/triggerstate_normal_48.png" 
        rendered="#{curTriggerState eq 'NORMAL'}" />
    <h:graphicImage value="/resources/images/triggerstate_paused_48.png" 
        rendered="#{curTriggerState eq 'PAUSED'}" />
    <h:graphicImage value="/resources/images/triggerstate_complete_32.png" 
        rendered="#{curTriggerState eq 'COMPLETE'}" />
    <h:graphicImage value="/resources/images/triggerstate_error_48.png" 
        rendered="#{curTriggerState eq 'ERROR'}" />
    <h:graphicImage value="/resources/images/triggerstate_blocked_48.png" 
        rendered="#{curTriggerState eq 'BLOCKED'}" />
</p:column>

jobListController.getTriggerState returns a string checked in the corresponding render attribute. The ouputText prints out the correct state. But no image is drawn. The paths of the images are correct if I set rendered="true" the image is drawn. Cannot find my mistake. Thought the ui:param could be the cause, but the outputText prints out the correct string.

Aritz
  • 30,971
  • 16
  • 136
  • 217
opfau
  • 731
  • 9
  • 37
  • Does it work if you do rendered="#{jobListController.getTriggerState(curJobTriggerInfo) eq 'NONE'}" /> etc. ? – Emil Kaminski Jul 08 '14 at 08:48
  • Does it work if you try ? – user3489875 Jul 08 '14 at 09:05
  • Yes. With rendered="true" ist works (as written in the post :)) – opfau Jul 08 '14 at 09:06
  • Use `==` instead of `eq` for enum comparisson: http://stackoverflow.com/questions/2524420/how-to-testing-for-enum-equality-in-jsf – Aritz Jul 08 '14 at 09:28
  • But getTriggerState() delivers a string. But with == the behaviour does not change. – opfau Jul 08 '14 at 09:31
  • I cant seem to find anything wrong with your code. It may be a wild shot, but maybe the returned string from the method jobListController.getTriggerState(curJobTriggerInfo) contains some whitespaces? Try changing it to retutn a static String and test again – Emil Kaminski Jul 08 '14 at 13:18
  • No there are no white spaces. I also checked the correct return with . I found another solution which I will post here as an answer. – opfau Jul 09 '14 at 09:31

3 Answers3

0

This works...but I do not like it to generate the path to the image

<ui:param name="curTriggerStateName" value="#{jobListController.getTriggerStateName(curJobTriggerInfo)}" />
<h:graphicImage value="/resources/images/#{jobListController.getTriggerStatusImageName(curJobTriggerInfo)}" 
                        style="margin-right: 3px !important;"/>
opfau
  • 731
  • 9
  • 37
  • As far as I understand this question has more to do with the `rendered` attribute rather than with the path itself. The path is actually correct, but the image does not get rendered, isn't that the problem? – Aritz Jul 08 '14 at 09:32
  • Yes. This is exactly the problem (which I do not understand). – opfau Jul 08 '14 at 09:46
0

Finally I changed it to generate the file name which is less code. But I do not like it in general to generate pathes to files upon states and follow a file name pattern. But this works:

<ui:param name="curTriggerStateName" value="#{jobListController.getTriggerStateName(curJobTriggerInfo)}" />
<h:graphicImage value="/resources/images/triggerstate_#{curTriggerStateName}_20.png" styleClass="triggerStateImage"
            title="#{curTriggerStateName}" />
opfau
  • 731
  • 9
  • 37
  • Ok. This does not work. After I have checked the backend data the images are not correct. The delivered state in curTriggerStateName is put into title which is shown as tooltip in the browser above the image. The image for the state is not correct. E. g. something like this is rendered as html: – opfau Jul 09 '14 at 09:40
  • It should be – opfau Jul 09 '14 at 09:41
  • I think I am lacking some fundamental knowledge of JSF internals using ui:param stuff? Think a ui:param can only be set once? Around the code is a p:dataList. – opfau Jul 09 '14 at 09:42
  • Tested it without ui:param and used the call getTriggerStateName directly. This does not change anything. – opfau Jul 09 '14 at 09:44
0

This was my fault. The backend service is a mock at this time which returns the trigger state randomly. It seems that the backing bean (and therefore the backend) is not only called once per graphicImage but several times. When each calls returns a different trigger state, the image and the title can differ of course. I am a little bit suprised about that because I assign the value with a ui:param and thought the backing bean method will be called only once per graphicImage.

opfau
  • 731
  • 9
  • 37