0

Hello there i want to ask about injecting xhtml code dynamically from a bean to xhtml page

this is the code i want to inject

code i want to inject

and i put it in a string in the bean like :

private String x="<th> \n <h:outputText value=\"#{msgs.label_insertInSalaryPayroll}\" /> \n </th> \n <td> \n <h:selectOneMenu value=\"#{financialElements.insertInSalaryPayroll}\" styleClass=selectMenu\"> \n <f:selectItem itemValue=\"\" itemLabel=\"#{msgs.label_all}\" /> \n <f:selectItem itemValue=\"true\" itemLabel=\"#{msgs.label_insertInSalaryPayroll}\" /> \n <f:selectItem itemValue=\"false\" itemLabel=\"#{msgs.label_notInsertInSalaryPayroll}\" /> \n </h:selectOneMenu> \n </td> \n <th> \n <h:outputText value=\"#{msgs.label_elementEffect}\" /> \n </th> \n <td> \n <h:selectOneMenu value=\"#{financialElements.elementEffect}\" styleClass=\"selectMenu\"> \n <f:selectItem itemValue=\"-1\" itemLabel=\"#{msgs.label_all}\" /> \n <f:selectItem itemValue=\"#{financialElements.credit}\" itemLabel=\"#{msgs.label_credit}\" /> \n <f:selectItem itemValue=\"#{financialElements.debit}\" itemLabel=\"#{msgs.label_debit}\" /> \n </h:selectOneMenu> \n </td>";

and i get it from the xhtml page like this :

<h:outputText value="#{financialElements.x}" escape="false" />

the result is as below image from the browser inspect view (only "th" and "td" tags are rendered but any h:.. tag is not executed and written in the page as is )

result from browser inspect

so i want to know is there any way to solve this issue or to inject jsf tags from the bean dynamically to xhtml page .

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • Hi, you don't 'inject' xml here, you inject facelets/xhtml source that still needs to be made part of the component tree (real page source) en then rendered. What you do now is only the render part and it won't work. There are several ways to sort of achieve what you want and assuming you are on JSF 2.2+ (you don't state version info, so I assume you are smart/sensible/sane and on a recent version), use https://stackoverflow.com/questions/13292272/obtaining-facelets-templates-files-from-an-external-filesystem-or-database – Kukeltje Sep 04 '18 at 08:01
  • Hi, thanks for your comment , i am on JSF 2.0 , i checked the link you provided , but it depends on a file not a string or couple of lines as these links will be changed dynamically according to specific criteria this is why i want to inject it in an already made xhtml page , and you are right i am injecting xhtml source not xml . – Mahmoud Fathy Sep 04 '18 at 09:25
  • The link (find older ones for JSF2.0) is an **example**, I hope you can understand that. You can get the xhtml you want to add from anywhere... – Kukeltje Sep 04 '18 at 09:54

0 Answers0