0

I want to insert outputText in the value attribute of a commandButton. The problem I am facing here is that the 'value' attribute of the commandButton only takes static text as value but I want this text to change according to the value assigned to that list and the whole value should be displayed inside the commandbutton.

<h:commandButton id="submit-button" styleClass="click_button1"
                                type="submit" value="Yes"
                                action="#{xyz.deleteAction(o)}" update="msgs" />

In this, instead of "yes", I want something like this

Yes, I want this thing <h:outputText size="15" value="#{o.name}" /></b> from <h:outputText size="15" value="#{o.detals}" /></b>

as the value.

Chirag Kawariya
  • 205
  • 2
  • 4
  • 18
  • Uhhhmmm you can do EL in the value attribute without a problem. Also string concatenation. It nowhere states you can only do static text – Kukeltje Oct 21 '15 at 15:05
  • 1
    The `` doesn't have a `size` attribute and those `` tags are invalid and confusing. Ultimately, you can just use EL in value attribute too like so `value="blah #{o.name} blah"`. Is this what you're actually looking for? I've seen that many starters are unaware of "partial" EL expressions in JSF component attributes and/or that they think that `` is the only way to print an EL expression (which is an indication that wrong learning resources are being used to learn JSF). – BalusC Oct 21 '15 at 19:55

1 Answers1

0

If you really need some h:outputText features such as escape="false" then your best bet is to use h:commandLink instead. You may need to tweak your CSS if you want to get a look and feel close to h:commandButton.

<h:commandLink id="submit-button" styleClass="click_button1" action="#{xyz.deleteAction(o)}" update="msgs">
     Yes, I want this thing <h:outputText value="#{o.name}" /> from <h:outputText value="#{o.detals}" />
</h:commandLink>

If you only need to display some dynamic values then you can perfectly use an EL expression

<h:commandButton id="submit-button" styleClass="click_button1" type="submit" value="Yes, I want this thing #{o.name} from #{o.detals}" action="#{xyz.deleteAction(o)}" update="msgs" />

See also Is it suggested to use h:outputText for everything?

Notes:

  • I removed the </b> tags from your example as this looks like a typo from me.
  • As BalusC stated in his comment, h:outputText doesn't have a size attribute.

Edited following Kukeltje and BalusC's comments.

Community
  • 1
  • 1
Mathieu Castets
  • 5,861
  • 3
  • 28
  • 37
  • You mean escape=“false“ you mean as (afaik) the value is by default escaped (but I could be wrong) – Kukeltje Oct 22 '15 at 23:28