I want JSF expression language to expand #(bean.property} before I access it in code so that I can get access to the CSS3 top and left property values in a in-line html style. Here is the JSF html expression that populates left and top in the webpage source, but do not appear in ViewRoot elements:
<h:outputText id="pg" value="${item.displayphrase.content}" style="margin:0px;padding:0px;position:absolute;left:10px;top:${item.displayphrase.topPos}px;width:${item.displayphrase.width}px " immediate="true" />
<h:outputText id="pg" value="${item.displayphrase.content}" style="margin:0px;padding:0px;position:absolute; left:${item.displayphrase.leftPos}px;top:${item.displayphrase.topPos}px;width:${item.displayphrase.width}px" immediate="true" />
Here is the Java code accessing the html “pg” id:
FacesContext facesContext = FacesContext.getCurrentInstance(); UIViewRoot viewRoot = facesContext.getViewRoot(); UIComponent component = viewRoot.findComponent(“pg”); If (component instanceof HtmlOutputText) { HtmlOutputText text = (HtmlOutputText) component; String style = text.getStyle(); System.out.println(“style:”+ style); }
The println above shows style properties for the top and left CCS3 are empty. What does work is when I use hard-coded top and left values in the html style, it displays properly. For example, if I hardcode the left/top values it works:
<h:outputText id="pg" value="${item.displayphrase.content}" style="margin:0px;padding:0px;position:absolute;left:10px;top:10px;width:${item.displayphrase.width}px " immediate="true" />
Also, I’ve tried using UIViewRoot viewroot in before and after phases in bean for the RENDER_RESPONSE phase and no luck. All the phases fire, but left/top style values are still empty for CSS3 top and left properties.
What did I miss here?
I tried normal access in viewroot phases but, left and top properties come up blank.
I tried before and after phases on viewroot, but it doesn’t pick up the left and top properties.
I was expecting access to the html control style and left and top properties.
Ideally, I would like to access the left and top html properties after the page has fully rendered. I would expect these are accessible then.
MightyWarrior is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.