0

I created a Chat object with style as the following:

Code

String style =  "<div style='border:2px solid #25d366; width:25px;height:25px; border-radius: 5px; display: inline-block; margin-right: 20px;'><p:commandLink  action='#{viewEventStatusController.callServiceAgent('{id: " + qrCode + ", action: warehouse}', chat.id)}' update='@this' disabled='#{!chat.valid}' ><h:graphicImage url='/images/1_yes_icon.png' width='22' height='22'/></p:commandLink></div>"; 
getLogger().info("style before setting to the chatText Object: " + style);
chatText.setStyle(style);

Some where I am inserting the object to the database.

With this code I am rendering the content of the style but I am getting the style as I have inserted it to the database displayed.

xhtml code

<p:outputPanel rendered="#{viewEventStatusController.eventStatus.objectId != chat.fromName}" > 
             <div style="background-color:white; ; width: 60%; height: 80px;border-radius: 10px; margin-left: 5%; margin-top: 30px;margin-bottom: 30px; padding-left: 20px; padding-top: 10px; margin-left: 5%;">
              <div id="header2">
                      <!--messageHeader2-->
                      <div id="messageHeader2" style="display: inline-block; color: gray; font-size: 12px;">
                        <h:outputText value="#{chat.messageTopic}" />
                     </div>
                     <!--time-->
                     <div id="timeWord" style= "display: inline-block; color: gray; font-size: 12px; margin-left: 73%;"> 
                      <h:outputText value="#{chat.lastWrite}" converter="DateTimeConverter">
                              <f:convertDateTime pattern="HH:mm" timeZone="#{localeController.timeZone}"/>
                      </h:outputText> Uhr
                    </div>
                </div>
                <h:outputText value="#{chat.msg}" style="float: left; padding-top: 10px;" />
                <div id="buttonContainer" style="margin-bottom: 10px; float: right; margin-top: 20px !important; padding-right: 100px;">
                 <!--The servericAgent decides which button we have here-->
                  <h:form id="chatHTMLForm" rendered="#{chat.style != null}">
                     #{chat.style}
                  </h:form>
                </div>
             </div>
  </p:outputPanel>

How can I get a commandLink button which stored in the database displayed in the xhtml?

I am getting the follwoing

<div style='border:2px solid #25d366; width:25px;height:25px;
 border-radius: 5px; display: inline-block; margin-right:
 20px;'><p:commandLink 
 action='#{viewEventStatusController.callServiceAgent('{id: Test 1,
 action: warehouse}', chat.id)}' update='@this'
 disabled='#{!chat.valid}' ><h:graphicImage
 url='/images/1_yes_icon.png' width='22'
 height='22'/></p:commandLink></div>

displayed in the xhtml.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
benz
  • 693
  • 1
  • 9
  • 29
  • You cannot "dynamically" add JSF components on that way. Check out this answer https://stackoverflow.com/questions/3510614/how-to-create-dynamic-jsf-form-fields – Dusan Kovacevic Dec 06 '17 at 06:16
  • If I write html code I can display the button but I do not know what would be the action? In the generated html code from primefaces I can see for action `onclick="'PrimeFaces.ab({s:"form:j_idt896",u:"@(form, idleMonitor)",ps:true});return false;'" ` How can I replace it in my case? `
    `
    – benz Dec 06 '17 at 08:29
  • I suppose that your action will always be something like #{viewEventStatusController.callServiceAgent (param1, param2)}. In that case, for example, you can have param1 and param2 in backing bean and put values that you need – Dusan Kovacevic Dec 06 '17 at 09:06
  • Possible duplicate of [Obtaining Facelets templates/files from an external filesystem or database](https://stackoverflow.com/questions/13292272/obtaining-facelets-templates-files-from-an-external-filesystem-or-database) – Kukeltje Dec 06 '17 at 13:52

0 Answers0